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:
marcel1691
Date:
Fri Aug 28 12:33:30 2015 +0000
Revision:
16:d0a5bb230d94
Parent:
15:210305b5a1fc
Temp (I2C), RGB LED Strip impl.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
marcel1691 14:777f0eb0d1ce 1 /* mbed Microcontroller Library
marcel1691 14:777f0eb0d1ce 2 * Copyright (c) 2015 Marcel (mc-b) Bernet
marcel1691 14:777f0eb0d1ce 3 *
marcel1691 14:777f0eb0d1ce 4 * Licensed under the Apache License, Version 2.0 (the "License");
marcel1691 14:777f0eb0d1ce 5 * you may not use this file except in compliance with the License.
marcel1691 14:777f0eb0d1ce 6 * You may obtain a copy of the License at
marcel1691 14:777f0eb0d1ce 7 *
marcel1691 14:777f0eb0d1ce 8 * http://www.apache.org/licenses/LICENSE-2.0
marcel1691 14:777f0eb0d1ce 9 *
marcel1691 14:777f0eb0d1ce 10 * Unless required by applicable law or agreed to in writing, software
marcel1691 14:777f0eb0d1ce 11 * distributed under the License is distributed on an "AS IS" BASIS,
marcel1691 14:777f0eb0d1ce 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
marcel1691 14:777f0eb0d1ce 13 * See the License for the specific language governing permissions and
marcel1691 14:777f0eb0d1ce 14 * limitations under the License.
marcel1691 14:777f0eb0d1ce 15 */
marcel1691 14:777f0eb0d1ce 16 #ifndef MBED_CLASSES_EXT_H
marcel1691 14:777f0eb0d1ce 17 #define MBED_CLASSES_EXT_H
marcel1691 14:777f0eb0d1ce 18
marcel1691 14:777f0eb0d1ce 19 #include "rpc.h"
marcel1691 14:777f0eb0d1ce 20 #include "Servo.h"
marcel1691 14:777f0eb0d1ce 21 #include "Motor.h"
marcel1691 15:210305b5a1fc 22 #include "StepperMotorUni.h"
marcel1691 16:d0a5bb230d94 23 #include "TMP175.h"
marcel1691 14:777f0eb0d1ce 24
marcel1691 14:777f0eb0d1ce 25 namespace mbed
marcel1691 14:777f0eb0d1ce 26 {
marcel1691 16:d0a5bb230d94 27 /**
marcel1691 16:d0a5bb230d94 28 * Temperatur TMP75 Sensor am I2C Bus
marcel1691 16:d0a5bb230d94 29 */
marcel1691 16:d0a5bb230d94 30 class RpcTMP75 : public RPC
marcel1691 16:d0a5bb230d94 31 {
marcel1691 16:d0a5bb230d94 32 public:
marcel1691 16:d0a5bb230d94 33 RpcTMP75(PinName a0, PinName a1, const char *name=NULL) : RPC(name), o(a0, a1)
marcel1691 16:d0a5bb230d94 34 {
marcel1691 16:d0a5bb230d94 35 o.vSetConfigurationTMP175( SHUTDOWN_MODE_OFF | COMPARATOR_MODE | POLARITY_0 |FAULT_QUEUE_6 | RESOLUTION_12, 0x48 );
marcel1691 16:d0a5bb230d94 36 o.vSetTemperatureLowTMP175( 0.0 );
marcel1691 16:d0a5bb230d94 37 o.vSetTemperatureHighTMP175( 60.0 );
marcel1691 16:d0a5bb230d94 38 }
marcel1691 16:d0a5bb230d94 39
marcel1691 16:d0a5bb230d94 40 int read(void)
marcel1691 16:d0a5bb230d94 41 {
marcel1691 16:d0a5bb230d94 42 return o.fReadTemperatureTMP175();
marcel1691 16:d0a5bb230d94 43 }
marcel1691 16:d0a5bb230d94 44
marcel1691 16:d0a5bb230d94 45 virtual const struct rpc_method *get_rpc_methods()
marcel1691 16:d0a5bb230d94 46 {
marcel1691 16:d0a5bb230d94 47 static const rpc_method rpc_methods[] =
marcel1691 16:d0a5bb230d94 48 {
marcel1691 16:d0a5bb230d94 49 {"read", rpc_method_caller<int, RpcTMP75, &RpcTMP75::read>},
marcel1691 16:d0a5bb230d94 50 RPC_METHOD_SUPER(RPC)
marcel1691 16:d0a5bb230d94 51 };
marcel1691 16:d0a5bb230d94 52 return rpc_methods;
marcel1691 16:d0a5bb230d94 53 }
marcel1691 16:d0a5bb230d94 54 static struct rpc_class *get_rpc_class()
marcel1691 16:d0a5bb230d94 55 {
marcel1691 16:d0a5bb230d94 56 static const rpc_function funcs[] =
marcel1691 16:d0a5bb230d94 57 {
marcel1691 16:d0a5bb230d94 58 {"new", rpc_function_caller<const char*, PinName, PinName, const char*, &RPC::construct<RpcTMP75, PinName, PinName, const char*> >},
marcel1691 16:d0a5bb230d94 59 RPC_METHOD_END
marcel1691 16:d0a5bb230d94 60 };
marcel1691 16:d0a5bb230d94 61 static rpc_class c = {"RpcTMP75", funcs, NULL};
marcel1691 16:d0a5bb230d94 62 return &c;
marcel1691 16:d0a5bb230d94 63 }
marcel1691 16:d0a5bb230d94 64 private:
marcel1691 16:d0a5bb230d94 65 TMP175 o;
marcel1691 16:d0a5bb230d94 66 };
marcel1691 14:777f0eb0d1ce 67
marcel1691 14:777f0eb0d1ce 68 /**
marcel1691 14:777f0eb0d1ce 69 * Servo RPC Template
marcel1691 14:777f0eb0d1ce 70 */
marcel1691 14:777f0eb0d1ce 71 class RpcServo : public RPC
marcel1691 14:777f0eb0d1ce 72 {
marcel1691 14:777f0eb0d1ce 73 public:
marcel1691 16:d0a5bb230d94 74 RpcServo(PinName a0, const char *name=NULL) : RPC(name), o(a0)
marcel1691 16:d0a5bb230d94 75 {
marcel1691 16:d0a5bb230d94 76 // Servo kalibrieren, damit er die vollen 180° verwendet.
marcel1691 16:d0a5bb230d94 77 o.calibrate ( 0.0009, 180.0);
marcel1691 16:d0a5bb230d94 78 }
marcel1691 14:777f0eb0d1ce 79
marcel1691 14:777f0eb0d1ce 80 void write(float a0) {o.write(a0);}
marcel1691 14:777f0eb0d1ce 81 float read(void) {return o.read();}
marcel1691 14:777f0eb0d1ce 82
marcel1691 14:777f0eb0d1ce 83 virtual const struct rpc_method *get_rpc_methods()
marcel1691 14:777f0eb0d1ce 84 {
marcel1691 14:777f0eb0d1ce 85 static const rpc_method rpc_methods[] =
marcel1691 14:777f0eb0d1ce 86 {
marcel1691 14:777f0eb0d1ce 87 {"write", rpc_method_caller<RpcServo, float, &RpcServo::write>},
marcel1691 14:777f0eb0d1ce 88 {"read", rpc_method_caller<float, RpcServo, &RpcServo::read>},
marcel1691 14:777f0eb0d1ce 89 RPC_METHOD_SUPER(RPC)
marcel1691 14:777f0eb0d1ce 90 };
marcel1691 14:777f0eb0d1ce 91 return rpc_methods;
marcel1691 14:777f0eb0d1ce 92 }
marcel1691 14:777f0eb0d1ce 93 static struct rpc_class *get_rpc_class()
marcel1691 14:777f0eb0d1ce 94 {
marcel1691 14:777f0eb0d1ce 95 static const rpc_function funcs[] =
marcel1691 14:777f0eb0d1ce 96 {
marcel1691 14:777f0eb0d1ce 97 {"new", rpc_function_caller<const char*, PinName, const char*, &RPC::construct<RpcServo, PinName, const char*> >},
marcel1691 14:777f0eb0d1ce 98 RPC_METHOD_END
marcel1691 14:777f0eb0d1ce 99 };
marcel1691 14:777f0eb0d1ce 100 static rpc_class c = {"RpcServo", funcs, NULL};
marcel1691 14:777f0eb0d1ce 101 return &c;
marcel1691 14:777f0eb0d1ce 102 }
marcel1691 14:777f0eb0d1ce 103 private:
marcel1691 14:777f0eb0d1ce 104 Servo o;
marcel1691 14:777f0eb0d1ce 105 };
marcel1691 14:777f0eb0d1ce 106
marcel1691 14:777f0eb0d1ce 107 /**
marcel1691 14:777f0eb0d1ce 108 * Motor RPC Template
marcel1691 14:777f0eb0d1ce 109 */
marcel1691 14:777f0eb0d1ce 110 class RpcMotor : public RPC
marcel1691 14:777f0eb0d1ce 111 {
marcel1691 14:777f0eb0d1ce 112 public:
marcel1691 14:777f0eb0d1ce 113 RpcMotor(PinName a0, PinName a1, PinName a2, const char *name=NULL) : RPC(name), o(a0, a1, a2) {}
marcel1691 14:777f0eb0d1ce 114
marcel1691 16:d0a5bb230d94 115 void up () { o.speed( 0.5f ); }
marcel1691 16:d0a5bb230d94 116 void down() { o.speed( -0.5f ); }
marcel1691 16:d0a5bb230d94 117 void stop() { o.speed( 0.0f ); }
marcel1691 14:777f0eb0d1ce 118
marcel1691 14:777f0eb0d1ce 119 virtual const struct rpc_method *get_rpc_methods()
marcel1691 14:777f0eb0d1ce 120 {
marcel1691 14:777f0eb0d1ce 121 static const rpc_method rpc_methods[] =
marcel1691 14:777f0eb0d1ce 122 {
marcel1691 16:d0a5bb230d94 123 {"up", rpc_method_caller<RpcMotor, &RpcMotor::up>},
marcel1691 16:d0a5bb230d94 124 {"down", rpc_method_caller<RpcMotor, &RpcMotor::down>},
marcel1691 16:d0a5bb230d94 125 {"stop", rpc_method_caller<RpcMotor, &RpcMotor::stop>},
marcel1691 14:777f0eb0d1ce 126 RPC_METHOD_SUPER(RPC)
marcel1691 14:777f0eb0d1ce 127 };
marcel1691 14:777f0eb0d1ce 128 return rpc_methods;
marcel1691 14:777f0eb0d1ce 129 }
marcel1691 14:777f0eb0d1ce 130 static struct rpc_class *get_rpc_class()
marcel1691 14:777f0eb0d1ce 131 {
marcel1691 14:777f0eb0d1ce 132 static const rpc_function funcs[] =
marcel1691 14:777f0eb0d1ce 133 {
marcel1691 14:777f0eb0d1ce 134 {"new", rpc_function_caller<const char*, PinName, PinName, PinName, const char*, &RPC::construct<RpcMotor, PinName, PinName, PinName, const char*> >},
marcel1691 14:777f0eb0d1ce 135 RPC_METHOD_END
marcel1691 14:777f0eb0d1ce 136 };
marcel1691 14:777f0eb0d1ce 137 static rpc_class c = {"RpcMotor", funcs, NULL};
marcel1691 14:777f0eb0d1ce 138 return &c;
marcel1691 14:777f0eb0d1ce 139 }
marcel1691 14:777f0eb0d1ce 140 private:
marcel1691 14:777f0eb0d1ce 141 Motor o;
marcel1691 14:777f0eb0d1ce 142 };
marcel1691 14:777f0eb0d1ce 143
marcel1691 15:210305b5a1fc 144 /**
marcel1691 15:210305b5a1fc 145 * Stepper motor mbed RPC Template
marcel1691 15:210305b5a1fc 146 * HACK: PinName direkt angegeben, weil nur max. 3 Argumente zulaessig sind.
marcel1691 15:210305b5a1fc 147 */
marcel1691 15:210305b5a1fc 148 class RpcStepper : public RPC
marcel1691 15:210305b5a1fc 149 {
marcel1691 15:210305b5a1fc 150 public:
marcel1691 15:210305b5a1fc 151 RpcStepper( const char *name=NULL) : RPC(name), o( PTB18, PTB19, PTC1, PTC8 )
marcel1691 15:210305b5a1fc 152 {
marcel1691 15:210305b5a1fc 153 o.set_pps( 300 );
marcel1691 15:210305b5a1fc 154 }
marcel1691 15:210305b5a1fc 155
marcel1691 16:d0a5bb230d94 156 void up () { o.move_steps( 100 ); }
marcel1691 16:d0a5bb230d94 157 void down() { o.move_steps( -100 ); }
marcel1691 15:210305b5a1fc 158
marcel1691 15:210305b5a1fc 159 virtual const struct rpc_method *get_rpc_methods()
marcel1691 15:210305b5a1fc 160 {
marcel1691 15:210305b5a1fc 161 static const rpc_method rpc_methods[] =
marcel1691 15:210305b5a1fc 162 {
marcel1691 16:d0a5bb230d94 163 {"up", rpc_method_caller<RpcStepper, &RpcStepper::up>},
marcel1691 16:d0a5bb230d94 164 {"down", rpc_method_caller<RpcStepper, &RpcStepper::down>},
marcel1691 15:210305b5a1fc 165 RPC_METHOD_SUPER(RPC)
marcel1691 15:210305b5a1fc 166 };
marcel1691 15:210305b5a1fc 167 return rpc_methods;
marcel1691 15:210305b5a1fc 168 }
marcel1691 15:210305b5a1fc 169 static struct rpc_class *get_rpc_class()
marcel1691 15:210305b5a1fc 170 {
marcel1691 15:210305b5a1fc 171 static const rpc_function funcs[] =
marcel1691 15:210305b5a1fc 172 {
marcel1691 15:210305b5a1fc 173 {"new", rpc_function_caller<const char*, const char*, &RPC::construct<RpcStepper, const char*> >},
marcel1691 15:210305b5a1fc 174 RPC_METHOD_END
marcel1691 15:210305b5a1fc 175 };
marcel1691 15:210305b5a1fc 176 static rpc_class c = {"RpcStepper", funcs, NULL};
marcel1691 15:210305b5a1fc 177 return &c;
marcel1691 15:210305b5a1fc 178 }
marcel1691 15:210305b5a1fc 179 private:
marcel1691 15:210305b5a1fc 180 StepperMotorUni o;
marcel1691 15:210305b5a1fc 181 };
marcel1691 15:210305b5a1fc 182
marcel1691 16:d0a5bb230d94 183 /**
marcel1691 16:d0a5bb230d94 184 * RGB LED Strip
marcel1691 16:d0a5bb230d94 185 */
marcel1691 16:d0a5bb230d94 186 class RpcLEDStrip : public RPC
marcel1691 16:d0a5bb230d94 187 {
marcel1691 16:d0a5bb230d94 188 public:
marcel1691 16:d0a5bb230d94 189 RpcLEDStrip(PinName a0, PinName a1, PinName a2, const char *name=NULL) : RPC(name), r(a0), g(a1), b(a2) {}
marcel1691 16:d0a5bb230d94 190
marcel1691 16:d0a5bb230d94 191 void write( int a0 )
marcel1691 16:d0a5bb230d94 192 {
marcel1691 16:d0a5bb230d94 193 //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) );
marcel1691 16:d0a5bb230d94 194 r.write( 1.0f / 255.0f * ((a0 & 0xFF0000) / 65636) );
marcel1691 16:d0a5bb230d94 195 g.write( 1.0f / 255.0f * (a0 & 0xFF00) / 256 );
marcel1691 16:d0a5bb230d94 196 b.write( 1.0f / 255.0f * (a0 & 0xFF) );
marcel1691 16:d0a5bb230d94 197 }
marcel1691 16:d0a5bb230d94 198
marcel1691 16:d0a5bb230d94 199 virtual const struct rpc_method *get_rpc_methods()
marcel1691 16:d0a5bb230d94 200 {
marcel1691 16:d0a5bb230d94 201 static const rpc_method rpc_methods[] =
marcel1691 16:d0a5bb230d94 202 {
marcel1691 16:d0a5bb230d94 203 {"write", rpc_method_caller<RpcLEDStrip, int, &RpcLEDStrip::write>},
marcel1691 16:d0a5bb230d94 204 RPC_METHOD_SUPER(RPC)
marcel1691 16:d0a5bb230d94 205 };
marcel1691 16:d0a5bb230d94 206 return rpc_methods;
marcel1691 16:d0a5bb230d94 207 }
marcel1691 16:d0a5bb230d94 208 static struct rpc_class *get_rpc_class()
marcel1691 16:d0a5bb230d94 209 {
marcel1691 16:d0a5bb230d94 210 static const rpc_function funcs[] =
marcel1691 16:d0a5bb230d94 211 {
marcel1691 16:d0a5bb230d94 212 {"new", rpc_function_caller<const char*, PinName, PinName, PinName, const char*, &RPC::construct<RpcLEDStrip, PinName, PinName, PinName, const char*> >},
marcel1691 16:d0a5bb230d94 213 RPC_METHOD_END
marcel1691 16:d0a5bb230d94 214 };
marcel1691 16:d0a5bb230d94 215 static rpc_class c = {"RpcLEDStrip", funcs, NULL};
marcel1691 16:d0a5bb230d94 216 return &c;
marcel1691 16:d0a5bb230d94 217 }
marcel1691 16:d0a5bb230d94 218 private:
marcel1691 16:d0a5bb230d94 219 PwmOut r;
marcel1691 16:d0a5bb230d94 220 PwmOut g;
marcel1691 16:d0a5bb230d94 221 PwmOut b;
marcel1691 16:d0a5bb230d94 222 };
marcel1691 16:d0a5bb230d94 223
marcel1691 14:777f0eb0d1ce 224 }
marcel1691 14:777f0eb0d1ce 225
marcel1691 14:777f0eb0d1ce 226 #endif