mbed RPC Server - Eclipse SmartHome Variante

Dependencies:   EthernetInterface HttpServer Motor Servo mbed-rtos mbed StepperMotorUni TMP175

Fork of RPCHTTPServerSimple by smd.iotkit2.ch

Das ist der mbed Teil zu Eclipse SmartHome (openHAB2). Compiliert das Programm und lädt es auf das Board.

Installation Eclipse SmartHome

Lädt eine vorbereitete Version des openHAB2 Runtimes von http://images.workshoptage.ch/images/ws4/ herunter und entpackt es auf Eurem PC. Alternativ kann die Entwicklungsumgebung von openHAB2 inkl. Eclipse wie hier beschrieben, installiert werden.

Zusätzlich ist das Addon (Eclipse Plug-In - ch.iotkit.smarthome.binding.mbedRPC*), ebenfalls von http://images.workshoptage.ch/images/ws4/ downzuladen und ins Verzeichnis addons zu kopieren.

Danach kann das openHAB2 Runtime mittels des start Datei gestartet werden und das UI mittels http://localhost:8080 aufrufen werden.

Der Sourcecode zum Eclipse Plug-In befindet sich auf GitHub

Konfiguration

Vorgehen:

  • Konfiguriert die Ethernet Bridge mit der IP Adresse des IoTKit SMD Shield
  • Fügt die Sensoren, Aktoren, LED's etc. vom IoTKit SMD Shield hinzu, aufbauend auf der Bridge

Unterstützte Geräte

  • Sensoren (auf Shield)
    • Poti (Pin A0)
    • Helligkeits Sensor (Pin A1)
    • Hall Sensor (Pin A2)
    • Temperatur Sensor (mittels I2C Bus)
  • Aktoren
    • Motor (Pin D3, D2, D4), verbinden mit DCMOT D2-D7 oben
    • Servo (Pin D9), verbinden mit Servo2 Stecker
    • Stepper (K64F Pins), verbinden mit STEPPER3, rotes Kabel nach unten
  • LED's (auf Shield)
    • LED's rot, gelb, grün, blau (Pin D10 - D13)
  • LED Strip 12 Volt (Pin D5 - D7), verbinden mit FET D5-D7, 12V oben

Der Motor und der LED Strip benötigen ein externes 12 Volt Netzteil.

cURL

Die Funktionen können mittels cURL oder Browser wie folgt getestet werden:

# RGB LED Strip (weiss 0xFFFFFF, rot 0xFF00, grün 0xFF0000, blau, 0xFF)
http://192.168.178.32/rpc/ledstrip/write+16777215
http://192.168.178.32/rpc/ledstrip/write+‭16711680‬
http://192.168.178.32/rpc/ledstrip/write+65280
http://192.168.178.32/rpc/ledstrip/write+255
 
# Motor Up, Down, Stop (Simulation Rollladen)
http://192.168.178.32/rpc/motor1/up
http://192.168.178.32/rpc/motor1/down
http://192.168.178.32/rpc/motor1/stop
 
# Schrittmotor                               
http://192.168.178.32/rpc/stepper1/up
http://192.168.178.32/rpc/stepper1/down
 
# Servo (Positionieren 0 - 1.0 und Position lesen)
http://192.168.178.32/rpc/servo1/write+0.5
http://192.168.178.32/rpc/servo1/read
 
# Temperatur Sensor abfragen                        
http://192.168.178.32/rpc/temp/read

IP-Adresse entsprechend dem Board anpassen.

Committer:
stefan1691
Date:
Wed Apr 08 12:31:41 2015 +0000
Revision:
11:43e28c85fd75
Korrektur AnalogIn laut . https://developer.mbed.org/questions/3897/AnalogIn-not-working-in-rpc/

Who changed what in which revision?

