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:
Wed Aug 26 19:37:26 2015 +0000
Revision:
15:210305b5a1fc
Parent:
14:777f0eb0d1ce
Child:
16:d0a5bb230d94
Stepper integriert

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 14:777f0eb0d1ce 23
marcel1691 14:777f0eb0d1ce 24 namespace mbed
marcel1691 14:777f0eb0d1ce 25 {
marcel1691 14:777f0eb0d1ce 26
marcel1691 14:777f0eb0d1ce 27 /**
marcel1691 14:777f0eb0d1ce 28 * Servo RPC Template
marcel1691 14:777f0eb0d1ce 29 */
marcel1691 14:777f0eb0d1ce 30 class RpcServo : public RPC
marcel1691 14:777f0eb0d1ce 31 {
marcel1691 14:777f0eb0d1ce 32 public:
marcel1691 14:777f0eb0d1ce 33 RpcServo(PinName a0, const char *name=NULL) : RPC(name), o(a0) {}
marcel1691 14:777f0eb0d1ce 34
marcel1691 14:777f0eb0d1ce 35 void write(float a0) {o.write(a0);}
marcel1691 14:777f0eb0d1ce 36 float read(void) {return o.read();}
marcel1691 14:777f0eb0d1ce 37
marcel1691 14:777f0eb0d1ce 38 virtual const struct rpc_method *get_rpc_methods()
marcel1691 14:777f0eb0d1ce 39 {
marcel1691 14:777f0eb0d1ce 40 static const rpc_method rpc_methods[] =
marcel1691 14:777f0eb0d1ce 41 {
marcel1691 14:777f0eb0d1ce 42 {"write", rpc_method_caller<RpcServo, float, &RpcServo::write>},
marcel1691 14:777f0eb0d1ce 43 {"read", rpc_method_caller<float, RpcServo, &RpcServo::read>},
marcel1691 14:777f0eb0d1ce 44 RPC_METHOD_SUPER(RPC)
marcel1691 14:777f0eb0d1ce 45 };
marcel1691 14:777f0eb0d1ce 46 return rpc_methods;
marcel1691 14:777f0eb0d1ce 47 }
marcel1691 14:777f0eb0d1ce 48 static struct rpc_class *get_rpc_class()
marcel1691 14:777f0eb0d1ce 49 {
marcel1691 14:777f0eb0d1ce 50 static const rpc_function funcs[] =
marcel1691 14:777f0eb0d1ce 51 {
marcel1691 14:777f0eb0d1ce 52 {"new", rpc_function_caller<const char*, PinName, const char*, &RPC::construct<RpcServo, PinName, const char*> >},
marcel1691 14:777f0eb0d1ce 53 RPC_METHOD_END
marcel1691 14:777f0eb0d1ce 54 };
marcel1691 14:777f0eb0d1ce 55 static rpc_class c = {"RpcServo", funcs, NULL};
marcel1691 14:777f0eb0d1ce 56 return &c;
marcel1691 14:777f0eb0d1ce 57 }
marcel1691 14:777f0eb0d1ce 58 private:
marcel1691 14:777f0eb0d1ce 59 Servo o;
marcel1691 14:777f0eb0d1ce 60 };
marcel1691 14:777f0eb0d1ce 61
marcel1691 14:777f0eb0d1ce 62 /**
marcel1691 14:777f0eb0d1ce 63 * Motor RPC Template
marcel1691 14:777f0eb0d1ce 64 */
marcel1691 14:777f0eb0d1ce 65 class RpcMotor : public RPC
marcel1691 14:777f0eb0d1ce 66 {
marcel1691 14:777f0eb0d1ce 67 public:
marcel1691 14:777f0eb0d1ce 68 RpcMotor(PinName a0, PinName a1, PinName a2, const char *name=NULL) : RPC(name), o(a0, a1, a2) {}
marcel1691 14:777f0eb0d1ce 69
marcel1691 14:777f0eb0d1ce 70 void write(float a0) {o.speed(a0);}
marcel1691 14:777f0eb0d1ce 71
marcel1691 14:777f0eb0d1ce 72 virtual const struct rpc_method *get_rpc_methods()
marcel1691 14:777f0eb0d1ce 73 {
marcel1691 14:777f0eb0d1ce 74 static const rpc_method rpc_methods[] =
marcel1691 14:777f0eb0d1ce 75 {
marcel1691 14:777f0eb0d1ce 76 {"write", rpc_method_caller<RpcMotor, float, &RpcMotor::write>},
marcel1691 14:777f0eb0d1ce 77 RPC_METHOD_SUPER(RPC)
marcel1691 14:777f0eb0d1ce 78 };
marcel1691 14:777f0eb0d1ce 79 return rpc_methods;
marcel1691 14:777f0eb0d1ce 80 }
marcel1691 14:777f0eb0d1ce 81 static struct rpc_class *get_rpc_class()
marcel1691 14:777f0eb0d1ce 82 {
marcel1691 14:777f0eb0d1ce 83 static const rpc_function funcs[] =
marcel1691 14:777f0eb0d1ce 84 {
marcel1691 14:777f0eb0d1ce 85 {"new", rpc_function_caller<const char*, PinName, PinName, PinName, const char*, &RPC::construct<RpcMotor, PinName, PinName, PinName, const char*> >},
marcel1691 14:777f0eb0d1ce 86 RPC_METHOD_END
marcel1691 14:777f0eb0d1ce 87 };
marcel1691 14:777f0eb0d1ce 88 static rpc_class c = {"RpcMotor", funcs, NULL};
marcel1691 14:777f0eb0d1ce 89 return &c;
marcel1691 14:777f0eb0d1ce 90 }
marcel1691 14:777f0eb0d1ce 91 private:
marcel1691 14:777f0eb0d1ce 92 Motor o;
marcel1691 14:777f0eb0d1ce 93 };
marcel1691 14:777f0eb0d1ce 94
marcel1691 15:210305b5a1fc 95 /**
marcel1691 15:210305b5a1fc 96 * Stepper motor mbed RPC Template
marcel1691 15:210305b5a1fc 97 * HACK: PinName direkt angegeben, weil nur max. 3 Argumente zulaessig sind.
marcel1691 15:210305b5a1fc 98 */
marcel1691 15:210305b5a1fc 99 class RpcStepper : public RPC
marcel1691 15:210305b5a1fc 100 {
marcel1691 15:210305b5a1fc 101 public:
marcel1691 15:210305b5a1fc 102 RpcStepper( const char *name=NULL) : RPC(name), o( PTB18, PTB19, PTC1, PTC8 )
marcel1691 15:210305b5a1fc 103 {
marcel1691 15:210305b5a1fc 104 o.set_pps( 300 );
marcel1691 15:210305b5a1fc 105 }
marcel1691 15:210305b5a1fc 106
marcel1691 15:210305b5a1fc 107 void write(int a0) {o.move_steps(a0);}
marcel1691 15:210305b5a1fc 108
marcel1691 15:210305b5a1fc 109 virtual const struct rpc_method *get_rpc_methods()
marcel1691 15:210305b5a1fc 110 {
marcel1691 15:210305b5a1fc 111 static const rpc_method rpc_methods[] =
marcel1691 15:210305b5a1fc 112 {
marcel1691 15:210305b5a1fc 113 { "write", rpc_method_caller<RpcStepper, int, &RpcStepper::write> },
marcel1691 15:210305b5a1fc 114 RPC_METHOD_SUPER(RPC)
marcel1691 15:210305b5a1fc 115 };
marcel1691 15:210305b5a1fc 116 return rpc_methods;
marcel1691 15:210305b5a1fc 117 }
marcel1691 15:210305b5a1fc 118 static struct rpc_class *get_rpc_class()
marcel1691 15:210305b5a1fc 119 {
marcel1691 15:210305b5a1fc 120 static const rpc_function funcs[] =
marcel1691 15:210305b5a1fc 121 {
marcel1691 15:210305b5a1fc 122 {"new", rpc_function_caller<const char*, const char*, &RPC::construct<RpcStepper, const char*> >},
marcel1691 15:210305b5a1fc 123 RPC_METHOD_END
marcel1691 15:210305b5a1fc 124 };
marcel1691 15:210305b5a1fc 125 static rpc_class c = {"RpcStepper", funcs, NULL};
marcel1691 15:210305b5a1fc 126 return &c;
marcel1691 15:210305b5a1fc 127 }
marcel1691 15:210305b5a1fc 128 private:
marcel1691 15:210305b5a1fc 129 StepperMotorUni o;
marcel1691 15:210305b5a1fc 130 };
marcel1691 15:210305b5a1fc 131
marcel1691 14:777f0eb0d1ce 132 }
marcel1691 14:777f0eb0d1ce 133
marcel1691 14:777f0eb0d1ce 134 #endif