We previously published some tutorials on how to read atmospheric variables using the WisBlock Starter Kit and send it via LoRa® P2P to another WisBlock. In this tutorial, we want to send atmospheric variables to the cloud, specifically to ThingSpeak, where the data will be stored and displayed. The module used is the RAK2305, which can connect to a WiFi network and send data to the cloud.
But why is it important to do this? Well, the idea of IoT is that all things are connected to the Internet. WiFi is the main way we are connected. Just as you connect to your favorite social network to show what is happening with you and see what your friends are doing. Things need platforms to show their status and they are constantly publishing new data.
Figure 1 shows the stages of this project: First, we will configure the hardware. Then, we will program the WisBlock to receive data from the sensor and send it using the RAK2305 module to the cloud. Finally, we will visualize the data in the ThingSpeak platform. Now that we have your attention, let's get started!
What do you need?- 1 WisBlock Core RAK4631
- 1 WisBlock Base RAK5005-O
- 1 WisBlock ESP32 RAK2305
- 1 WisBlock Environmental Sensor RAK1906
These items are also available in:
Optional
Step by Step- Hardware Assembling
- ThingSpeak Configuration
- Code
- What’s Next
If you already use WisBlock, you are familiar to all the benefits it has. WisBlock is the easiest and fastest way to create IoT projects from prototyping to mass production, thanks to easy-to-connect modular blocks without the need for wires. But if you want to learn more about it, you can refer to the introductory tutorial.
Make sure you have all the necessary materials as shown in the following figure:
The RAK005-O has three types of slots. The slots indicated with letters are for the sensors. You can plug the RAK1906 sensor into any of the slots: A, B, C and D. The ESP32 WisBlock module can be plugged into the IO slot.
Mounting is simple, just push the module into the slot carefully and fasten it with the screws, as you can see in Figures 4 and 5. For more information about it, you can refer to the official documentation site.
Finally, you will have a final result like the one shown in Figure 6.
Before start programming, you should know that the default RAK2305 firmware does not support AT commands for HTTP or MQTT connections. So, the first step is to download the firmware version and install it. Let's do it!
For this, it is necessary to make some connections in the RAK2305, using a RAKDAP or any other USB to UART-TTL converter.
- Connect pin 3V3 to pin 3V3 of the RAKDAP
- Connect the GND pin of your RAKDAP to the GND pin of the RAK2305
- Connect the TX pin of the RAK2305 to the RX pin of the RAKDAP
- Connect the RX pin of the RAK2305 to the TX pin of the RAKDAP
- Finally, connect the IO0 pin to the GND pin of the RAK2305.
To connect these pins, you can either solder them using wires or use test clips, as shown in Figure 8.
After connecting the RAKDAP or converter to your computer, download the next files:
Proceed to unzip and open the Flash Download Tools program. You will see a window like the one shown in Figure 9. Select ESP32 in the chipType option and develop in the workMode option:
The program will open another window, on this, access the SPIDownload tab and follow the next steps:
1. Click on the three dots icon and select the file of the MQTT/HTTP firmware that you downloaded previously.
2. Change the value to 0x0.
3. Select the port where the device is connected.
4. Select the baud rate to 921600 bauds.
Leave all the fields as it is shown in Figure 11. And then press START.
A progress bar will show the download process to the RAK2305 and, finally, an alert will appear to indicate that the download is complete, as seen in Figure 12.
Now your RAK2305 is ready to receive and accept all AT commands for HTTP and MQTT protocols. Connect the RAK2305 to the baseboard as it’s shown in Figure 6.
ThingSpeak ConfigurationThingSpeak is a platform for receiving and managing data from IoT devices. This platform is usually the official platform supported by the popular mathematical analysis software, MATLAB. To learn more about it and register for free you can access its official site.
You can create a new account with a corporative or personal email, and send up to 3 million packages in four different channels, in the free version. After you have created an account, follow the next steps to create a new channel:
Go to the Channels tab and select My Channels
Click the New Channel button and a form will open. Fill in the information according to the help section on the right of the page or following Figure 13.
When you have filled in the information you consider necessary, click Save Channel at the bottom of the page:
A new dashboard will open showing your variables in charts ready to receive data from your end devices.
The code was programmed in the Arduino IDE and is available in our official GitHub repository. A brief summary: Variables are collected using the RAK1906 environmental sensor. This sensor connects to the RAK4631 using the I2C protocol. The RAK4631 sends AT commands to the RAK2305. The RAK2305 sends data to ThingSpeak using the HTTP protocol.
Download or clone the code and open it using Arduino IDE. To install the libraries of the RAK1906 click on the link in the code.
Install the library. If you haven’t used this library before, the program will install other packages too.
And that’s it. You can verify and upload your code.
A short explanation
#define WIFI_SSID "Your_Network_Name"
#define WIFI_PASSWORD "Your_password"
These two lines are used to store your WiFi name and password. Enclose the name and password of your access point in quotes.
#define SERVER "https://api.thingspeak.com/update?"
#define API_KEY "YOUR_API_KEY"
Next, you need to add the server and API key. For that, you need to go to your ThingSpeak dashboard, click on API Keys and copy your unique key from the Write API Key field. Then replace it in your code.
The function bme680_init()
is used to initialize all the parameters for the RAK1906 sensor. The function read_sensor()
is used to read all the values and print them in the serial monitor to view the results. the execute_at()
function is used to execute all the AT commands safely and easily.
Finally, in the Setup()
function, all the parameters of hardware are initialized and we connected the RAK2305 to the internet. And in the loop()
function the sensor data is read and sent to the cloud of the ThingSpeak.
When you open the Serial Monitor, you can see how the Internet connection process was successful, and then you will see how the data is read and sent. As shown in Figure 21:
Finally, on the ThingSpeak platform, you can see your characters, as shown in Figure 22.
You did it! Your first IoT app using WiFi and the ThingSpeak platform!!! We recommend that if you are monitoring data for long periods of time, you change the delay time in the loop()
function, that is useful to take advantage of your free account.
In the next tutorials, we will continue working on sending data to the cloud using LTE, creating alarms to your phone with SMS and, finally, sending data to the cloud using LoRaWAN®. Follow us on our official Hackster profile to learn more about creating your own IoT projects.
Comments