![](/media/cache/profiles/c19a46c712c75b70a137f619a0916436.jpg.50x50_q85.png)
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.
Revision 8:5afd599875e4, committed 2016-11-24
- Comitter:
- defrost
- Date:
- Thu Nov 24 16:54:56 2016 +0000
- Parent:
- 7:bd21c60b5dd2
- Commit message:
- - Updated messages.h to its own library
Changed in this revision
diff -r bd21c60b5dd2 -r 5afd599875e4 WiflyInterface.lib --- a/WiflyInterface.lib Thu Oct 06 08:05:21 2016 +0000 +++ b/WiflyInterface.lib Thu Nov 24 16:54:56 2016 +0000 @@ -1,1 +1,1 @@ -https://developer.mbed.org/users/defrost/code/WiflyInterface/#7f2f9f78f866 +https://developer.mbed.org/users/defrost/code/WiflyInterface/#e08d655acee6
diff -r bd21c60b5dd2 -r 5afd599875e4 main.cpp --- a/main.cpp Thu Oct 06 08:05:21 2016 +0000 +++ b/main.cpp Thu Nov 24 16:54:56 2016 +0000 @@ -54,7 +54,7 @@ char msg[128]; // Set the IoT ID: - IoT_ID = 1; + IoT_ID = 5; // Set the Auto reconnect flag: IotStatus.SetFlag(SF_AUTOCONNECT);
diff -r bd21c60b5dd2 -r 5afd599875e4 messages.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/messages.lib Thu Nov 24 16:54:56 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/defrost/code/messages/#7968911e2787
diff -r bd21c60b5dd2 -r 5afd599875e4 source/globals.cpp --- a/source/globals.cpp Thu Oct 06 08:05:21 2016 +0000 +++ b/source/globals.cpp Thu Nov 24 16:54:56 2016 +0000 @@ -44,18 +44,18 @@ Serial pc(USBTX, USBRX); InterruptIn UIBut1(USER_BUTTON); Timer DisplayTimer; -DigitalOut Led(LED1); +DigitalOut Led(D5); // Global variable declarations: int ReconnectAttempts = 0; int SendCounter = 0; extern int IoT_ID = 0; float TempSensor = 0.0f; -char* wifissid = "MyHomeNetwork"; -char* wifipassword = "MyHomeNetworkPassword"; +char* wifissid = "SC"; +char* wifipassword = "smartcellshield"; // Wifily interface declaration: -WiflyInterface eth(D8, D2, D6, D5, wifissid, wifipassword, WPA2); +WiflyInterface eth(D8, D2, D6, LED1, wifissid, wifipassword, WPA2); // WebSocket declaration: Websocket ws;