Read device by RS485 ASCII

@Colin @Steve-Mcl
Sorry for my late reply, I was a little busy :upside_down_face:
Yeah, I know that, but this was a completely "misch-masch" for me, so I started all once again, I put this program (form #27 post) to Raspberry and started locally get those data first at MQTT explorer (what succeeded) but asix (my scada) still can't.
However asix got establish connection with mqtt broker, but now the problem is in correctly typing the properly text (in the request) for recieve answer from broker.
So, my question is: data are shown as text-encoded data or data encoded in json format? When I started request the data as text-encoded there were a many errors in my scada that suggest, the data output are in json format. So I started requesting in this format.
In my opinion this will be the request:
json:device1/flow+payload
And according to manual this should work and flow value sould be present in my scada.
But this didn't work, so I started make combinations, having other words, like "object", "val", "value", "var", etc. instead "payload" but no effect.
I hope you understand everything I am talking about

Thats a good sign

The manual doesn't make a great deal of sense but reading "Data encoded in Json format" I suspect the following should work...

  • setup a TAG in your driver to access machine1/measurement1+value
  • the driver should try to read .value from a JSON payload at topic machine1/measurement1

Try sending this to your broker...

msg.topic = "machine1/measurement1",
msg.payload = {
  value : 123.45
}

... inject --> function --> MQTT

Once you have this manual test topic, we can modify your flow to send JSON instead of raw numbers.

Okay, that,s working, but instead "123.45" I've got "123.0", but doesn't matter, digits after dot aren't required

can you do the following...

  1. inject a different value
    e.g...
msg.topic = "machine1/measurement1",
msg.payload = {
  value : 999.78
}
  1. show me what topic you subscribe to in the Driver settings for that TAG
  2. show me what data type the TAG is setup as (integer? float? decimal? )

I tried other value



Now I subscribe:

machine1/measurement1+value

or

json:machine1/measurement1+value

Json is the default data format and the prefix "json:" may be omitted.

Data type is float.

So i guessed the driver was rounding the value.

I would try some other data formats. Perhaps try sending data as a string (not ideal but if it works - it works!)

e.g: what happens if you sent "value":"99.7" to the broker?

There may be other settings in the driver (i.e. double type? scaling? rounding?) - have a look around.

Lastly, I would contact asix about this issue as a float value of 999.78 should NOT be rounded to 1000.000

Sorry, my bad, I got chosen wrong conversion function, now I choose float, and it's good

Excellent - almost done :slight_smile:

Now you need to format your real data as JSON.

Give that a go - see if you can get your driver to subscribe to your RS485 data.

NOTE: I noticed in an earlier post the topic names had superscript like - I would advise only using standard ASCII characters for topics.

@json_lame

So one of the reasons i took you down this path was to let you realise how easy and flexible node-red + MQTT is.

I hope by now you realise you will be able to use node-red to get values from almost anywhere into your SCADA (and out of it too).
e.g.

  • Need a database value in SCADA? - use a Database node to get value, format the data, send it to broker.
  • Need a value from the internet or a REST API? - Use a HTTP Request node to get the value, format it, send it to the broker
  • Need to hook up a value from a USB device? - you get the idea.

Not only that, you can make a dashboard in node-red (who needs SCADA eh?)

There are so many possibilities.

Don't be surprised is that my nick consists "lame" :expressionless:
I don't know how to format the code for that data, but I expect that should be changed in function node (just before "rbe") .

Yeah, I've seen too.

Yes, it's true, but if I will be bored, I will try do this (hehehe funny).

And with all you wrote I agree

But I can continue working tomorrow, now it's too late

You've done really well for a newbie :+1:

Yeah in there.

Instead of setting payload to the value, set payload to an object with .value set to the value.

Same here.

Bye for now.

Even with that easy task I've got problems. I tried do something myself, but I don't know java script very well. I showed this our IT homies, but they only said

"nah, it can't work, try change "payload: val;" to "object.payload: val" or something, should work and if not, then leave it, better way is buy device that has normal-working protocol".

Obviously when they said this, I told them we haven't enough budget for buy new devices and change that and also they are a band of lazy lames, worse than me in this stuff.... :upside_down_face:
Could you show me what exactly is to do? I don't mean like a "there you go, this is a code" (unless there is no other way), but where I should looking for a value to change. I've exhausted your patience a lot almost, but I see this is the last step to achieve the target.

^ does this help?


So I think you could benefit from learning javascript. Nothing heavy - this is a nice light and well presented video on javascript for beginners

Also, you should watch the youtube videos on node-red - some really useful tips. Its about 30 mins max - and worth every second.

Then you can show your colegues they dont need to buy overpriced protocol convertors that only convert 1 thing to 1 thing - you can pretty much do EVERYTHING in node-red - for the price of - free (plus a raspberry pi)

I didn't think it's that simple, I've got establish communication and asix got the all data what I need. Now I tried to get data from two devices like FP210, so in change node I added another RS485Setup with other parameters, but it's not working, still I've got data from one device, should I add another "change" or add new flow and in it configure the second device?


Oh, now I see that in message from 23:49:53 just appeared some weird symbols, but this could happen, due to long RS485 line. Also mqtt explorer sees one of this two devices

To simplify addition of items to poll, we setup an object that describes where the data vomes from.

Edit that & press the inject (to re-initialise flow.RS485Setup)

image

^ After editing...

  • deploy,
  • click the "initialise" inject button.
  • check the flow values in the flow context viewer
    image

then check the debugs to see if the COMM is returning expected data.

Okay, I think it's working, I got that what I wanted, all data are shown in debug page so this is it. MQTT Explorer also sees two devices and its data. Tomorrow I will adjust that for all FP210 which we have got and we'll see how that's working.
At this moment we can admit it's good. Only thing to do was reinstall raspbian on my raspberry, export this flow to it and recognize how to run communication with moxa, wchich we use to communicate with devices by RS485 line. If you know it's even possible, you could tell something about, because I was looking for some information, but after find out it's impossible I was give up. There's one last thing, I just can run this on our server, which connect with moxa. But this is for our IT task to do :slight_smile:
By the way, I'll not show they what you helped me with this stuff, because of their laziness.
Thank you very much for your help and time, if I can repay you? I'm soooooo happy :slight_smile:

Is the moxa an Ethernet --> serial device? should be possible - you will have to change the serial port to a TCP Request node & probably add something to the COM but it is definately possible to Serial over Ethernet (I have done this with a different Serial Server for an old Allen Bradley PLC3-10)

Your'e welcome.

Just keep learning & convince your colleagues of the potential and possibilities node-red presents.

Moxa 5650-8-DT-J as I remember. Now moxa is set as real COM mode, and PC where scada is running has made virtual COM ports by "NPort Driver Software" or something like that, asix as communication channels has choose COM ports (com1, com2, com3, etc.).
But for now the easiest way is install Node-red on server, configure it and enjoy it.
Once again big thank you, thanks for the over 3-hour yt video, thanks for few days your patience and help.
All the best
Robert

Final words Robert.

As the data is polled sequentially, the more items you poll, the slower updates will come. Currently the inject "poll trigger" is set for 1 sec. If you need speed, you can probably tweak this down to about 0.3 before getting into bother. But if update time is not important, just leave it.

Also, you may wish to add timestamp to the output message so your SCADA knows the age of the data.

Lastly, you probably want to set the QoS higher than 0 and the retained flag so data is always available in mqtt.

Good luck.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.