When ESP8266 Meets Ubidots
When ESP8266 Meets Ubidots
Wondering how to get access for real time data analytics and visualization? Well then here’s the solution!! Yes you heard it right. In this guide you will learn how to connect Node MCU to Ubidots for sending and receiving data i.e POST and GET data to/from Ubidots. For more information about POST and GET refer POST and GET. Here we are going to work with temperature and humidity data.
There are many cloud platforms where you can send sensor data to cloud so that you can analyze and visualize your data. Out of all the platforms I found Ubidots to be more convenient platform for users.
Supplies
Hardware & Software Requirements :
- NodeMCU
- An active Ubidots account.
- Arduino Ubidots Library for NodeMCU
- Of course.....Arduino IDE
- DHT11 sensor
- Jumper wires
- Breadboard (optional)
Create an Ubidots Account:
To begin the work you need to create an Ubidots account. So Sign up to Ubidots. Click Sign up to create an account. After your account is created you need to create dashboard and widgets for data interpretation. There are various options available for the interpretation of data like pie chart, bar chart, histogram, double axis, line chart etc. For more information about creating dashboards and widgets you may refer to Dashboard and Widgets. Here i have represented the temperature and humidity data in the form of pie chart and bar chart.
Install Arduino IDE
After signing up the Ubidots account to begin the work you also need to download and install the Arduino IDE software on your computer. Refer Download Arduino for downloading and installation of Arduino IDE.
Library Installation
NodeMCU is an third party compatible device with Arduino IDE. Hence to interface NodeMCU with Arduino it is important to connect them. This connection can be established by installing the Ubidots libraries in the Arduino IDE. Here are the two options for library installation:
1.Download from Github:
i. For downloading library go to the Github website, click on the code i.e. green button and Download ZIP.
ii. Open the Arduino IDE click Sketch > Include Library >Add .ZIP Library.
iii. Select the .ZIP file saved recently and then “Accept”.
iv. Close the Arduino IDE and reopen it to continue working.
2.Install from library management of Arduino IDE:
i. Go to Sketch/Program > Include Library > Library Manager and install the library of Ubidots.
ii. To simply find the correct library, search "Ubidots" within the search bar.
iii. Then press “Install” and wait until the installation is complete.
iv. Close the Arduino IDE and reopen it to continue working.
IMPORTANT NOTE: If the library is not available in the Arduino IDE Library Manager, please refer to the Option 1 to install the library of Ubidots.
Installation and Selection of Board and Platform.
i. Open the Arduino IDE, select Files > Preferences and enter the URL : http://arduino.esp8266.com/stable/package_esp8266com_index.json into Additional Board Manager URLs field.
IMPORTANT NOTE: You can add multiple URLs by separating them with commas.
ii. Now go to Tools > Board > Boards Manager and search for esp8266 board. Once you see the ESP listing, click on install button. This will take around 10 to 15 minutes to install. Enjoy your snacks (if you have around... LOL) till then...!!!
iii. Now select the board from Tools > Board > NodeMCU 1.0 (This board may appear in separate ESP category in boards menu) to continue working. Done for now.... lets move in to next step...!!!
Connections
Now lets see some hardware part.....!Lets begin with the connections. You have to make connections between DHT11 sensor and NodeMCU. Don't panic..... the connections are very simple and the circuit diagram is provided. After the connection of NodeMCU and DHT11 is completed, connect the NodeMCU to your PC to proceed.
It's Coding Time...!!!
To start posting & getting the data from DHT11 sensor to & from Ubidots two different programs are needed. Code for this project is uploaded on GitHub. You can download the code from here. Download & open the repository. You will find two folders in it : one is for posting data & another is for getting data. Open the Posting Data code first and then set the following parameters in code :
1. SSID (Wi-Fi name) and password of your Wi-Fi network.
2. Your Ubidots TOKEN
Now you might be thinking what is Ubidots Token and where it is found? It is an authentication key given for each and every registered user, for getting your token follow the steps:
1. Go to your Ubidots account.
2. Click on user tab and click on API Credentials. You will get your TOKEN.
And that's it.... After setting all this parameters in code, just move on to next step.
Let's Compile & Upload the Code - Part 1 : Sending Data to Ubidots
Once you are done with writing the code follow the steps:
1. To verify/compile the code, press the "Check Mark" symbol located in the top left corner of the Arduino IDE. Once the code is verified, you will receive this response message in the Arduino IDE: Done compiling.
2. To upload the code press the "Right-Arrow" icon beside the check mark. Once the code is uploaded, you will receive the message below in the Arduino IDE: Done uploading.
3.Now the code is uploaded on the board, you can see the messages passed on to the board. To do this, open the Serial Monitor of the Arduino IDE i.e. by pressing the "Magnifying Glass" icon located in the top right corner of our Arduino IDE.
IMPORTANT NOTE: If the response is not seen on serial monitor, try plugging the NodeMCU and plugging it back again. Also check the baud rate of the serial monitor is same as mentioned in your code.
Is my data POSTed ?
Confirm whether the temperature and humidity data is uploaded on your Ubidots dashboard. If not, check the credentials mentioned in program whether it is correct OR not.
Let's Compile & Upload the Code - Part 2 : Getting Data From Ubidots (GET Method)
Well... now you have successfully POSTed data on ubidots. But what if you want to read it back from ubidots in Arduino (NodeMCU)...??? To do this, we need a GET method. Open the code for Getting data which is downloaded earlier from github & set following parameters just like previous code :
1.SSID (Wi-Fi name) and password of your Wi-Fi network.
2.Your Ubidots TOKEN
3. Your Device Label (Read note below)
4. Variable Label (Read note below)
Note : While posting the data you have came to know about the Ubidots Token now we will discuss about the Device label and the Variable label. Device label is a label of the device which can be found in your Ubidots account > Devices. The variable label is the form in which you want the data.
PLEASE NOTE: The device and variable label should be defined in the following line of code:
ubidots.get("********", "temperature"); //replace stars with token
ubidots.get("********", "humidity"); //replace stars with token
Once you are done with writing the code follow all the steps same as you did for posting data. i.e. compile, upload, and then you can see the data in serial monitor.
IMPORTANT NOTE: If response is not seen try plugging the NodeMCU and plugging it again. Also check the baud rate of the serial monitor is same as mentioned in your code.
SUMMARY:
I have tried my best to make this guide understandable. By following this instructable you will be able to POST and GET data with the help of NodeMCU and Ubidots with an ease. Do put the proper SSID and password of your connection to avoid panic situation and don’t forget to put the authentication key i.e. your device label. Avoid putting wrong Device label or you will not get the result. With proper SSID, Password and Device label you will surely succeed in this project. Hopefully very soon i will upload the next instructable for the same experiment, but by using ESP32 & some another sort of sensor. Till then, enjoy this project....!!! (This project is performed and documented by Punyokti Patil - Trainee Intern at Aerobotix Techsolutions). My this article has also been approved for the first author post contest on instructables itself. Do share your suggestions about this project in comments section below...!!!