Connect to ThingSpeak (ESP32 + Arduino series)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
once you're happier SP 32 connected to Wi-Fi you can send data to external services to keep track of them in this video I will show you how to use things speak now in a nutshell think speak allows you to send data to the cloud they'll store it and they visualize it for you in this handy dashboard here's an example of a sensor that I was working on that frequently uploads the value of some IR sensors and what's cool is that things speak automatically generates these graphs to visualize your data over time pretty cool right now on top of that things speak is free if you send less than 3 million messages per year that's about eight thousand two hundred messages per day that should be more than sufficient for DIY projects now to get started you will need to sign up for a free thing speak account and here I'm obviously already logged in to mine things speak is organized in a very simple way you can create channels that contain data fields a simple example if you're building a temperature sensor you probably want to create one channel for your device with two fields a temperature field and a humidity field now to create a channel you can go to channels my channel and then click on new channel I'll call mine test Channel and I will define two fields one for a simple counter just to demonstrate how things speak works and how it visualizes data and then I will create another one to let's say keep track of the Wi-Fi signal strength now you can fill in the other details as well but that's not required those are mostly there for when you want to share your channel to the public when you're done click on save channel now things peak automatically shows you the dashboard of your channel with a graph for each of the fields that we just defined that is counter and Wi-Fi signal so now we're ready to push data to things peak and you can do this in two ways you can make HTTP calls or you can use their MQTT broker the easiest one is by using HTTP calls but you don't need to make these yourself we can use this thing speak Arduino client so I'll switch the visual studio code and I open up the details of this library so you can see the things speak library created by MathWorks themself it's compatible with any Arduino board provided that you have a Wi-Fi extension and it's also compatible with the esp8266 and the ESP 32 now to install this library i will go to my platform i out any file i will create a new section called lib depths and I will add things speak right here the library manager is something that was mentioned in the previous videos but in a nutshell platform IO will take care of downloading and installing this library for us now let's write some code in the main dot CPP file I already added code to connect to a Wi-Fi network I also made a video about this one so if you haven't seen it go check it out but back to things speak there are two things that I want to push a simple counter just to demonstrate and the current Wi-Fi signal strength let's start by importing the things speak library so I will say include things speak dot H next I will define two constants one for the channel ID and one for the channel API key and you can find these on the things speak website so if I go back to Safari and I scroll up here at the top of your page of your details page you can find your channel ID so simply copy that and paste it in to channel ID to find your API key go back to things speak go to API keys and you'll have two API keys you have a right API key and read API key we obviously need to use the right API key so I'm going to copy this one and paste it in here now we'll also create an instance of Wi-Fi client which I will call clients this will be used by the things speak library to make HTTP requests now finally I will also create a counter and initial to zero now let's move on to the setup function here I already have some code to initialize the serial and to connect to Wi-Fi we obviously need to have a Wi-Fi connection because otherwise we cannot push data to things speak the only thing that's left to do in the setup function is to call things speak dot begin and this function expects one parameter it expects an instance of Wi-Fi client which we have defined at the top of her file and we've called it client and that's all we have to do to initialize the things speak library now we're ready to send some actual data and we'll do that in the loop function I'll start by incrementing the counter so I'll say counter plus plus then we can use the right field method of the things speak library to send some data so I will say things speak dot write fields and this one expects for parameters the ID of the channel where you want to push data to which we have defined in our constant channel ID the field number to which you want to push a value we want to push the counter to field number one so I will say number one then the value that you want to push so we want to push our counter and finally your channels API key which we have defined in channel underscore API key the last step is to add a delay of 15 seconds to our loop function because the free tier of things speak only allows one new data point every 15 seconds so I'll say delay 15 thousand let's save the file and let's flash it to our board to see if it works so once the flashing is done you can see that the board is connecting to Wi-Fi it's connected and it's connected with this particular IP address now if I go back to things speak and I go to my private view of my channel you can see the value of our counter is being incremented so it started at counter 1 then it was counter 2 and if we wait another 15 seconds you will see another data point being added to this graph there we go counter equals 3 so that's pretty cool but let's now push the Wi-Fi signal strength to things speak as well now to do that you could just copy and paste this line and write something to field number 2 but that would not be very efficient because the right field method makes an HTTP request for each field you want to submit so if you copy and paste this line you would make two calls instead you can also update all of your fields in one go so to do that I will replace right field by set field and this method only accepts two parameters the field number and the value for the field so we'll remove channel ID and I will remove the channel API key now I can also push field number two so I will copy and paste this line and I will say that field number two has to be my Wi-Fi signal strength which we can get by calling Wi-Fi dot RSSI you can repeat this for all of the fields in your channel and once you're done you have to send them through two things speak and you can do that by calling things speak dot write fields this method expects two parameters the channel ID and the API key so I will say channel ID and channel API key now this is much more efficient because again you can update all the fields of your channel in one go with one single HTTP requests so let's save the file let's flash it to our board and see if this works as well alright the flashing is done you can see again the board has connected to Wi-Fi so let's go to things speak and let's hit refresh to see what has happened and you can see there yes the counter has been reset it to value one and you can also see that it started reporting its Wi-Fi signal strength now one side note the things speak library also allows you to download your readings back to the ESP 32 this could be handy if you wanted to retrieve the previous state for example but that's for another video now as you can see things speak is an amazing tool for quickly capturing and analyzing data from your IOT projects I've been using it a lot during testing phases because it's easy to use and because it immediately visualizes your data over time check out the rest of the series if you want to learn more about ESP 32 programming and thanks for watching
Info
Channel: Simply Explained
Views: 51,194
Rating: undefined out of 5
Keywords: beginner, guide, getting started, easy, tutorial, basic tutorial, introduction, flash, free, c programming, howto, educate, espressif, understand, learn, esp32, cpp, microcontroller, cpu, best practices, dummies, training, course, sleep, lesson, fundamentals, simple, education, programming, program, project, arduino, diy, basics
Id: F1fQ8m3S8-4
Channel Id: undefined
Length: 9min 4sec (544 seconds)
Published: Fri May 22 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.