Home automation using Xbee radios
Dependencies: EthernetNetIf HTTPServer RPCInterface mbed C12832_lcd
Diff: main.cpp
- Revision:
- 5:ae3cbcf75d78
- Parent:
- 4:6091cb494e73
- Child:
- 8:e32fcca16102
diff -r 6091cb494e73 -r ae3cbcf75d78 main.cpp --- a/main.cpp Thu Nov 28 21:40:10 2013 +0000 +++ b/main.cpp Mon Dec 02 19:28:26 2013 +0000 @@ -1,8 +1,33 @@ #include "mbed.h" +#include "EthernetNetIf.h" +#include "HTTPServer.h" +#include "SerialRPCInterface.h" DigitalIn pb(p8); +//Create port variables +float ReadTemperatureSensor1; +float ReadTemperatureSensor2; +int ReadMotionDetector1; +int ReadMotionDetector2; +int ReadLightSwitch1; +int ReadLightSwitch2; +int WriteLightSwitch1; +int WriteLightSwitch2; + +//Make these variables accessible over RPC by attaching them to an RPCVariable +RPCVariable<float> RPCTemperatureSensor1(&ReadTemperatureSensor1, "TemperatureSensor1"); +RPCVariable<float> RPCTemperatureSensor2(&ReadTemperatureSensor2, "TemperatureSensor2"); +RPCVariable<int> RPCMotionDetector1(&ReadMotionDetector1, "MotionDetector1"); +RPCVariable<int> RPCMotionDetector2(&ReadMotionDetector2, "MotionDetector2"); +RPCVariable<int> RPCReadLightSwitch1(&ReadLightSwitch1, "ReadLightSwitch1"); +RPCVariable<int> RPCReadLightSwitch2(&ReadLightSwitch2, "ReadLightSwitch2"); +RPCVariable<int> RPCWriteLightSwitch1(&WriteLightSwitch1, "WriteLightSwitch1"); +RPCVariable<int> RPCWriteLightSwitch2(&WriteLightSwitch2, "WriteLightSwitch2"); + +EthernetNetIf eth; +HTTPServer svr; struct xbee { // radio prototype with addresss, location, pointer to sensor list unsigned int addrHigh; // upper 16 bits address of sensor @@ -21,6 +46,23 @@ void analogInputHandle(struct xbee* ,unsigned int , unsigned int , int , float ); int main() { + + // Ethernet Setup + EthernetErr ethErr = eth.setup(); + if(ethErr) + { + printf("Error %d in setup.\n", ethErr); + return -1; + } + printf("Setup OK\n"); + + // Add RPCHandler + svr.addHandler<RPCHandler>("/rpc"); + + // Show that the server is ready and listening + svr.bind(80); + printf("Listening...\n"); + /* This won't change, or we would lose the list in memory */ struct xbee *root; root->next = NULL; @@ -33,6 +75,16 @@ xbee1 = addnode(root,0,1); xbee2 = addnode(root,0,2); xbee3 = addnode(root,0,3); + + // TODO: Read sensors and set RPC variables to initial values + + //Main program loop + while(true){ + Net::poll(); + + // TODO: Poll sensors and reset RPC variables. + + } } struct xbee* addnode(struct xbee* root,unsigned int addrhigh,unsigned int addrlow){