This is the coordinator node.
Dependencies: mbed-rtos mbed Zigbee_communication EthernetInterface WebSocketClient
Diff: main.cpp
- Revision:
- 7:4b85a9051b3a
- Parent:
- 5:7019f4f6b538
- Parent:
- 6:bd6001a78537
diff -r 7019f4f6b538 -r 4b85a9051b3a main.cpp --- a/main.cpp Tue Feb 14 19:59:03 2017 +0000 +++ b/main.cpp Tue Feb 14 21:06:06 2017 +0000 @@ -8,12 +8,17 @@ #include "rtos.h" #include "xbee.h" +#include "EthernetInterface.h" +#include "Websocket.h" + // 4269 Serial pc(USBTX, USBRX); DigitalOut myled(LED1); Mail<char, 250> mymail; -XBee xbee(p8, p13, p14, &mymail); +Mail<char[256], 16> webmail; +XBee xbee(p8, p13, p14, &mymail, &webmail); +Websocket* ws; void ReadSerial() { @@ -28,6 +33,9 @@ char PanID[2] = {PANIDMSB, PANIDLSB}; xbee.SendATCommand('I', 'D', &PanID[0], 2); + wait(5); + xbee.SendATCommand('M','Y'); + xbee.SendATCommand('O','P'); } void BroadcastHelloWorld() @@ -72,6 +80,14 @@ int main() { pc.printf("\r\nI am coordinator\r\n"); + EthernetInterface eth; + eth.init(); //Use DHCP + eth.connect(); + printf("IP Address is %s\n\r", eth.getIPAddress()); + + ws = new Websocket("ws://192.168.137.1:4242"); + ws->connect(); + Ticker ticker; ticker.attach(&tick, 1); @@ -82,8 +98,17 @@ wait(3); ReadSerial(); InitialisePANID(0x42, 0x69); - BroadcastHelloWorld(); while(1) { + osEvent evt = webmail.get(); + if (evt.status == osEventMail) + { + char *c = (char(*))evt.value.p; + // Send email + ws->send("sending"); + ws->send(c); + wait(1); + mymail.free(c); + } } } \ No newline at end of file