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.
headers/globals.h@1:4403f2ed1c1f, 2016-10-04 (annotated)
- Committer:
- defrost
- Date:
- Tue Oct 04 13:19:19 2016 +0000
- Revision:
- 1:4403f2ed1c1f
- Child:
- 2:7abdaa5a9209
- Temperature sensor with injected channel conversion
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
defrost | 1:4403f2ed1c1f | 1 | // ************* |
defrost | 1:4403f2ed1c1f | 2 | // * globals.h * |
defrost | 1:4403f2ed1c1f | 3 | // ************* |
defrost | 1:4403f2ed1c1f | 4 | // |
defrost | 1:4403f2ed1c1f | 5 | // Created: 2015/03/19 |
defrost | 1:4403f2ed1c1f | 6 | // By: Damien Frost |
defrost | 1:4403f2ed1c1f | 7 | // |
defrost | 1:4403f2ed1c1f | 8 | // Description: |
defrost | 1:4403f2ed1c1f | 9 | // Provides global definitions. |
defrost | 1:4403f2ed1c1f | 10 | |
defrost | 1:4403f2ed1c1f | 11 | #ifndef IQ_GLOBALS_H |
defrost | 1:4403f2ed1c1f | 12 | #define IQ_GLOBALS_H |
defrost | 1:4403f2ed1c1f | 13 | |
defrost | 1:4403f2ed1c1f | 14 | #include "mbed.h" |
defrost | 1:4403f2ed1c1f | 15 | #include "WiflyInterface.h" |
defrost | 1:4403f2ed1c1f | 16 | #include "Commands.h" |
defrost | 1:4403f2ed1c1f | 17 | #include "Websocket.h" |
defrost | 1:4403f2ed1c1f | 18 | |
defrost | 1:4403f2ed1c1f | 19 | |
defrost | 1:4403f2ed1c1f | 20 | // Wifi Interface defines: |
defrost | 1:4403f2ed1c1f | 21 | #define TCP_SERVER_PORT 4445 |
defrost | 1:4403f2ed1c1f | 22 | #define WIFIBAUDRATE 115200 |
defrost | 1:4403f2ed1c1f | 23 | #define WIFINETWORK 2 |
defrost | 1:4403f2ed1c1f | 24 | #define CHARMSGBUFF 1024 |
defrost | 1:4403f2ed1c1f | 25 | #define TIMEOUTRECEIVEATTEMPTS 5 |
defrost | 1:4403f2ed1c1f | 26 | #define WS_PORT 4444 |
defrost | 1:4403f2ed1c1f | 27 | #define SERVER_IP "192.168.0.3" |
defrost | 1:4403f2ed1c1f | 28 | |
defrost | 1:4403f2ed1c1f | 29 | extern char* wifissid; |
defrost | 1:4403f2ed1c1f | 30 | extern char* wifipassword; |
defrost | 1:4403f2ed1c1f | 31 | |
defrost | 1:4403f2ed1c1f | 32 | extern Serial pc; |
defrost | 1:4403f2ed1c1f | 33 | extern InterruptIn UIBut1; |
defrost | 1:4403f2ed1c1f | 34 | extern Timer DisplayTimer; |
defrost | 1:4403f2ed1c1f | 35 | |
defrost | 1:4403f2ed1c1f | 36 | extern WiflyInterface eth; |
defrost | 1:4403f2ed1c1f | 37 | |
defrost | 1:4403f2ed1c1f | 38 | extern int ReconnectAttempts; |
defrost | 1:4403f2ed1c1f | 39 | extern int SendCounter; |
defrost | 1:4403f2ed1c1f | 40 | extern int IoT_ID; |
defrost | 1:4403f2ed1c1f | 41 | extern float TempSensor; |
defrost | 1:4403f2ed1c1f | 42 | |
defrost | 1:4403f2ed1c1f | 43 | extern Websocket ws; |
defrost | 1:4403f2ed1c1f | 44 | |
defrost | 1:4403f2ed1c1f | 45 | // Functions: |
defrost | 1:4403f2ed1c1f | 46 | void SensorToPu(float gain, float offset, int sensor, float* result); |
defrost | 1:4403f2ed1c1f | 47 | void InitializeStruct(struct tf_history_t* toClear); |
defrost | 1:4403f2ed1c1f | 48 | void SetupVar(void); |
defrost | 1:4403f2ed1c1f | 49 | void SetButtonEvent(void); |
defrost | 1:4403f2ed1c1f | 50 | void rt_OneStep(void); |
defrost | 1:4403f2ed1c1f | 51 | void DisplayInputs(float CPS); |
defrost | 1:4403f2ed1c1f | 52 | void SetSCKDCParams(bool enable, float gain); |
defrost | 1:4403f2ed1c1f | 53 | int SetupNetwork(int Tries); |
defrost | 1:4403f2ed1c1f | 54 | bool ConnectToServer(int Tries); |
defrost | 1:4403f2ed1c1f | 55 | void SendNetworkData(void); |
defrost | 1:4403f2ed1c1f | 56 | void ReceiveNetworkData(unsigned int * wifi_cmd, unsigned int * var, float * value); |
defrost | 1:4403f2ed1c1f | 57 | void ModifyVariable(unsigned int wifi_var, float wifi_data); |
defrost | 1:4403f2ed1c1f | 58 | |
defrost | 1:4403f2ed1c1f | 59 | |
defrost | 1:4403f2ed1c1f | 60 | #endif /* IQ_GLOBALS_H */ |
defrost | 1:4403f2ed1c1f | 61 |