UserRevisionLine numberNew contents of line
stefan1691 11:43e28c85fd75 1 /* mbed Microcontroller Library
stefan1691 11:43e28c85fd75 2 * Copyright (c) 2006-2013 ARM Limited
stefan1691 11:43e28c85fd75 3 *
stefan1691 11:43e28c85fd75 4 * Licensed under the Apache License, Version 2.0 (the "License");
stefan1691 11:43e28c85fd75 5 * you may not use this file except in compliance with the License.
stefan1691 11:43e28c85fd75 6 * You may obtain a copy of the License at
stefan1691 11:43e28c85fd75 7 *
stefan1691 11:43e28c85fd75 8 * http://www.apache.org/licenses/LICENSE-2.0
stefan1691 11:43e28c85fd75 9 *
stefan1691 11:43e28c85fd75 10 * Unless required by applicable law or agreed to in writing, software
stefan1691 11:43e28c85fd75 11 * distributed under the License is distributed on an "AS IS" BASIS,
stefan1691 11:43e28c85fd75 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
stefan1691 11:43e28c85fd75 13 * See the License for the specific language governing permissions and
stefan1691 11:43e28c85fd75 14 * limitations under the License.
stefan1691 11:43e28c85fd75 15 */
stefan1691 11:43e28c85fd75 16 #ifndef RPCVARIABLE_H_
stefan1691 11:43e28c85fd75 17 #define RPCVARIABLE_H_
stefan1691 11:43e28c85fd75 18
stefan1691 11:43e28c85fd75 19 #include "rpc.h"
stefan1691 11:43e28c85fd75 20
stefan1691 11:43e28c85fd75 21 namespace mbed {
stefan1691 11:43e28c85fd75 22
stefan1691 11:43e28c85fd75 23 /**
stefan1691 11:43e28c85fd75 24 *Class to read and set an attached variable using the RPC
stefan1691 11:43e28c85fd75 25 *
stefan1691 11:43e28c85fd75 26 */
stefan1691 11:43e28c85fd75 27 template<class T>
stefan1691 11:43e28c85fd75 28 class RPCVariable: public RPC {
stefan1691 11:43e28c85fd75 29 public:
stefan1691 11:43e28c85fd75 30 /**
stefan1691 11:43e28c85fd75 31 * Constructor
stefan1691 11:43e28c85fd75 32 *
stefan1691 11:43e28c85fd75 33 *@param ptr Pointer to the variable to make accessible over RPC. Any type of
stefan1691 11:43e28c85fd75 34 *variable can be connected
stefan1691 11:43e28c85fd75 35 *@param name The name of that this object will be over RPC
stefan1691 11:43e28c85fd75 36 */
stefan1691 11:43e28c85fd75 37 template<class A>
stefan1691 11:43e28c85fd75 38 RPCVariable(A * ptr, const char * name) : RPC(name) {
stefan1691 11:43e28c85fd75 39 _ptr = ptr;
stefan1691 11:43e28c85fd75 40 }
stefan1691 11:43e28c85fd75 41 /**
stefan1691 11:43e28c85fd75 42 *Read the variable over RPC.
stefan1691 11:43e28c85fd75 43 *
stefan1691 11:43e28c85fd75 44 *@return The value of the variable
stefan1691 11:43e28c85fd75 45 */
stefan1691 11:43e28c85fd75 46 T read() {
stefan1691 11:43e28c85fd75 47 return (*_ptr);
stefan1691 11:43e28c85fd75 48 }
stefan1691 11:43e28c85fd75 49 /**
stefan1691 11:43e28c85fd75 50 *Write a value to the variable over RPC
stefan1691 11:43e28c85fd75 51 *
stefan1691 11:43e28c85fd75 52 *@param The value to be written to the attached variable.
stefan1691 11:43e28c85fd75 53 */
stefan1691 11:43e28c85fd75 54 void write(T value) {
stefan1691 11:43e28c85fd75 55 *_ptr = value;
stefan1691 11:43e28c85fd75 56 }
stefan1691 11:43e28c85fd75 57
stefan1691 11:43e28c85fd75 58 virtual const struct rpc_method *get_rpc_methods();
stefan1691 11:43e28c85fd75 59 static struct rpc_class *get_rpc_class();
stefan1691 11:43e28c85fd75 60
stefan1691 11:43e28c85fd75 61 private:
stefan1691 11:43e28c85fd75 62 T * _ptr;
stefan1691 11:43e28c85fd75 63 };
stefan1691 11:43e28c85fd75 64
stefan1691 11:43e28c85fd75 65 template<class T>
stefan1691 11:43e28c85fd75 66 const rpc_method *RPCVariable<T>::get_rpc_methods() {
stefan1691 11:43e28c85fd75 67 static const rpc_method rpc_methods[] = {
stefan1691 11:43e28c85fd75 68 {"read" , rpc_method_caller<T, RPCVariable, &RPCVariable::read> },
stefan1691 11:43e28c85fd75 69 {"write", rpc_method_caller<RPCVariable, T, &RPCVariable::write> },
stefan1691 11:43e28c85fd75 70 RPC_METHOD_SUPER(RPC)
stefan1691 11:43e28c85fd75 71 };
stefan1691 11:43e28c85fd75 72 return rpc_methods;
stefan1691 11:43e28c85fd75 73 }
stefan1691 11:43e28c85fd75 74
stefan1691 11:43e28c85fd75 75 template<class T>
stefan1691 11:43e28c85fd75 76 rpc_class *RPCVariable<T>::get_rpc_class() {
stefan1691 11:43e28c85fd75 77 static const rpc_function funcs[] = {
stefan1691 11:43e28c85fd75 78 "new", rpc_function_caller<const char*, T, const char*, &RPC::construct<RPCVariable, T, const char*> > ,
stefan1691 11:43e28c85fd75 79 RPC_METHOD_END
stefan1691 11:43e28c85fd75 80 };
stefan1691 11:43e28c85fd75 81 static rpc_class c = {"RPCVariable", funcs, NULL};
stefan1691 11:43e28c85fd75 82 return &c;
stefan1691 11:43e28c85fd75 83 }
stefan1691 11:43e28c85fd75 84
stefan1691 11:43e28c85fd75 85 }
stefan1691 11:43e28c85fd75 86
stefan1691 11:43e28c85fd75 87 #endif //RPCVARIABLE_H_