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.

Revision:
9:66ff9ae5572e
Parent:
8:3e6bfb96a451
Child:
10:f92d1e679fea
--- a/main.cpp	Sat Mar 07 12:57:40 2015 +0000
+++ b/main.cpp	Wed Mar 11 17:48:42 2015 +0000
@@ -1,111 +1,34 @@
-//#define DNS_SERVER_ADDRESS(ipaddr)        (ip4_addr_set_u32(ipaddr, ipaddr_addr("208.67.222.222"))) /* resolver1.opendns.com */
-
+/** Minimalistischer RCP HTTP Server
+*/
 #include "mbed.h"
 #include "rtos.h"
 #include "EthernetInterface.h"
 #include "HTTPServer.h"
 #include "mbed_rpc.h"
-#include "SDFileSystem.h"
 
 EthernetInterface eth;
 
-DigitalOut led4(LED4);
-
-//LocalFileSystem local("local");
-SDFileSystem sd(PTE3, PTE1, PTE2, PTE4, "local"); 
-
-static float value = 20;
-
-class AnalogInHandler : public SimpleHandler
-{
-public:
-  AnalogInHandler(const char* rootPath, const char* path, TCPSocketConnection* pTCPSocketConnection) : SimpleHandler(rootPath, path, pTCPSocketConnection) { }
-  virtual ~AnalogInHandler() {}
-
-//protected:
-  static inline HTTPRequestHandler* inst(const char* rootPath, const char* path, TCPSocketConnection* pTCPSocketConnection) { return new AnalogInHandler(rootPath, path, pTCPSocketConnection); } //if we ever could do static virtual functions, this would be one
-  
-  virtual void doGet()
-  {
-    char buf[20];
-    sprintf( buf, "%f", value );
-    value += 0.01;
-    setContentLen( strlen(buf) );
-    respHeaders()["Connection"] = "close";
-    writeData(buf, strlen(buf));
-  }
-  
-};
-
-void aliveState(void const *args)
-{
-    while (true) 
-    {
-        led4 = !led4;
-        Thread::wait(2000);
-    }
-}
-
-uint32_t do_list(const char *fsrc)
-{
-    DIR *d = opendir(fsrc);
-    struct dirent *p;
-    uint32_t counter = 0;
-
-    while ((p = readdir(d)) != NULL) {
-        counter++;
-        printf("%s\n", p->d_name);
-    }
-    closedir(d);
-    return counter;
-}
-
 int main()
 {
-    printf("********* PROGRAM START ***********\r\n");
-    Thread thread(aliveState);
-    
-    // LED's
+    printf("RPC HTTP Server\n");
+    eth.init(); //Use DHCP
+    eth.connect();
+    printf("IP Address is %s\n\r", eth.getIPAddress());
+        
+    // Klassen
     RPC::add_rpc_class<RpcDigitalOut>();
-    RPC::construct<RpcDigitalOut, PinName, const char*>(PTC3, "led1");
-    RPC::construct<RpcDigitalOut, PinName, const char*>(PTC2, "led2");
-    RPC::construct<RpcDigitalOut, PinName, const char*>(PTA2, "led3");
     
-    // Sensoren bringt Linkfehler
-    //RPC::add_rpc_class<RpcAnalogIn>();    
-    //RPC::construct<RpcAnalogIn, PinName, const char*>(PTB3, "s1");
-    //RPCFunction rpcFunc(LcdWrite, "LcdWrite"); //ADD Here!!
-    
+    // Objekte
+    RPC::construct<RpcDigitalOut, PinName, const char*>(D10, "led1");
+    RPC::construct<RpcDigitalOut, PinName, const char*>(D11, "led2");
+    RPC::construct<RpcDigitalOut, PinName, const char*>(D12, "led3");
+    RPC::construct<RpcDigitalOut, PinName, const char*>(D13, "led4");
 
-    printf("EthernetInterface Setting up...\r\n");
-    if(eth.init()!=0) 
-    {                             //for DHCP Server
-        //if(eth.init(IPAddress,NetMasks,Gateway)!=0) { //for Static IP Address
-        printf("EthernetInterface Initialize Error \r\n");
-        return -1;
-    }
-    if(eth.connect()!=0) 
-    {
-        printf("EthernetInterface Connect Error \r\n");
-        return -1;
-    }
-    printf("IP Address is %s\r\n", eth.getIPAddress());
-    printf("NetMask is %s\r\n", eth.getNetworkMask());
-    printf("Gateway Address is %s\r\n", eth.getGateway());
-    printf("Ethernet Setup OK\r\n");
-
-    printf("\nList all directories/files /local.\n");
-    do_list("/local");
-
-    //HTTPServerAddHandler<SimpleHandler>("/hello"); //Default handler
-    HTTPServerAddHandler<AnalogInHandler>("/analogIn"); //Default handler    
-    FSHandler::mount("/local", "/");
-    HTTPServerAddHandler<FSHandler>("/");
+    // Handler
     HTTPServerAddHandler<RPCHandler>("/rpc");
+    
+    // Start HTTP Server auf Port 80
+    printf( "Starte Server\n" );
     HTTPServerStart(80);
 }
 
-void LcdWrite(Arguments* arg, Reply* r)  //ADD Here!!
-{
-    printf("%s",arg->argv[0]);
-}