Connecting Node Red to InfluxDB V2.0 (64Bit)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] in this video we're going to build a small project up and we're going to use three um uh node-red nodes over here and we're going to use simulated data or generate simulated data and push that into influx DB and this video is going to be focusing on a 64-bit operating system so it's going to be influx DB version 2. and um the processes is slightly different for a 32-bit so I'll do a video about that at a later date so the nodes that we're going to use we're going to use the inject node the change node the debug node so these are three standard nodes I'll go into these in a minute and then we're going to use an influx DB node Now by default this isn't installed so to install this make sure that your Hardware where node red is installed so in this case it's on a Raspberry Pi has a connection to the internet because it's on my Wi-Fi and it has a connection then everything is is Cushy but let's go and have a look over here so let's um uh manage our palette so this is where we can update our nodes I already have this one installed so I'm just going to show you the process so these These are what I've got here in a project that shows you which ones are in in use but let's have a look at installing this one so it's influx DB and you can see here it's the one I've already got installed but for you guys and girls just click on install and then that will appear in this Library once you've done that the one we're going to be using we need we're going to be pushing data out to influxdb so these are all of the nodes that we're going to use so the first node we'll look at is the timestamp node and for for this particular exercise we don't actually want this inject node to do anything other than just tell our our flow to start doing something so you can build up quite uh a comprehensive list of actions here but as I said we don't want it to do anything other than say energize our flow I'll come on to this bit in a minute so as we get going we're going to um use this to automatically generate data on Startup and then keep injecting it say once every second now of course as I said about documentation we need to make sure that we have something that says something other than timestamp stamp so that's all I want this node to do sorry if this looks like I'm I'm jumping around I noticed a bit of a mistake on my recording but the the next node even though this is complete that we're going to look to to build this this routine up with the change node which is down here so let's have a look at how we've built this in so what the change node is doing is basically moving information and and giving us some sort of outputs what we want to achieve is to store process values in global memory but to make it interesting we want to randomize those values so let's have a look at what we've done with these um with these flows so you can add as many of these as you want so you can see down here I've added a couple you can delete them all right but what we're doing is we're going to set a global memory location that we're going to call temperature and I'm only going to push it into memory because it's a process value I don't need to store this in in file so I'll leave it set at memory so we're going to do that and then we're going to use a Java expression here and we're going to randomize this so we're going to have a starting position of 50 and then we're going to use the random command so we're going to have a random value of around 50 then we're going to set another area in global memory called density we're going to give that the same Java expression but density of water is 998 ish depending on temperature so I'll put it over 1000 and then I'll randomize that again so that you're going to get two Global memory areas and then a time stamp so we can have a global timestamp it's a bit pointless doing this by the way because you can just call the timestamp wherever you want so I can call it within my function which you'll see in a minute but I'm doing it here for completeness I've created a global memory area called timestamp and then you'll see I can actually pull the timestamped it's a it's a you know a fixed function within node-red so I've done that there's no point in putting a debug on here because there's actually no message payload coming out of this function so it's just going to push this this action all the way through after but in the background it will move to to these these areas so um if I go to my context data now you will see here I have density so every time I click on this and do a refresh I will have a new value so I can't put a debug on because the debug is looking at the message coming out of here and there physically isn't any message so that's how you you can use the change log and you can you can use this to to do all sorts of actions so I could delete move data but we are setting data in in this and that's probably the one you will use the most the next block that we need to generate or node we need to generate is probably the most important we we need to generate a payload adjacent payload that we can push into influx DB and to do that we're going to use this function node and this is the most commonly used block within node-red you do need some programming experience but what we need to understand here is we need to grab data from our Global memory location put it into a little subroutine and give that a tag reference and then push that out as a message payload so the first thing we need to do is to start grabbing the data so I've already started this and hopefully this will make sense so the first thing is to give this little bit of a subroutine or this data like a name and it's just good programming you know structure we don't need to put this on we don't need it there but it could be useful for moving data around at a later date so let's have a look at this this First Command what we need to do first is pull the data from Global memory and put it into a tag that we are going to use within our program and I've already done it here so VAR density so this is the the new tag that I'm generating I've kept it short because I'm lazy equals Global get so again the information from our Global memory area and then where the value that we want to get is density and you can see here over on the rights now you don't need a comma or invert you know a semicolon at the end for this command so we'll do the same for temperature so and we call this temp to keep it nice and short equals if I put my mouse over it it will start building this expression up but we're going to do global you can see here Global dots gets yes so um if it's not doing this you've probably got an old version of node-red and it's worth updating it um but this Expression Builder is quite nice we we are bringing in a value so we put in the the commas in it's put both of them in the inverted comma and then the value that we're pulling from Global memory is temperature so let's type that in we've got the two values We'll add the uh um timestamp and then we'll start working on our payload so I've I've mapped in the uh the time stamp here but all I've done is I've moved this to you know temporary variables that I can use to to create a payload so to create a payload in Json formats we'll use message dot payload and you can see it here so I can build the description up um equals and then you could put it all on one line but I prefer to to open it up so I can I can see this so what we have first the first bit is the text description that is going to appear in influxdb yeah so we'll call that time stamp okay so we can see their timestamp and then what is that going to equal and we use a colon and then it is the tag that we have generated up here so we've moved the data from Global memory into this tag and then we're going to use this to set up our Json expression and this is the value that's going to be pushed into influx DB so we'll use timestamp okay it's in Black now I do need a comma here and then I can put the the next command in so we want temperature that's going to be my description for influx DB again equals temp and that should go green so that is my tag and then the last one is density because this is the last expression in my my Json format I don't need a comma that sort of tells you that it's the last command so here here we have commas we don't have one here then we close this expression off so we're saying the message payload no it's the typo there um equals this and then return message is saying that this is end at the the end of our transmission so um I've got this on message so every time it gets a transmission from my generating data it will it will um uh run this code but you could do it on start on stop it depends how you want to do it but this is like a runtime routine and of course I need to give it a name so we've generated our code we're going to put a debug on here so we can see what's going on um we want the complete message okay and then we'll link this and we make the screen a bit smaller and then we'll drag this over and put debug on so I'll just clear this for now and we need to deploy that so it looks like my code is is is relatively good so I'm going to inject something in here now and then we'll see what our message payload so I can see my topic here is influx data that I set and then my message payload is timestamp temperature and density and then I can keep injecting this and I will get the the value coming through so then the next stage is to add the influx DB node so we've downloaded installed that so let's have a look here influx DB out and we will link that it's red triangle because we need to configure this now this there's a couple of parts to to this the first one is I have to set my server so you can have multiple servers I've already set one up because I'm using it in another part of my code but let's just have a look at how we set that up and where we get the the information from so here we have to say the version of influxdb so where version two this is just a a text description if we had influx DB in the cloud we could put a https and we could put the full address here but this is influxdb running on the same machine so we just put Local Host and then colon 8086 so what we need to look at now is how we generate this this token to get this token we need to open up influxdb so it's very similar to how we open up node Red House home 8086 is my port number and it will probably land with this sort of home screen let's have a look when you click on this try this Arrow here you get API tokens now the first thing I need is a is a bucket and I've already set a bucket up called hey how's home if you haven't got one then you will need to create one up but this is the database where you're going to to push all of the data once you've generated that house home you can see here you create bucket you need then to go to your API tokens I will then generate a token All Access we will call this um errors home click save and then I get this long code copy that to a clipboard so to use the the token I've copied it here hopefully I've copied it right into my notepad open up my connection we're going to the server and here I have my API token paste it click update and then when I go back into there look I can't actually see the token I want to to see that um if I go to configured nodes it's here as well so this is used on on all flows this is my server it looks like I could have multiple servers but I only have one so that's the first bit we need to do the measurement is just a text description you push the measurement name through so we'll call this flow meter so this will be for each yeah it could be for for each individual database that you're creating um it will sit within the house home bucket so we can put that here and then we need to find the organization now this next bit got me a little bit pickled for a while so finding the organization reference Within um uh influx DB so this is your screen and you'll jump around these and you think where the hell is my organization um and it's quite simple when you know how you'll see this little button down here to expand and you can see here how's home and then my organization is this underneath iot connectivity so um let's put that in so we have our organization I've given it a text description at the at the top could be anything you want I have a bucket here that says house home I've already used this before and called something flow meter so I'm going to call this flow meter one and I'm gonna click done but I'm not going to click the deploy yet because if I come back here I want to have a look at data Explorer and I just want to show you this so This Here how's home flow meter when I click on here you can see my time stamps this is the one I've already generated if this all works when I click um deploy and then inject my signal I should have one here called flow meter one so let's see what happens and see if I get this right first time so let's put the debug on by the way I'll be amazed if I've got it right first time let's deploy um we can click on this to and inject now it's connected to influx DB if I if it hadn't done that I I'd had an error message here okay so that looks like a little bit of a success so let's see if we can do a refresh and we can see down here flow meter one there's my density now what if I want to see that I can the easiest way is go up here and just put this as a table and don't forget to click on submit and I can see here flow meter one density now if I click on density and temperature and submit I should get both of those those values up up here on my screen so um if I want to to do something a little bit more like a runtime session that's really easy to do with node red so I know all of this is working let's just have a a little look um how we can tidy this up so the first thing called flow one let's call this influx DB simulation because it's not real data we could put if we wanted to just a comment here as well to put in a bit more you know information uh but that's that's automates this a little bit more so we don't have to keep clicking on on this button so if we come into the inject node you'll see this option here and we can set it to interval so if you just wanted it to inject once off the startup so you wanted to say write some alarm set points in once at startup you could do that but we want it to inject once every second so let's do that and deploy and you will see now my data is is being generated every second I'm just going to stop it stop the screen if I have a look in here you'll see my payload is is being automated so density's gone down to 400 temperature has changed so I'm happy with that so now I can go back to to influxdb let's have a look at that rather than looking at that as a table let's have a look at it as a chart submit and I can start to see my values so I'll put here last hour let's put this to um last minute and submit and there's some other nice things when when you come to um get this to to Auto refresh because don't forget this is a web page you can see here Auto refreshes every every second um aggregate feature I'll I'll come on to if you've got any missing values rather than have a gap it will just join join a line in between so you can see here my data is now being um filled in if I want to create a dashboard because this is just exploring my data so I want something a bit more permanent um let's uh delete this and create a new dashboard it will create a new dashboard um and let's add a graph and then here's my data it's almost automatically pulled it through temperature and density submit and I can see my data here let's do that so it's um last minute and I might want to do some some nice things with with the graph so I can customize this I can change my colors and I can change how how it fills in underneath so and give it some some labels as well um so I will have it uh the the window as one second fill in the the missing values submit now when I click on the tick I will see my dashboard View and we can see here with the dashboard view I've got set auto refresh well let's refresh every 10 seconds this is without human Intervention when it when it will go down and refresh the the dashboard I want to do it all the time so it's going to refresh every 10 seconds I can confirm that and this data now will will push along every 10 seconds I can see last minute last five minutes this was me practicing for the video on it no this was me injecting the data manually then we talked for a bit and now we've now we've automated it there we have um simulated data being pushed into influx DB the the dashboard is okay it's not brilliant you'll see when you know there's other tools where we've got better dashboards for historical data I personally prefer grafana to this because this Aggregates the data in ways I don't really like um so let's just recap on the nodes we've used we've used the inject node we've used the change node we've used this function node which is really important and then we've downloaded and installed the influxdb node we've set up a server on here and we've set up a a connection um so yep a little bit of a longer video but as you can appreciate we've learned a bit more about some nodes on node-red but we've actually done something can push data into a database so we talk about this big data strategy we now are starting to see that you know building up as we go through these videos so I hope you found that useful if you like what you see please share it with your colleagues click on the notification Bell because there's quite a few of these videos come in coming out but for now thanks for listening and hope to see you again soon
Info
Channel: IOT Connectivity Simplified
Views: 8,551
Rating: undefined out of 5
Keywords:
Id: hRwZCvQasvI
Channel Id: undefined
Length: 23min 6sec (1386 seconds)
Published: Mon Feb 27 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.