Let's now see the sketch that we will use for this chapter. It is actually very similar to the code for the previous chapter, so I will just highlight the important parts here.
As before, we define the server to which we want to connect the board. Here, we will use the dweet.io
service:
We also define an interval on which we will send data to the dweet.io
servers:
In the loop()
function, we check if it is time to send data. If so, we measure the reading from the sensor, and send this to a function that will send the data:
Let's now see the details of this function:
As you can see, the function is very similar to what we did in the previous recipe. The main difference is that we pass the measured data as an argument when calling the dweet.io
server.
You can now grab the code from the GitHub repository of this book, and upload it to the board.
Tip
Don't forget to change your Wi-Fi name and password here, otherwise it won't work.
Then, open the Serial monitor, and this is what you should see:
If you can see the 'succeeded' message, it means that the data has been correctly stored on the server.
To check that it was actually recorded, you can now go to the following URL:
https://dweet.io/get/latest/dweet/for/myarduino
You should see the answer in JSON format, meaning data was recorded from your board.