Node-RED with Modbus Tutorial (part 1)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello in this tutorial I will show how to create a very simple example using node-red and models tcp/ip so first I will start by adding a model server here in the flow this node will emulate if I double click on it it will emulate on this port modules application but usually the most common word is this one so I will leave this one instead and also we will need to listen to what is India outputs of the server in case if something goes wrong this will be very useful and inject now so in this case injection please simply an empty string and that we can trigger whenever we want so I'll go here and deploy this to show you how it works so basically this server is active right now and it's showing our wait all right so I think something just it's not working right now or all right so it seems like there's something wrong with the configuration I'm using so I guess is that I can't use this port it's probably blocked on my computer for some reason so I will need to go and read this flow but I can use this interface because node-red is down right now so the best way to do let's go to the terminal and here you can see there is the flow files are located in this folder so I will go directly to this holder and try do did this JSON file so if I open my finder and you choose go go to folder I can paste that here and so it seems like I have to judge and this one is flows this I think so according to this is the one okay is this one so all up in here so as you can see it's kind of difficult to find or to understand this JSON file so first what I can do is try to format document so I will see it more clearly I see a problem is here I put this a report this 5:02 which should be originally ten thousand five zero two you can also search if you know what's the problem you can simply go and search where you put this and it's jack this case is only here what I need to to I did this and I will save this document so we'll go back and try to start nowhere again okay so yeah it seems like it's working now so yeah for some reason it is why default not using 502 so yeah okay so let's use it with this default port and so yeah I will deploy again so what I was going to show is that I fight click here inject I could see a a bunch of zeros which are the values of all these addresses of modules modules I think it's for slow I don't know how many also suppose probably eight eighty thousand so yeah with this with this listener here I could simply read all all the registers that are on this server but what are we gonna do is just listen to in a specific specific address and that will be using the reader so here you can see there are two readers this one is called Modbus Gator and Modbus FlexCare I would strongly recommend to use the Flex Gator the main difference is you can see I mean I can show them that to you is that the Gator it's simpler because you can usually usually you will only need this and complete this part to get to read a specific register but it's kind of slow and sometimes it crash so a crashes so what I suggest is to use this flex scatter which in fact will require you to use of obviously an injection now create a function note with the metadata that you will in the other in the other node you will you will need to use this we will use this so we have better control to to read what we have here and also I will also add this to read what is in the output of what we're reading you can always use of course you could also use regular listener but in this case this listener that comes within this package is more suitable so you will need to one need to read this Jason which is kind of cumbersome sometimes so basically if you're clicking here and you go into the info you will see there are some samples of what kind of string you need to pass so in this case what we want is to read multiple inputs from from a specific address so I will copy this and I will go here and paste it here so actually we don't need to pass a value and we want to read in this case we only need to pass the function code which is the first part or the unit ID address quantity so I recommend you to put some cones here safer so this is what we want to read we want to use this function cards number three you can read here why we why why it's not here but you can read why we are using function code three and many modules to document and in this case way we will need to read only four values of registers so I will get down here so here is where you can read this are the function calls are only four so we need to read registers we will use three and that's what we need now so if we click deploy okay there are some problems here so yeah I think yeah we need to connect this node we are reading this server because there's not an read any address of tcp/ip so what we will do is just go ahead another Marcus client and this would be the one we created which is in this address it's a chord you don't need that or alright localhost which is more suitable for human so now that we are done on this we will deploy that and see if I if I use this time stamp I can I can see I could read four registers which right now are set on zero because there's nothing on it but at least we can read this four modules addresses using this which is in fact using this server so next let me just well I always like to put this is a string so I don't get confused or what I'm passing also it's also a good practice in this case to write in the name of the of the node which function called I'm using which address I'm reading and it's what's the length of the vector drum waiting right now so it's this is a battle for so I would put here for and that's kind of easier to read from the outer of the note that the we are reading for values from here also this one it's even better if I just simply write the border on the TC TCP port around reading so I can see from the outside what all ingredients just for breeding purposes so now I will to brighten in some registers there's also this also node called mode was right and also models flex right in this case like the same like this one I also recommend to use the Flex one which requires to use a function but it's more versatile and so yeah we'll simply go and copy this and here so now what we want is to inject some values and this address so we need to change this at a given grid here the documentation of you of this node will tell me we have an example of how can I write multiple values so in this case you will only copy - and no I don't think I need it so basically what the only thing I need to have is this value in this case unlike the other I need to pass about it because in this case I'm not reading on writing so I would pass this value and I like only to pass two values but make sure this value is an integer right now as we have it we are just passing a string so this should be a number you can simply pick one two three we test it so the same than in the old one say you Pam I'm trying to this second into this port so I can get from the outside that this is the same as this go and apply it's quite a couple seconds okay so this is now active I can rate these values and are now in just this into that to that register but I can't see that so in this case and passing one two three which is here okay and on the other it's right it's correct way but we're we're passing a quantity of two value so we need to pass vector and not ninja here so in this case there is there is a nice know that we can use which is just join these node simply create an array in this case we need to leave this include an array of two and then send them here source of it there's also another thing okay let's see what happens by the ploidies wave nitride right I still can't see that here I should see this way by sending twice guys can't see this here so I think the problem is yes the function code to read in function code to write that different so I will need to use a function called 16 to preset value so yeah so languages is here we also need to this too because I wanted right into here this is just a name for us to see what we are inside so yeah it's 16 the same address the same unit ID and then for to test it now so if I inject one and two and I still can see that so let me check this is an array oh yeah but I need to specify that the Rayleigh's length is 2 so let's write our again so 1 2 so yeah now we just send something here and if we try to read it yeah we have 1 2 3 1 2 3 we can read it actually we are writing here we can for example make an offset of the address and say ok I wanna put this book starting with the address number 1 so if I deploy this that way I still have the last value we find inject wrote this great I will see I have just made this into the next 2 so this is actually working now that probably you might be interested in seeing this breathing constantly so for that reason I will instead of inputting just want to treat I will put the random number one number okay so I will need to install first now for random so that's that can be done here on the correct if I look for London I can't see no have to search here so as you can see there are many the one that I want to use is this one so I could click here to install but if it fails the best way to do that is using console so I wish I will show you how to use the console to style notes in case this interface interface crashes so first of all you need to copy this name you need it and you will need to stop not Norway for a second so after talking no bread well you have to make sure you go to the folder where your package let's do that Here I am install the this NPM is down the minute we know so you can do that and you will see that's right so the problem right now is on have permissions to right here so this thing is saying try running with sudo it means traveling with students try the same thing but at the beginning it will ask for the password so put your passport here and yeah you'll see that working bar so we seems now that there was one error over here because this money this thing is looking for this package on this directory which is not exactly where it is we go up you can see the directory you for not read is this one so I will copy this now we go back here place this so I'll need to be in this directory and then try again to install the random node so it seems like it's working now or wait did it work even package yeah it seems like it's working out so if I do not write again I'll be able to see that package from the online interface so let's go back here and I should be able to see random yeah they are Justin Saudis so what I want to do now is with this here and I can now create a number that it could be from 0 to I think the maximum for Mongoose is 2 to the power of 16 which is this value but because make sure you remove this comma and you have good one last because just we're starting from 0 so after this is done I will also make this we don't link is 1 2 3 anymore I will make this interval to run every 1 second every second and to read this also with an interval of 1 second so if I deploy this I should be able to see yeah this value is now changing every second because it's being created randomly so yeah that's pretty much it this is the example you can stop the video now if you don't want to see how I do some embellishments but yeah I always recommend to make things it'll be pretty and add some comments you you can so you or someone else can read that issue for example I could say yeah here I'm writing back door slamming - but let's say this is at address 1 and so I mean this we are reading at 0 so we thought that this this here you can also state the pieces so well this is pretty much it and in the comments I would put link to the code if you want to download this and stay tuned because I will make another sample where we can read not not an emulated models for the real models with real values these days thank you very much
Info
Channel: Leo Varela
Views: 95,168
Rating: undefined out of 5
Keywords: modbus, tcp/ip, tutorial, node.js, node-red, example, beginner
Id: nN9SJfK0iIo
Channel Id: undefined
Length: 23min 22sec (1402 seconds)
Published: Sun Dec 17 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.