ESP8266 | MicroPython | Telegram | Sending Sensor Data | #ElecrowMaker

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello magicians thank you so much for joining us so i think i am live on youtube let me just quickly go and check whether i am live or not yes i am live now so okay i think you are able to see my screen what i have in front of you okay so this is the esp32 this time we are working on esp32 and this is the button which i have connected to the esp82 and what we will be going to do today very interesting task we will be sending sensor data from our esp module to our telegram group so how do we do that we'll we'll do it in a couple of minutes let me first share my screen and let me show you what all i have for you okay so okay let me minimize everything and let me open my document so this is the document hope uh you are able to see this document okay so uh the interesting task will be sending sensor data or reading sensor data from our esp and then we will send that data to our telegram so how do we do that today we will be exploring it in details okay so first of all uh there is a concept called telegram bot that we have to understand about that and we will understand about telegram groups also and then we will add our telegram bot to our telegram group and once that is done it will be easier for us to communicate between esp32 and the telegram before uh moving ahead i hope that you all are aware of the telegram app this is a messaging app like whatsapp i think now most of the people are using telegram and there is a feature on telegram it's called telegram bot so telegram is very powerful and a very customizable tool so that you can use this tool you can use the apis they have exposed not many apis for the developers so this is the best app that you can use for your iot projects as well okay so without wasting any time let's first try to understand what is telegram bought and how do we create our own board maybe i think some of you may be familiar of the bot which is sometimes what happens when you go for a particular website there you see a kind of chatting uh the automatic chatting that that comes that pops in right pops up so that's automatic chatting actually you are not doing any chatting with any any human being over there it's automatic chatting that you are doing with a computer so that is nothing but it's a kind of bot an artificial intelligence program which is interacting you with you so bot is the same thing it's an artificial ai actually uh program who gives the response based on your particular commands so here is the time that we will be going to create our telegram bot for the first time and we will proceed now so this is the document which i have prepared for you only 14 major document so this document will cover everything in detail how to create our board how do we add our bot to the telegram group and then how do we use this bot to send sensor data from our esp32 to telegram and in our further next projects in future we will try to control our home appliances or the connected devices from telegram directly so we will give some commands from telegram and will try to automate our home appliances so that will be our next project so stay tuned with me if you need this document and if you need the code that we have used in this document so please ask me in my whatsapp group or my facebook group or just comment me under this video i have given my whatsapp number also in the description of this video so please go ahead there and you can ask me about the code and this document i can provide you okay so enough of the talkings let me directly move into telegram bot so telegram is all about freedom and open sources it announced the new telegram bot api in 2015 which allowed third parties to create telegram bots for esp32 that utilize the messaging applications as their main communication interface this means we can control our home appliances our home device devices smart home devices and our uh any home appliances that we can use we are using in our home so that we can easily control those so before actually controlling our home appliances let's understand what a telegram board is and how do we create our own bot okay so i think you are ready and must be excited for this new learning so what is a telegram what telegram is a cross platform cloud-based instant messaging video telephony and web service and end-to-end encrypted chat for secret chat only where is server client client server encryption is used in client chats but before but what differentiates from other such messaging platform is the ability to create bots so we have many other messaging tools also like whatsapp we have or we have some other messaging tools so this telegram is different than other messaging platform is the ability to create bots so if you want to if you have not used telegram you can install the telegram app for ios user this is the link and for android users you can use this link to download and install telegram app on your mobile phone okay so what are actually telegram bots telegram bots are ai based applications that can be configured to serve many different functions such examples would be like send relevant information about the weather useful news articles some are pre-configured to set reminders so these are the applications these are the different purpose and uses that we can you know we can implement bots and we can fulfill all these aims also there are some which we can play tunes and create to do list also so in this session we will do these activities so now we are seeing the uh the power of board right so using this board telegram boards you can actually do everything whatever you want to achieve it's now all your imagination that you can achieve from this telegram box so in this session what we going to achieve we are going to create a telegram bot creating a telegram group where we will post message like sensor data in our future projects and adding our bot to the telegram group so that we just created okay let's do that first creating a telegram bot so how do we create a telegram bot so our bot name is image slash tele dash set telly dash what so this will be our bot name so as we discussed earlier telegram allows us to create several bots with different functionalities for our project we will be creating a simple bot by the name of image tele bot using telegram first and foremost foremost let's open the telegram app and we'll follow the below steps okay so as i already mentioned that this document is a pretty straightforward and very simple document if you will go step by step and follow exactly whatever is mentioned then you will be done okay so ask me for this document ask me all the quotes that i have mentioned in this document i will provide you that all those informations my number my whatsapp number will be in the description of this video you can join my facebook group and you can subscribe for my channel also so how do we create a bot so first of all let's open the telegram app and search for bot father okay so let me open my telegram so i am using uh this uh desktop version of my uh telegram so you can use web version also whatever is okay for you or you can do this activity in your mobile also okay so first of all we need to search for bot father okay so let me go to the telegram and here let me search for bought father so bought father if you will search for godfather so you will get this but father you will just click it over here okay so these are the all things that you will be that you are seeing on my screen so you just ignore this for you it will be totally blank so let me first see if i can clean all this so that it will be easier for you to see okay clear history delete okay so here now i have cleared all this screen so this is how it will look like for you also bought father so once you have open the bot father bought father will appear and show below options so now so you will be seeing a screen like this so it will show you all the options like this new bots so if you want to create a new board you just need to write slash new bot so this is the command to create a new bot slash new bot so you will go here and you will just give a command slash new bot and it will show pop pop up here also you can use simply this and it will ask for all right a new bot how are you going to call it please choose a name for your bot so now is the time to give the name of the bottle let's follow the document so in the document i'm saying give it a name imx tally bot so let's let's give the same name since i already have this bot name so i'll be using uh a suffix dash one but you just use same name inh tally so you will go here and i will use image delhi board dash one okay so press enter okay so now our uh telegram bot has been created with this name now good now let's choose a username for your bot it must end with bot okay so now it is asking us for the username of this bot so let's follow the document now it will ask for the username that must end with bot so i am giving the username as imah daily user bot okay so here i will give you you use the same name or you can choose any username for your bot so i am going here and i am choosing username as image tele user underscore one so this is my username for the bot so enter sorry host it should end with bot as i already mentioned so let me give it again user underscore one underscore bot always remember it must end with bot okay okay so done so if you will see this screen here congratulations on your new bot so my new bot has been generated so so the bot name will be imx delhi bot one and and the user name of this bot will be this so in most of the cases you will be using your bot name wherever required or wherever it will ask for the username we will use this as the bot username okay so let's follow the screen again congratulations your telegram bot is ready okay now note down and keep safe the http http api key so when you created this bot you will observe that there is one http api keys already generated for your bot so you need to copy this and keep it safe because in all the programs future programs you will be using this http api key okay i am going to copy it and let me simply paste it here in a notepad okay don't try to use this api key because after this demo program i will remove and delete all these groups and all this telegram bots so that it will not be useful for you so use your own api keys use your own uh whatsapp groups okay so once you have got this http api key which will be used in our future projects or wherever we use this bots okay so once this is done that's it so it is as simple as that creating a bot so now you have created a bot if you are further interested in exploring your board you can try something like below so there are a couple of commands which i have mentioned here that if you want to uh explore more then you can go ahead and explore this suppose like if you want to change some description of your bot you can use set description so let me show you just one command so if you go here in your bot if you will say set this encryption command so then it will ask for for which bot you want to change the description since i have three bots here image tele user one image tele user bot and i have iot uh meeting hub board so i have three bots already created so it is asking for for which bot you want to change the description yes let me choose the user one which i just have created for this now it will ask for okay so what will be your description for this bot so you can type any description for that so i'm just typing it at imh demo okay and i will just press enter okay success description updated so now the description also i have added for the bot so this is not required at this point but if you want to you can just play around with some more commands if you want so these are the couple of commands which i have mentioned here okay so we are done with our bot we have api key uh already noted down for our bot now next step will be we have creating a telegram group and adding our bot to it so next important thing will be we have to create a telegram group and inside the telegram group we have to add our bot okay so it means the bot should be a part of that group where we are supposed to send our sensor data okay so let's first create a group so the the groups in telegrams the same as same as the groups that we have in our whatsapp so here also we can create groups telegram groups so how do we create a telegram group let's first create that so click on the three lines that you are seeing at the top left and then click new group and then there you have to provide a new group name so you can group any name like image data center i will use the same group name dash with dash one prefix but you can use the same group name and then you will click next okay so let me go to my telegram these are the three lines you will click here you will go here for creating a new group click here and then here you can click give any name i am giving imh uh let let's say what was that name image data center okay let me use the same image data center one okay dash let me use dash one so this is my group name text so once you will once you will do next then it will ask what all members you want to add to your groups just like whatsapp okay so here we will search for our bot remember our bot so because we want to add our bot to the group so you will search for your bot imhtali bot one i will search and once found you will just click on that and finally click create so it will create the group and it will add your bot to the group okay so let me go here let me search my bot image slash tele bot one so this is the bot which i have just created so i will select it and i will do a create okay so awesome our telegram group has been created with two members oh right you will see one yourself and other our board see below so here you will see two members so let me show you our group so this is our group here at the top and there are two members if you over this you can see myself and other telegram board that we have just created so okay so we have created the group also so now our aim will be sending sensor data from our esp to this group so esp will send esp32 will send the sensor data to this group using our bot pair we have already created already added this bot as a member of our of this group so far so good i think there is nothing much difficulty there should not be any issue this is pretty straightforward approach no technicalities much technicalities behind this so i think you may be understanding all the aspects so far okay great now what do we do from the manage group menu item make sure that all the group members can send message to this group okay so since we have created we have added imx daily bot one to this group so first of all make sure that this bot can send data to this group because if the settings are not enabled then this bot will not be able to send data to this group so we will go to the manage group and from the manage group we will see the permissions and from permissions we will see will make sure that all the permissions are set okay let me go here let me show you so this is so at the top let me just minimize it so that you can see it better now okay so at the top here we have these three buttons you will click here you will go to the manage group and under manage group you will be seeing permissions so you will go to permissions here you should see all are enabled and then you can just do a save okay save that's it so that's it this is the way we uh enable the group members to send data to a particular group in telegram now we are ready with our telegram bot to send receive data to this telegram group okay now the essential and the most important part at this stage when you have just created a bot enneagram group and added bought to the group try using below url in any browser and observe the result so here now we are going to see some magic so what is the magic here the magic is let me first copy this if i can copy this copy let me tell you what i am saying here in this line so once you have created let me go to the telegram so once you have created a bot a group and you have added your bot to the group so now at this stage if you will copy this url which i have mentioned in my document api dot telegram dot org bought followed by your api key slash get updates so first let me copy this and i let me use our so here in in place of your bot api key instead of this phrase you just have to paste your actual bot api key which you had copied earlier so this was my api key so i will just remove this keyword and i will simply paste it so this will become our url okay this is our api to get the latest information for our bot so now always remember and as i already said already informed that this api key is your now it will become your master key or api key for all the interactions that you want to perform uh all all the rest api calls that you want to perform for your bot so this will be your api key so okay let me just copy this entire url and i will go to any browser so let me go open its separate browser i paste it here and you will enter it so here you will see the magic happening voila so you can see that my result is okay and i i got an empty response okay so so far so good it means my bot is working and it is responsible why a result is blank here because there have no messages so far there is no updates for our newly created ports so as we move forward we will see results coming out in this value okay finally we have created a bot and we are able to communicate with our bot uh using the rest api okay now i will try sending some data to our bot and see what happens okay search for let's see now what we'll do we'll try to send some data or send some messages let's try to send some message to our bot and then let's see what happens search for our bot so this is our bot so go to the telegram and then start uh click on start and then simply post start to image teleport okay so what i'm going to do i am trying to open telegram and i'm going to send some message to our bot so what what was image [Music] jelly got one so this is our bot so you will click it and you will simply do a start over here and now you can sense any data suppose i am sending let me follow the document so that it will be i will be exactly in sync with the document okay so since as soon as you will click start you will see that i have sent a start message as you see here here this start message i have sent okay so now visit the url again and observe the results okay let me let's go to that url and just refresh this and see what happens i'll refresh it voila so you can see some data let me minimize it so that you can see it properly okay so here now you are seeing some data is coming if you will see like i have you have received some data here the data is start okay so far so good so let's follow the document one of the very important information we all need to know and perform is the chat id of the telegram group which bot is added so once we are able to communicate once we are able to use our rest api http api to connect over bot now the next important step will be to know the chat id of the telegram group so as you already aware or you should know all the groups that you are creating in that you create in what's in your telegram for each group you get a chat id or we call it we call it a chat id or a group id okay so if you want to send any data to a group so you must know the chat id for that group so that you can send because there may be n number of groups right group one group two so which group you want to send data using your bot right so for that you need to know the chat id because the chat id is unique for each and every group so once you know the chat id then you can specifically uh mention that chat id uh while sending data through the bot okay so the next task will be how do we know uh the chat id for a particular group the group which i had created i need to know the chat id for that okay okay fine so how do we do that we'll see now so let's follow this go to telegram group where your bot is added okay so we will go to the group first and from group information first we will remove the bot from the group wow we are going to remove now so just we had added the uh bot from the group so what we now what we will do first we will try to remove the bot from the group okay so go to the telegram and from your group so what was the group i had created so that was the group which i had to remember imx data center one so this was the group i had created so from here uh you will go here view group info and from here you will you can remove this you will right click here and remove from group remove simply this is quite simple and easy to remove any member from a group so now you will see information that i have removed this board from a group so i will see only one member only myself is there and the bot has been removed from the group okay so that was the step one remember we are what we are doing in this step we are trying to get the chat id of the group so what we did first first we removed the bot from the group next step b now you can see that bot has been removed from the group yeah we saw that now add back again so now i will add the bot again okay so let's do that so how do we add simple like we add we had added group info you can go here and simply you can click this icon and search for your bot image [Music] tally bot dash one so this is the bot click it and edit voila so we have you will see a message that we have added back the bot and you can see again two members myself and the teleport one okay so what did we do we first deleted the bot and then we re-added the bot to the group so why we did that you will get to know just in a second now what you do you just get the url and refresh it so i will go to that go back here same url and i will refresh it let's see what happens wow so you will see couple of more uh information that has been now populated so all this information is coming because we have done some uh processing or we have taken some steps for that board that's why you are seeing so many messages coming out that but from all these messages from all these messages how will we know the group id or the chat id of the particular group so how do we do that let's follow the document so now how will you observe you will observe just observe the chat id of the title group name so like this if your group name was imx data center one so for that group you just get the id okay so what we'll do here so here from all this data you will simply if you will do a find off there so i am edge so here i got it data center so so you check this line it will observe this line so in this line this is the group group name that i had and this is the id of the group so you will just copy this id this e this will be our group id or the chat id for the particular group okay so you will simply copy this and keep it safe with you okay so now remember so far we have copied our api key and we have copied the group chat id which to which we had already added our bot so must you must have done all these steps so far whatever i have done in order to proceed if you have not done all these steps do not proceed okay awesome we have got the chat id of the telegram group now to which the bot is added in my case it is something like this you can have some different id remember this id starts with a dash sign so you need to uh make sure that dash is also there dash five triple to whatever number is there after that okay so this complete uh string will be your chat id of the particular group okay so i think you should be clear by now that how do we create a bot how do we create a telegram group how do we add bot to our group how do we get the api key of our bot and how do we get the chat id of a particular group so far if you understand all this information then it will become very easy for you to move ahead to the project and you will soon you can send sensor data from esp to your telegram group okay okay so now let's try to do some magic so there is one more url i am giving you so this is the url copy this url and just paste it here again same thing what you do with this string your bot api key you just paste your api key here you will paste it here okay and for the chat id you will give the chat id of your group okay i will go here and paste it here and i am giving some message here text is hi just copy this whole url and paste in the browser let's see what happens see the magic happen i will go here and i will paste it here and enter voila as soon as you will paste it here go to your telegram and see the magic this is your group and you are seeing the message coming from your bot the message hi wow so means my bot the bot that i had created is able to send data to our group so this hi is just sent by our bot but we use the httpi api http api rest api i used to send the data but now our aim is to send data from our esp32 once you are able to send data from your rest api then it will become easier for us to send data from esp32 voila great so you are all are doing good and hope you have finished this step now our main uh main thing main job comes from here where we will be using esp32 micro python and telegram so all these three things we will link together and we will complete this project our aim is on button press as soon as we put on this breath press this button esp32 should send sends the data to our telegram group so couple of assumptions that we are going to make here first is you have gone through the earlier session on creating telegram board and telegram group which i just explained you how to create a board and how to create a group this already we have done yes okay we are good you have added your bot to the telegram group yes we have done this also you have your bot token key for http api as noted okay yes we already have this is our http api key and you have the chat id of the telegram group as noted from the earlier session so yes we have our group id also this is our group id so if you have all these four things with you then you are good good to go to execute this project now what we'll do we will make a simple connection please use the below connection scheme to connect the push button over esp32 this is again the very simple connection diagram there is not nothing much difficult for connecting our button so how do we do that the first leg of button connect to 3.3 volt of esp32 let me show you my freezing document freezing diagram how it looks like so that it will be easier for you to make the connection the first leg of button will go 3.3 volt of esp32 so this is our button and this is the first leg so first leg will connect to the 3.3 volt this red line and this red line is connecting to 3.3 volt okay second leg of the button will be connected to gpio16 of esp32 this is our second leg this second leg is connected to the yellow wire and this yellow wire is going to gpio16 of esp32 okay second leg of button will connect to first leg of 10km register again this if you will see second leg of button the same second leg of the button the same length is connected to the first leg of our 10k ohm register and the second leg of register will be connected to ground of esp and the second leg of the register will be connected to this black wire and this black wire is connected to the ground okay so the important thing is that this one this yellow wire which is connected to gpio 16. so this is our gpio16 means if you will count from here one two three four five six so if you come down towards six come towards your left and you will count like this one two three four five six so this six this six pin uh from uh from here from this 3.3 volt this pin will be your gpio16 just connect this to your second leg of your button so that's a simple diagram simple simple connection scheme and this is my connection looks like this is my connection i'm not going to detail because this is quite simple and any small newbie or anyone can easily easily do this connection now let's follow the below steps to execute this project well and now we are ready to execute this project remember in this project we'll be having couple of uh python course involved so if you need those python programs you just ask me in the comment window of this video or you just join my facebook group do whatsapp me i will provide you complete code and this document and if you have any issue any problem uh for this you can ask me so now what we'll do first let's connect esp32 to a laptop okay i have already connected my esp and confirm your com port let me show you how do we get our com port yes we go here and we do the device manager we go to the device manager and inside this device manager for this port you should see your com port yes mine is com3 you are seeing here so i have got my com port ready then open the command prompt okay and cd to your working directory okay so let me show you first what where is my working directory so here inside this i have esp essentials inside this project inside this i have sent sensor data to telegram so this is our uh this is my working directory so what you will do you will open a command form as mentioned this is my command prompt and first of all you need to do the cd to your working location so i am going to my working location done next next you have to copy our below files inside your work directory so you need to copy these two files send sensor data to telegram group dot pi and you telegram dot file okay so from where you will get these two files yes as i already informed you you will get these two files from me if you will ask for me and i will provide you just ask me or drop me a message in my whatsapp or ask me in the comments window or join my facebook group there i can provide you these two python files along with this document if you need so just you just need to copy these two and paste it under your working directory so let me show you my working directory this is my working directory so send sensor data to telegram group this is the one the one five first file second file is now you telegram dot py these two files we have to copy just ignore this test dot py not required just copy these two files under your working directory okay now then below command to transfer you telegram dot pi file to your esp32 so this will be our command to transfer you telegram dot py file inside our esp32 this is the library file for telegram uh which will be used in our main program okay so i will copy this command and i will go here in command prompt and i will simply paste this so that this telegram file this telegram library it will directly transfer inside my esp32 make sure you use your own combo com port from there so it might take couple of more minutes more seconds not minutes and okay so we have transferred our telegram library to our esp32 so let's follow the document now open send sensor data telegram group dot pi code in any editor so now we have to edit remember we had copied our api api key and the group chat id right so we need to provide these two information in our main telegram file main code so we will open this another python code and we will edit below values so all these values we have to edit okay first let me go ahead and let me open this you can open it in any editor i have to open it in tony so inside this there is section here from line 22 to 25 so here you have to provide your wi-fi information your ssid and password and telegram chat id so this will be the place where you have to provide your own group chat id which you have just copied so let me paste my group id so this is the group id i will copy remember it should start with dash i have copied it and your api key you will just copy this api key and paste it here okay so i have pasted my uh api key for bob bought token and telegram chat id this my group id and you will simply save it i will do control s that's it and you can close it so that's it these are the only changes that you have to do in this program now we are ready to execute this project voila so let's finger cross and let's do that run this command so i will copy this command and execute in our esp32 board so now this is going to run our main program in our esp32 okay okay now it is connecting trying to connect wi-fi wi-fi is connected now it is trying to connect to our board our bot is also connected voila so great so we have our bot connected uh this esp32 has been connected to our bot successfully and now it is waiting for us to press any button so button press it will send data to telegram group and when we will release when we long press the data it will exit our program great so now first let me press the button so i will press a button voila so it has it was trying to post below sensor data to telegram group sensor 1 is 21 sensor 2 is 241 sensor 3 is 236 4 is 91 sensor 5 is 181 sensor 6 is 71 message successfully posted it has posted this sensor data to our telegram group successfully so will you believe that unless you will see in your telegram group okay so let me show you the group whether it has received so this is our group so if you will see here the message has been arrived from our esp32 to our group image data center one so we have received this sensor information sorry we have received this sensor information from our esp32 okay so let me put it side by side from this and from this so that you can see both the screens together okay so now here i will press the button again and you will just observe our telegram uh group okay so i am going to press one two three so i am sending i just pressed it and you see here in the telegram group we have received sensor 1 is 140 and if you will see this sensor 1 is 140 sensor 2 is 128 sensor 3 is 67 sensor 4 is 26 sensor 5 is 146 sensor 6 is 195 so all this data we have received in our group also voila it's working perfectly let me do it one more time i will click it i will press the button it is trying to send the data it has sent the data sensor 1 is 160 sensor 2 is 55 sensor 3 is 228 sensor 4 is 0 sensor 5 is 50 sensor 6 is 217 voila great so here actually i'm just using some random data that are representing six sensors but you can connect the actual sensors and then collect those sensor data and send to your telegram group so let me long press it and let's see what happens so when i will long press it you can see i can exit from my uh esp program so that's it that that's all that i had for you now you are able to send your data from your esp32 to your telegram group so this is as simple as that and the program also it was very simple to understand and there was no not many changes need to be done in the program so you can easily do that so just go ahead and ask ask for this document and ask for the course also whatever you need from me uh ping me on my whatsapp or ask me in the comments of this video and if you like it please subscribe for the channel join my facebook group also for such uh projects and the explanation of this project and in the next project we are going to control our home appliances from telegram group so this time what we did we transferred the data from esp to telegram and in our next projects we will we will send command from telegram and we will handle those commands in our esp so this way we can control our home appliances or all the home uh home um appliances that are connected to our esp we can control those from our uh telegram group so that's that is it what we are going to uh yeah create in future also so that's it that's it what i had for you hope you enjoyed it and you will also implement all these things and let me know how it works for you whether you are able to do that or not and if you need any information any help if you are facing any issues whether whether you are a newbie you are a student professionals teachers mentors experts or whatever level or iot enthusiasts so just ask me for your doubts for your questions always welcome so goodbye take care of you take care of yourself and do good and i'm grateful for your you join my session and enjoy it let me stop share the screen and let me close this meeting bye bye arigato and
Info
Channel: IMH Videos
Views: 148
Rating: undefined out of 5
Keywords: IOT, Raspberry Pi, IOT Course, Online IOT projects, Online IOT session, Amazon AWS IOT, MQTT IOT, Wireless IOT, XBEE, Home Automation, Learn IOT Online, firebase, Realtime database, ESP, ESP8266, ESP32, Micropython, IoT Core, Webserver, ESP Webserver
Id: WH6H0gjqkk0
Channel Id: undefined
Length: 46min 32sec (2792 seconds)
Published: Sat Jul 10 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.