What IoT actually stands for? In order to analyze in more depth, the subject we need to define some basic concepts about this kind of young technology. IoT is the acronym of Internet of Things, a network of hardware, mainly used for automation and data logging in order to simplify every day tasks both in industry and in every day life. Usually these kind of equipment are connected together to form a network over the internet.

The first mentioning of IoT was made in 1999 by Kevin Ashton during one of his presentation. Todays IoT is all around us starting from simple smart gadgets mainly designed for home and office use till serious surveillance and security systems used by the military and airports.
As you can see on the first image a basic IoT network is made out of three components. The first, WeMos the starting point of the chain – takes care of collecting data and transmitting to the closest WiFi hotspot. The second is a common WiFi equipped router, links the WeMos to the internet. The third one is AT&Ts cloud service, called M2X. No, it is not full of vegetables as presented on the picture. It takes care of collecting and storing the data transmitted by the WeMos.
But how can we setup fast and for low price such a device? Actually it is more cheap and easy as it sounds. There are several online platforms available nowadays for IoT projects. One of the best is called M2X and it is developed by AT&T corporation. Its free version has some limitations of course, but comes with a lot of advantages:
- Large and explicit documentation
- Huge number of APIs for numerous environments like Arduino, Python, PHP, C, Java, JavaScript, .NET and many others
- Easy to use
- Ready made charts, maps and triggers
One of the cheapest hardware solution I could find for WiFi based applications is the so called WeMos D1 R2, which cost me around 7 euros from a local shop here in Košice. Which is a good price if we keep in mind what we get for that price, lets see the specifications:
- 80 or 160MHz selectable operating frequency
- 11 IO pins: one analog input, PWM/I2C/one-wire support (except D0 pin)
- 3v3 voltage level
- 4MB flash
- ESP8266 chipset
- Http host and client support
- Wifi capability
There are two methods how you can easily flash the Wemos D1:
- Arduino IDE: it is possible to write and compile software directly in Arduino official IDE, with the necessary libraries installed, in C/C++ language, this article will deal with this method.
- NodeMCU: the original IDE for managing these boards, its language is Python
Hopefully you already have the latest Arduino IDE downloaded and installed on your PC, if not you can get it from this link: arduino-1.8.7-windows.exe
Step 1:
Fire it up, and go to File -> Preferences (or shortcut Ctrl + comma ) , than copy the following address into the Additional Boards Manager URLs: http://arduino.esp8266.com/stable/package_esp8266com_index.json
Step 2:
After this step, go to Tools -> Board: “current board” -> Boards Manager. In the search bar type ESP82666, and download the ESP8266 library developed by ESP8266 Community.
After installing the library select the corresponding board (in this case WeMos D1 R1), from Tools -> Board: “WeMos D1 R1”.
It is recommended to try flashing your board before getting into more serious things with a simple Blink code, to verify if the installed libraries are up and running fine. For this task you can find a lot of examples under Files -> Examples.
Step 3:
If everything went as it was supposed to be it is time to download the library for Arduino from AT&T Github page (link: https://github.com/attm2x/m2x-arduino ) and install it with the in-built *.zip installer, (Sketch -> Include Library -> Add .ZIP library).
Step 4:
For now we are finished with the necessary hardware and software preparation, it is time to create a new account or login into the existing one, at https://m2x.att.com and create a new device.
The last step on the AT&Ts website is to Add a new stream to the device.
Step 5:
Everything is ready to test out the setup. For this paste this code into your IDE:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
#include <ESP8266WiFi.h> #define ESP8266_PLATFORM #include "M2XStreamClient.h" char ssid[] = "change it"; // your network SSID (name) char pass[] = "change it"; // your network password (use for WPA, or use as key for WEP) int keyIndex = 0; // your network key Index number (needed only for WEP) int status = WL_IDLE_STATUS; char deviceId[] = "GET IT FROM M2X"; // Device you want to push to char streamName[] = "GET IT FROM M2X"; // Stream you want to push to char m2xKey[] = "GET IT FROM M2X"; // Your M2X access key const int temperaturePin = 0; WiFiClient client; M2XStreamClient m2xClient(&client, m2xKey); void setup() { Serial.begin(9600); while (status != WL_CONNECTED) { Serial.print("Attempting to connect to SSID: "); Serial.println(ssid); // Connect to WPA/WPA2 network. Change this line if using open or WEP network: status = WiFi.begin(ssid, pass); // wait 10 seconds for connection: delay(10000); } Serial.println("Connected to wifi"); printWifiStatus(); } void loop() { int randomValue = random(1995); //generating a random number between 0 - 1995 Serial.print("random value: "); Serial.println(randomValue); int response = m2xClient.updateStreamValue(deviceId, streamName, degreesC); Serial.print("M2x client response code: "); Serial.println(response); if (response == -1) while(1) ; delay(1000*60);// sends a random value every 1 minutes } void printWifiStatus() { // print the SSID of the network you're attached to: Serial.print("SSID: "); Serial.println(WiFi.SSID()); // print your WiFi shield's IP address: IPAddress ip = WiFi.localIP(); Serial.print("IP Address: "); Serial.println(ip); // print the received signal strength: long rssi = WiFi.RSSI(); Serial.print("signal strength (RSSI):"); Serial.print(rssi); Serial.println(" dBm"); } |
I would like to mention that I am not the author of this source code, I have just modified the original example code that was included in the examples library by AT&T.
After uploading the source code to the WeMos D1 and refreshing M2X you should see the incoming data from your device, something similar as mine on the right.
Wait! There are more possibilities with M2X! You can create custom dashboards, where you can add widgets like charts (bar, radial), stream activity, geographic maps. Also these widgets can be embedded into external websites, like the one below:
Basically this would be the main idea behind IoT, how you send data to a remote server and store it. Of course there is much more what could be done, like sending commands to the WeMos D1 R2 or storing and also analyzing the remotely received data. This will be an other article, how many other things you can do with these cheap equipment. Possibilities are unlimited.