NodeMCU and Firebase | ESP8266 | send, receive data | Beginner friendly

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys welcome to hmd cyberspace and i'm your hmd today we are going to see how to connect nodemcu which is the 8206 module with firebase database this video is going to be a beginner friendly video which means i'm going to explain these stuffs down to its bit and if some of you people find this much explanation aren't useful i mean if you don't need that much information uh coming up you can check out the timestamps and skip to the parts of the video that you're actually that you actually want so let's get into the video okay guys the next thing that we are going to do is uh downloading the arduino ide for coding and to be able to push your code to the board you can also go with uh visual studio code for the purpose of programming but uh i recommend you to go with the arduino ide because it seems to be uh more specific and um it just does the job so for downloading already know ide hit uh hit your browser up and then search for a doing or do you know why download and hit the first link that shows up you can see the list of options available here for you to download i recommend you to go with a windows zip file now once you hit this uh zip file download uh your file will be downloaded and you can see that downloads in your download section and in my case i've already downloaded and downloaded that particular file and this is the file that you could find and so when you extract it this will be the folder and open the folder and here you could find the arduino ide of exe application file head that up and it's done we are having already know ide on our [Music] disk so guys now that we have installed arduino ide uh now we should make the id recognize our nodemcu both initially after fresh installation if you go to tools and have a look at the boards section you will find only the boats that are related to all you know i mean only this section will be directly available when you hover over this not this intermediary section in between because i'm having this section because i'm having an extra list of both okay so in order to get this esp8266 boards you have to go to files and then preferences and here you can see additional boards manager url in that field you have to paste this link to plus c then just paste this this will give you the list of books because i have already did that in order to show you from scratch i tried removing it but uh it doesn't remove this thing from my arduino ide and that's why it still shows up even if i didn't have that url in my preferences uh okay now doing this is not enough you should go to both board manager and then search for esp8266 and you will find something from uh esp8266 community install that i have already installed that this gives the support for that body board now after installing this close so great now you can make your id recognize your board which means your ide can fetch you the list of both for you to choose from and now you have to go to tools and of course and then select generic esp8266 module now when you go again to the tools you will see this boards also other related features that are uh associated with this book i mean any particular board that you selected the that particular sports feature will be listed or updated here so you can choose or control those things from here so far so good now uh is that enough not at all only your id can recognize your boat now you must make your computer to recognize your boat too which me only after your computer knows your board it will introduce you to the i mean introduce your boat to the sofas which means you need a driver so we are going to uh install a driver for node ncua to double module uh for that go to this this link let me copy paste i'll give you this link in the description just by entering the link the download will automatically start it's just a small file it instantly downloaded after downloading you can find that thing uh in your downloads extract this and you can find this one and once you execute this you give this you will find this dialog box popping up and click install i have already installed this so i'm not going to install once after installing they'll just give you a popup message and it will go so just close this after the successful installation and now if you connect your board your computer also will recognize mind that guys for any particular boat that you use you should be needing an appropriate driver for that board in order to make your computer recognize that board uh it's not going to work unless to unless you have that uh particular driver installed in your computer so let me connect my nodemcu module now yeah let's uh check with the device manager both yeah it is recognizing as uh ch340 which me which is also three four one ser but actually you can find that a particular driver name at the back side of your node j i mean not mcu module so guys the next thing that we are going to do is uh we are going to download fibres library for that we are going to open a new tab we will google such as firebase and then click the first github link i mean the firebase extent that slash firebase arduino and uh click and download the zip you could say that uh uh i've already did this this was the previous try for this video so once this is downloaded you can go to uh you can go to the ide and max message and go to sketch and go to include library here add dot zip library and go to the location where that file is installed uh minus and libraries folder so click this and you are done here it will show error message because i have already included library so now because i've already yeah so it's done now we have the functionality enough functionality and the libraries to or to be able to connect with the firebase database so with the help of the functions available from that arduino firebase library we can connect to firebase i'll show you in a while now okay guys i'm getting this error because i have already included the library for the sake of the tutorial i have again included and that's why i'm getting this error for you guys i guess it won't show up uh if you're including it for the first time it will show up so no need to worry about that the next thing is let's go to the github page that we from where we downloaded that from and scroll down to the dependency section and here you could find that firebase arduino now depends on arduino json library instead of containing its own version of it but that what this means is that we need um a library called you know json library in order for the arduino firebase library to work so let's go to ide and go to tools and manage libraries let us pop up actually this will uh take quite a bit of time to update the list of libraries that we have already installed to check for updates so i'll skip this okay now this is loaded now here search for adobe no json and i'll let that load up and you can see something from benoit blatch on blanchon whatever this thing and none of the latest version anything would be compatible because uh when if we go to this uh we can see we recommend that audino json is at least version 5.3.1 and we are having 6.78.3 that's fine let's install this okay now that is installed and it's just again once after the demo it's again updating the list of libraries we can just close right away and the next thing that we should do is uh to include i mean to redefine the fingerprint uh wait i'll show you what i mean in a second but before that i'll show you another thing you can see the second part of the dependencies uh that is stating that esp8266 core sdk uh we recommend using officially tag releases and it should be at least 2.4.1 what does this mean guys remember we have downloaded something uh by going into the boots manager and we have downloaded something from something called esp8266 uh from esp8266 community and this is the exact thing okay so you guys don't need to worry about the second one because we already have it so let's get into the next thing which is more even more important which is a flaw in this uh firebase adreno another floor uh this is not quite updated because uh the fingerprint that it is library holds is outdated if you go to pull request and down to a dead fingerprint by mabel i'll let this load up yeah go to this update of fingerprint and then you can see the difference right uh this fingerprint and this fingerprint is totally different and we have to upgrade to this fingerprint for uh i mean in order to get that uh firebase library working okay so now let's just copy this no just copy the entire string okay let's see now we have to file the file explorer go to documents because by default order notes library files would be available in documents arduino libraries and now go to firebase arduino master then source src and then http client yeah this one now whatever just notepad or whatever that fixed data that you want to go with totally fine with that now i mean replace this string with that we have copied okay now save it yeah we just see it and then we can close it at last we are totally done with all those things that are needed for the setup so our setup is completely done and next thing we can dive into the coding part i mean the setting i mean the real part that so at last we have completed all these setup process all these things that are required and the only thing that has left is to get our id get our code into the ghetto code into the board and also set up the firebase database and connect them and get them working so let's uh just do it okay guys to get started with programming we'll go to ide and then now we'll use a preview sketch for the sake of simplicity on concerning the scope of project that would suffice and for that i will go to file and examples so what do i mean by sketch sketch is nothing but in case if someone doesn't know what a sketch and they are fairly new to this whole thing uh sketch is nothing but the file that contains the program it's just at the end of the it's just the file that has the program uh the program that you try to send to your board so yeah arduino comes with a previous set of examples uh these are the sketches related or you know some general sketches um you should probably find that here i mean the example for custom libraries for the libraries that you have installed by your own or right from the external sites whatever you want to see that should be here i couldn't find anything related to firebase how does it go okay incompatible yeah here it is i don't know why it went under incompatible um if this issue is only with me only i would get something like this uh other than that you guys could find it right here itself you don't have to go inside incompatible and then firebase agreed arduino and then firebase demo okay let's uh fire that up and okay we got the program that uh we can proceed with good okay guys that's going to be a complete explanation of this code later in this video uh there is a timestamp given i said before uh you can jump if you want to listen to the complete uh explanation for now for the scope for the sake of simplicity um i just explained what these are and what these does and because we are going to modify only these fields uh to show you how the program works so five is host is nothing but the host name or the domain name i don't know which term could make you people understand it's just the domain which contains your mind uh if your family you're way too new then i think know that i think this is the website name to be to be like make it way too simple it is the website name our website names are called host and to be more professional it's the domain name so and then the secret will show i'll show you what this means in a while for now it's just it's like a token for you uh to connect this particular code firebase database okay guys let's have in mind that uh we haven't initialized any data database in the firebase which we will do so uh this token is nothing but a string uh which helps firebase uh to know uh if this program is accessible or not it's like uh we are giving the firebase uh like uh hey firebase uh if someone comes with this token allow them to access the database that's uh it's it's just that simple for the sake of security yeah uh so the next thing is ssid a society is nothing but the name of the access point and again if you are way to know to understand what has an access point it does uh the name of the wi-fi or your who i mean your home wi-fi or the hotspot whatever you want to call it anything uh that lets other devices connect to it in order to have internet connection that is called access point and you can see this i have connect i've connected my lab to my hotspot and it is called formulable and that is exactly going to make its case sensitive and just be careful for me and in case of uh any empty passwords i mean you your wi-fi doesn't have any pros password wi-fi or i mean wi-fi or hotspot doesn't have any password just leave it empty string but it should be your stream don't just completely take it out or in case if you have any password just pull it out case sensitive again and now let's save the sketch okay some files are not read only so we are accessing this that file directly from the firebase library okay so what should we do i mean the these examples are stored in the firebase package right so we can access this directory i mean modify we can access this but we can modify this so let's save it in another location okay let's go ahead and save it 5a is demo esp8266 oh okay [Music] okay i have already uh tried this before so that's why customized let's go to the okay let's save this and the next thing that we should do is to create a firebase database and connect this uh program to that database so let's just do it [Music] okay guys so the next thing is uh we'll create a firebase database so for that we'll go to google chrome any browser new tab and like um firebase.google.com uh this will land you in this page and if you are someone who is failing you to i mean totally new to firebase then you must create an account and that uh explaining that would be weight or the scope so uh it is easy guys so just go ahead and create an account and so that you will be given a console uh so let's go to the console straight away and yeah uh let's create a new project let's call that node fire note file try not right right let's continue with those numbers so yeah let's just keep it simple no fire continue uh we actually don't need uh google analytics so even if you want to have this there's no problems just go with continue it's about an account it's a default for firebase in the create project so i will take some time to create the project i'll skip that okay guys now that our project is ready let's continue this will take us to the note fire you can have a look at the available project and we are in the note fire app these are all the stuffs related to note fire uh the console that this dashboard is i mean this dashboard is uh all loaded up with uh the functions that are related to this particular app okay this then now we have to create a database we'll choose real-time database we i recommend you to go with real-time database for some reasons and uh let's create a database we'll go with the united states yeah united states next lock the mode test point okay guys uh log tomorrow is nothing but uh uh you'll it's like you can only manipulate your database uh through this console we'll just go with the test mode even in locked mode you can let's let me show you you can change this rules to true you can just change these rules to true and anybody can have that read write access i mean anybody with that token can have the read write access we'll go with the test mode which by default so just do now okay now guys we'll go with the log mode enable we'll change the rules now i'll show you know why let that create yeah now that our database is set up let's go to rules now change this to true yeah true and also true uh and click publish only then it will get updated please don't want to use a security rule as public so anyone okay we can ignore that for now no worries just a sample projects then we'll go to data actually we don't need to populate it with anything because our program will take care of that i'll explain that in the explanation section uh now we should go to settings project settings and service account this page will have database secrets yeah database secrets so now we have a secret it show uh copy this yeah let's hide it again now go to our program paste that secret here okay i hope that this thing makes sense now because this is called a secret in firebase database only the programs with this particular secret can access that firebase and now we what's left we should fill this firebase host thing okay let's go to yeah general where is my database yeah now go to real time database you can see this thing right this is where our database is hosted okay now leave the protocol i want you to leave the protocol just copy protocol is nothing but the http or https that you could clearly see in front of any uh website name copy until the dot com ctrl c and go to our program and paste here yeah done um now just save the program okay now i'll connect my nodemcu module with my computer hold on i hope you hear that yeah now it's connected now go to what yeah it's already detected in case if it isn't detected go to tools and then both and select generic esp8266 module okay now these all things will be fired up and next thing is you should choose the port okay for a reason i know that com3 is not where my nodemcu is connected you can try just this is just try on error you can try click this i mean select this and compile your code uh if it doesn't work it's not there since i know this modulus connected to com4 i'll choose this then okay next uh let's see let's try compiling then we will push to the board okay the compile might take some time so i'll skip it oops we are given with uh yes so guys like you as you could see here it's something related to the ordinary json package so this is something for sure related to the audio json that we have downloaded so let's have a look at uh the github file okay let's go to code and scroll down again to the dependencies and have a look at the recommended questionnaire okay let's try this exact version itself okay let's go to tools and manage libraries until that fires up we'll have a look at the yeah here it is 5.13.1 let's have in mind five point thirteen point one let's get this updating part yeah this has come okay now let's search how do we know json again yeah it's correct yeah we have installed version 6. 1370.3 so let's go to 5.13.1 now because that is the recommended thing they have given there because that worked and they also they also mention that um we recommend that at least version 5.13.1 this means that anything uh higher would be compatible but that might be just hope so let's now try to what the heck is this man my thirty point one stone uh yeah yeah done okay guys now we'll try to compile this thing okay let's hit let's call verified here so it's compiling meanwhile i'll fire up or the serial monitor serial monitor is the place where you could see uh the output um to you to make it so simple the output of the program that you have so it's still compiling i'll skip this it seems that it's compiled uh so let's upload it to our board yeah let's compile now you see this thing here means uh it's compiled okay it's uh it's just showing the stats okay now let's go to let's check here it's selected everything is perfect now let's upload yeah hit upload uh this upload will also take some time and while uploading it will again recompile the thing even if you have already compiled that so have that in common let's get this so now if you if you have a look at the serial monitor now it's still compiling yeah 41 percent 70 okay it's done okay you see it's connecting yeah it's connected okay and it's just showing the ip address okay so nothing to worry about you see we're printing it now let's check the firebase relatively yeah hooray we got the results you see the number is popping up here okay guys that's how we connect our nodemcu with firebase database hope you have enjoyed this video if you have in need doubt feel free to comment it out i am here to sort it out okay yeah yeah we're all right so guys if you have uh uh no further curiosity you can just cut the video here and uh rest of the people who wants explanation for this particular yeah for this particular code can still wait because i'm gonna explain this language okay let's jump into the code now uh these are all the comments uh uh comments like description so we can ignore it ignore it totally yeah these are called the header files and header files means uh like the dependencies you know this contains the features that we need or these contains these are just programs that license another file okay now what is these header files mean uh this header file gives us the functions to manipulate or play with the wi-fi module that comes with the node mcu so the next thing firebase already know this helps us or provides us with the uh functions to be able to esta to be able to connect to the firebase database and firebase was okay these are definition defined in the sense we are just declaring it okay just globally these are globally declared uh common to all the files okay so firebase host means the asset before its host name or the website name or where your file lies or i mean where your database is hosted or ours or the domain name okay and the next thing is firebase auth auth is just a form of token or form authorization uh in this the form is to have a token to authorize you any app with this token is allowed to manipulate the database so or you're the database so the wi-fi ssid what does this mean just just means the name of the hotspot or router or whatever um the name of the access point makes the password the password for that access point uh in my case it's ssi is forward open okay white setup what is white setup uh voice setup is a function uh an arduino which runs only one time for the entire life cycle which means if you power up your arduino or uh node x or whatever the board that you have this particular setup function will run only once and then it will pass to the next line and this loopy loop you see here will run infinitely until the board is alive i mean supplied with power so you can all write your all initialization and set up codes uh here inside the setup and those things that should be repetitively done inside the loop function so let's now jump into the setup function serial.begin what does this mean so this just means uh that it is trying to initialize the serial connection to your board um i mean like it's not going to print anything it's just uh a convention just keep in mind as a convention it's it will just uh initialize uh a serial connection okay wi-fi dot begin it initializes your wi-fi module that is present on the board and then this we are passing the ssid which is the name and the password of the wi-fi access point to this function with this with the help of this the function is initiate a connection i mean connect to the wi-fi and initiate a connection then serial.print serial.printer is nothing but printing to the serial monitor it's a function like a printf and c uh console.logdo i mean console.log in javascript something like that and while while just runs a classic while loop here it prints the dot until the wi-fi is connected it's right it just says wi-fi dot status not equal to y well connected it's just a global variable don't mind it guys this is the i guess it might have some good uh so until the wife is connected you just print some dot and then coming to the next line just just printing a new line and the next line prints connected once this loop breaks it uh prints a new line and it connects until the until it connects this dot is being printed okay that will be printed next line print line cylinder printer wi-fi dot local ip okay this prints the ib address of the module that is allocated to the module whatever and that's what we have seen in the serial monitor earlier i would have said this is that this is nothing but the ib of the module okay firebase.beginner uh yeah this is the actual point we are establishing a connection with firebase database firebase.begin initializes the connection with firebase database from your node node mcu module um firebase host firebase or being passed to make the connection possible for the purpose of authorization okay next again it is just a decline globally so that its value should not be changed uh and firebase.setfloat is used to set uh a particular value for a particular field this na this number is the field name and 43.0 is a float and it has the value for the field number okay if firebase dot failed in case if there is an error we can catch that error and we can handle that error this way this is nothing you just don't have to worry about it uh because i hope you won't have any errors in case if you have any errors you can put the error this way firebase dot error will contain the error and which not contact it will just uh print the air it will return the error and that error will be printed okay this delay delay is nothing but a time delay as just literally delay okay a thousand refers to the milliseconds thousand milliseconds and next update value uh what i said firebase.setfloat okay uh if uh if the field is already present this will just update that's why here both said float both these times only said float is used you might wonder uh if we should update we might use some other function or some other variable right but firebase is clever enough to understand if the field is already present go update to that field okay now the same way we are handling error to firebase or failed then for represent the firebase dot error message then again a delay after the delay delay of 1000 milliseconds we'll print again the number then in serial.print we will print firebase.getfloat okay in order to get the value of field we will use get float okay to remove firebase.remove this removes the field from the firebase again a delay set string if you want to set a string as a value for the message you'll use set string again handling errors then again a delay of thousand milliseconds which is one second virus that's it bull next line yeah it sets the truth key to the value false you as we have seen in the uh firebase database updating uh at the third second we could see some new value popping up and then delete a handling error and then delay and then again string is equal to five is that push and locks this is nothing but we are using a string and we are just uh pushing the value which means appending the value and uh that value is printed as this is logs and it's uh so simple actually you don't have to worry about this we are not actually going to print anything we don't need this to so next serial.print push logs and then name because we are storing these logs in the name each time this will be printed after printing lock so with the serial monitor you will be seeing uh like a like a dedicated log okay then again a delay then again it will start from here the whole process will continue again and again and then this will be going until your boat dies okay hope you have enjoyed this video hope the uh explanation makes sense and uh the explanation is what thank you guys for for watching till the end so thank you guys for watching till the end and keep supporting peace
Info
Channel: hmd cyberspace
Views: 5,080
Rating: 4.8699188 out of 5
Keywords: nodemcu, firebase, microcontroller, arduino
Id: 082JBZ-Txvo
Channel Id: undefined
Length: 35min 57sec (2157 seconds)
Published: Tue Apr 06 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.