mbed RPC Server - Eclipse SmartHome Variante
Dependencies: EthernetInterface HttpServer Motor Servo mbed-rtos mbed StepperMotorUni TMP175
Fork of RPCHTTPServerSimple by
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.
Revision 16:d0a5bb230d94, committed 2015-08-28
- Comitter:
- marcel1691
- Date:
- Fri Aug 28 12:33:30 2015 +0000
- Parent:
- 15:210305b5a1fc
- Commit message:
- Temp (I2C), RGB LED Strip impl.
Changed in this revision
diff -r 210305b5a1fc -r d0a5bb230d94 RpcClassesExt.h --- a/RpcClassesExt.h Wed Aug 26 19:37:26 2015 +0000 +++ b/RpcClassesExt.h Fri Aug 28 12:33:30 2015 +0000 @@ -20,9 +20,50 @@ #include "Servo.h" #include "Motor.h" #include "StepperMotorUni.h" +#include "TMP175.h" namespace mbed { +/** + * Temperatur TMP75 Sensor am I2C Bus + */ +class RpcTMP75 : public RPC +{ +public: + RpcTMP75(PinName a0, PinName a1, const char *name=NULL) : RPC(name), o(a0, a1) + { + o.vSetConfigurationTMP175( SHUTDOWN_MODE_OFF | COMPARATOR_MODE | POLARITY_0 |FAULT_QUEUE_6 | RESOLUTION_12, 0x48 ); + o.vSetTemperatureLowTMP175( 0.0 ); + o.vSetTemperatureHighTMP175( 60.0 ); + } + + int read(void) + { + return o.fReadTemperatureTMP175(); + } + + virtual const struct rpc_method *get_rpc_methods() + { + static const rpc_method rpc_methods[] = + { + {"read", rpc_method_caller<int, RpcTMP75, &RpcTMP75::read>}, + RPC_METHOD_SUPER(RPC) + }; + return rpc_methods; + } + static struct rpc_class *get_rpc_class() + { + static const rpc_function funcs[] = + { + {"new", rpc_function_caller<const char*, PinName, PinName, const char*, &RPC::construct<RpcTMP75, PinName, PinName, const char*> >}, + RPC_METHOD_END + }; + static rpc_class c = {"RpcTMP75", funcs, NULL}; + return &c; + } +private: + TMP175 o; +}; /** * Servo RPC Template @@ -30,7 +71,11 @@ class RpcServo : public RPC { public: - RpcServo(PinName a0, const char *name=NULL) : RPC(name), o(a0) {} + RpcServo(PinName a0, const char *name=NULL) : RPC(name), o(a0) + { + // Servo kalibrieren, damit er die vollen 180° verwendet. + o.calibrate ( 0.0009, 180.0); + } void write(float a0) {o.write(a0);} float read(void) {return o.read();} @@ -67,13 +112,17 @@ public: RpcMotor(PinName a0, PinName a1, PinName a2, const char *name=NULL) : RPC(name), o(a0, a1, a2) {} - void write(float a0) {o.speed(a0);} + void up () { o.speed( 0.5f ); } + void down() { o.speed( -0.5f ); } + void stop() { o.speed( 0.0f ); } virtual const struct rpc_method *get_rpc_methods() { static const rpc_method rpc_methods[] = { - {"write", rpc_method_caller<RpcMotor, float, &RpcMotor::write>}, + {"up", rpc_method_caller<RpcMotor, &RpcMotor::up>}, + {"down", rpc_method_caller<RpcMotor, &RpcMotor::down>}, + {"stop", rpc_method_caller<RpcMotor, &RpcMotor::stop>}, RPC_METHOD_SUPER(RPC) }; return rpc_methods; @@ -104,13 +153,15 @@ o.set_pps( 300 ); } - void write(int a0) {o.move_steps(a0);} + void up () { o.move_steps( 100 ); } + void down() { o.move_steps( -100 ); } virtual const struct rpc_method *get_rpc_methods() { static const rpc_method rpc_methods[] = { - { "write", rpc_method_caller<RpcStepper, int, &RpcStepper::write> }, + {"up", rpc_method_caller<RpcStepper, &RpcStepper::up>}, + {"down", rpc_method_caller<RpcStepper, &RpcStepper::down>}, RPC_METHOD_SUPER(RPC) }; return rpc_methods; @@ -129,6 +180,47 @@ StepperMotorUni o; }; +/** + * RGB LED Strip +*/ +class RpcLEDStrip : public RPC +{ +public: + RpcLEDStrip(PinName a0, PinName a1, PinName a2, const char *name=NULL) : RPC(name), r(a0), g(a1), b(a2) {} + + void write( int a0 ) + { + //printf( "RGB %f, %f, %f\n", 1.0f / 255.0f * ((a0 & 0xFF0000) / 65636), 1.0f / 255.0f * (a0 & 0xFF00) / 256, 1.0f / 255.0f * (a0 & 0xFF) ); + r.write( 1.0f / 255.0f * ((a0 & 0xFF0000) / 65636) ); + g.write( 1.0f / 255.0f * (a0 & 0xFF00) / 256 ); + b.write( 1.0f / 255.0f * (a0 & 0xFF) ); + } + + virtual const struct rpc_method *get_rpc_methods() + { + static const rpc_method rpc_methods[] = + { + {"write", rpc_method_caller<RpcLEDStrip, int, &RpcLEDStrip::write>}, + RPC_METHOD_SUPER(RPC) + }; + return rpc_methods; + } + static struct rpc_class *get_rpc_class() + { + static const rpc_function funcs[] = + { + {"new", rpc_function_caller<const char*, PinName, PinName, PinName, const char*, &RPC::construct<RpcLEDStrip, PinName, PinName, PinName, const char*> >}, + RPC_METHOD_END + }; + static rpc_class c = {"RpcLEDStrip", funcs, NULL}; + return &c; + } +private: + PwmOut r; + PwmOut g; + PwmOut b; +}; + } #endif
diff -r 210305b5a1fc -r d0a5bb230d94 TMP175.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TMP175.lib Fri Aug 28 12:33:30 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/Suky/code/TMP175/#e177f6671b88
diff -r 210305b5a1fc -r d0a5bb230d94 main.cpp --- a/main.cpp Wed Aug 26 19:37:26 2015 +0000 +++ b/main.cpp Fri Aug 28 12:33:30 2015 +0000 @@ -25,16 +25,23 @@ RPC::add_rpc_class<RpcMotor>(); RPC::add_rpc_class<RpcStepper>(); - // Objekte - RPC::construct<RpcDigitalOut, PinName, const char*>(D10, "led1"); - RPC::construct<RpcDigitalOut, PinName, const char*>(D11, "led2"); + // LED's + RPC::construct<RpcPwmOut, PinName, const char*>(D10, "led1"); + RPC::construct<RpcPwmOut, PinName, const char*>(D11, "led2"); RPC::construct<RpcPwmOut, PinName, const char*>(D12, "led3"); + RPC::construct<RpcPwmOut, PinName, const char*>(D13, "led4"); + RPC::construct<RpcLEDStrip, PinName, PinName, PinName, const char*>( D5, D6, D7, "ledstrip"); + + // Sensoren RPC::construct<RpcAnalogIn, PinName, const char*>(A0, "poti"); RPC::construct<RpcAnalogIn, PinName, const char*>(A1, "light"); - RPC::construct<RpcDigitalIn, PinName, const char*>(A2, "b1"); - RPC::construct<RpcServo, PinName, const char*>( D9, "servo1" ); + RPC::construct<RpcAnalogIn, PinName, const char*>(A2, "hall"); + RPC::construct<RpcTMP75, PinName, PinName, const char*>(D14, D15, "temp"); + + // Aktoren RPC::construct<RpcMotor, PinName, PinName, PinName, const char*>( D3, D2, D4, "motor1" ); RPC::construct<RpcStepper, const char*>( "stepper1" ); + RPC::construct<RpcServo, PinName, const char*>( D9, "servo1" ); // muss als letzer Eintrag kommen, ansonsten wird Signal gestoert // Handler HTTPServerAddHandler<RPCHandler>("/rpc");