Example program to create IoT devices for a local network, which connect to a local server.
Dependencies: WebSocketClient WiflyInterface mbed messages
This code is used in the second part of my Internet of Things (IoT) blog post available here. The code is fairly simple, but its real value is in its reliability. I have worked hard to try to make the wireless connection as reliable, and as fast, as possible. There are a few lines of code that must be modified before it will work correctly, and those are described in the following Wiki pages.
It is designed to work with a Python WebSocket Server running on a PC, the source code of which is available here.
Once operating with the server, each microcontroller, or IoT device, will broadcast a counter and its internal temperature to your WebSocket Server.
Diff: source/globals.cpp
- Revision:
- 3:f20e114eb2ee
- Parent:
- 2:7abdaa5a9209
- Child:
- 5:0c7d131e6089
--- a/source/globals.cpp Tue Oct 04 13:59:13 2016 +0000 +++ b/source/globals.cpp Tue Oct 04 16:20:14 2016 +0000 @@ -23,7 +23,7 @@ Timer DisplayTimer; DigitalOut Led(LED1); -WiflyInterface eth(D8, D2, D6, LED1, wifissid, wifipassword, WPA2); +WiflyInterface eth(D8, D2, D6, D5, wifissid, wifipassword, WPA2); int ReconnectAttempts = 0; int SendCounter = 0; @@ -140,10 +140,7 @@ INFO("Received: %s", msg_buffer); sscanf(msg_buffer, "%d,%s", wifi_cmd, msg_buffer2); if(*wifi_cmd == CHANGEVAR_WIFI_CMD){ - // Get two more values: - sscanf(msg_buffer2, "%d,%f", var, value); - }else{ - // Get one: + // Get one more value: sscanf(msg_buffer2, "%f", value); } }else if(resp == -1){ @@ -163,7 +160,11 @@ // modifies something in the SCS Controller: switch(wifi_var){ case CV_LED: - + if(wifi_data > 0){ + Led = 1; + }else{ + Led = 0; + } break; default: