Read/Write data to ThingSpeak Server using Raspberry Pi

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
Hello friends welcome to embedded gate in this video I am going to show you how to read and how to write data to thingspix server first we're going to create thingspeak account for that open your web browser search for thinkspeak open this link click on profile picture I have already account with thinkspeak server so I am going to directly login with my account if you don't have account then click here this is login ID and enter password click on sign in option this is a main page of thinkspeak server now create new channel from here assign name to your Channel I am going to assign embedded gate now select field 1 which is already selected and save Channel now you can see the field one is here add widgets and add numerical display field is field one and press ok here you will see the digital display of field 1. now click on API keys here two API keys are there first is for writing purpose and second one is for reading purpose copy this link we call this as a write API key open new browser and paste this link and change field one value to any other value I am going to assign value 1 2 3 and press enter now go to the private View and you will see the same value is updated here you can change this value as many as time you want see the new value is updated here our task is read this value in Raspberry Pi I am going to open Tony IDE first I am going to create new file and save this file assign name to your file I am going to assign test to dot pi first Library I am going to import is a request using this Library we can easily read and write data to thingspix server next line I am going to write the while loop the code we we have write in while loop are going to execute continuously next line we have write method request dot get from this function we get response of URL here we're going to write this URL paste this URL in between two inverted commas now whichever the response is get from this URL I am going to store in variable X in next line I am going to write if condition if x dot status code equal to equal to 200 that's I have write this line because whenever we hit the API keys and we get a response to 200 then the data is successfully updated I am going to create one variable and whichever the response got from link I am going to convert that response in Json format and now I am going to print that response now run the code now you will see the response is printed here I am going to copy one of the response here and paste this response in new file I need only one response and so I am going to delete last three lines and next I am going to convert this line into a readable format after the rearranging data the data will look like this now you can see the data start with the curly bracket and end with the curly bracket the data which is in curly bracket we call this data as a dictionaries now I am going to show you one example I will write here python dictionaries open any link I'm go I am go with the w3school now you can see here the dictionary is going to start and end with the curly bracket and here data is assigned using the column I am going to refer this example now Suppose there is one dictionary is there and three data are there each are assigned using a colon if I run this code and print the value you can see the value is printed here I am going to do same thing in my example if you check in program to dictionaries are there first channel and second one in speeds so in code I am going to print s only in square bracket in double inverted commas I am going to write here fits now stop first and run run and you can see the data is in fields that only prints you can see the feed data is in square bracket square bracket represents the list there are two lists in a Fields option 0 and 1 we want to print only this this data that's why I am going to write here 1 in square bracket and press run key you will see that second data is only it's going to print on output in this data we need only value of field 1. now another there is a data start with the open and close curly bracket means this is the dictionary now we want to Value we want value of field one we're going to do same thing which which we have to earlier in square bracket in double in order commas right field one stop and run the code now you will see the value whichever the available on field 1 in the server now you can change value to I am going to write here 432 and you will see the same value is updated here suppose you want to read two fields to read the two Fields go to the channel setting now check this box here for field to and save changes in Channel now we have two fields field one and field two create digital box for field 2 select field 2 and create there is a field too we have not uploaded any data to fill 2 to upload data the procedure is same add and here write field 2 and equal to value enter you will see the value of field 2 here now suppose we want to read the feed 1 and field two then if I write here directly field to then we can get the value of field 2 here you will see the output the value is three to one okay now suppose we want to read data of field one and field 2 at same time then we can assign variable here like suppose I am going to assign F1 equal to I am going to copy this response and paste here and write build one here same F2 equal to paste now print F1 and same next line print F2 top the code and run you will see the value of F1 and F2 if you want you can change value of F1 and F2 here I am going to change to any other value enter open code and you will see the same value here now we have successfully read the updated data from the thinkspeak server now suppose we want to upload the data to thingswick server to upload the data I am going to use same example first I am going to comment out this program which is in while loop for commenting I am going to use three inverted commas at the start and at the end next I am going to use one variable to store the response for uploading the data we're going to use the method post and in circle bracket I am going to write a training which is available on thingspeak server copy this link and paste this link in circle bracket in between double inverted commas change value of field 1 to 42. now I am going to check the response if the response is 200 then data is successfully updated here in if condition I am printing message data updated stop the code and then you will see the message data updated of the code and open thinkspin server private View you will see the updated data on field one the value is 43. now change the value run the code open thinkspeak server and after some time you will see the updated value now stop the code for field 2 right and and after that keyword field to equal to the value and run the code open browser in thinkspeak server you will see the updated value of build 2. stop stop the code now suppose suppose you want to update the data of sensors to thinkfix server here I am going to take two variables F1 and F2 I have assigned value here then you can write value here directly you have to use the string concept right double inverted comma Plus per string dot Str in circle bracket write F1 whichever the integer values available in F1 we have converted to string then Plus do same procedure for F2 run the code data is updated successfully open browser and you will see the updated value here you can use any sensor to store value in F1 and F2 run stop open the data is updated you can download this code from video description thanks for watching
Info
Channel: Embedded Gate
Views: 485
Rating: undefined out of 5
Keywords: #embeddedgate, raspberrypi, ThingSpeak, write data to thingspeak server using raspberry pi
Id: DHE3l9Cc8ak
Channel Id: undefined
Length: 19min 27sec (1167 seconds)
Published: Fri Sep 01 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.