Go Down

Topic: Modbus TCP master library (Read 4026 times) previous topic - next topic

LamySae

Nov 12, 2017, 09:43 am Last Edit: Jan 20, 2018, 01:20 pm by LamySae
Hello everyone,

Actually I'm working on a project based on arduino Uno and ESP8266 UART shield to connect it to a controller dynamic power as a Modbus TCP master to read some registers .

I've already tried a http requests to read data from the webpage of the controller using Ethernet shield but unfortunately the connection failed many times and if it's established, the response is too slow. Hence, I drooped this method.

Then I decided to use Modbus TCP/IP protocol but I got some troubles with the libraries and it seems that this method is not reliable as I want to get data in real time.

As I've decided to use a wireless connection , I change the ethernet shield to an ESP8266 one .
I prefer to not use a Modbus RS485 protocol, but it seems that it's the most reliable . In this case, I should add another serial device with the controller to send data to the socket, but I really don't want to  add more hardware.

Could you please give me your opinions to choose the best method ?
Thank you in advance.




pylon

This post includes several very different things.

Quote
I've already tried a http requests to read data from the webpage of the CDP using Ethernet shield but unfortunately the connection failed many times and if it's established, the response is too slow. Hence, I drooped this method.
What does that mean? Don't you think it may be a programming problem? So with a corrected sketch it may be a perfect method?
Don't you think it's time to post a link to that CDP and it's manual in English?

Quote
Then I decided to use Modbus TCP/IP protocol but I got some troubles with the libraries and it seems that this method is not reliable as I want to get data in real time.
Define what "real time" means for you. For most people it simply means that the time to get the information is predictable. It sounds that you think the response must be immediate but in the computer field there is no immediate answer. So specify what time range you think is acceptable in your case. Given your description I would assume it's several seconds.
And who told you that the ModBus TCP protocol is not reliable? It was me who told you that some libraries for ModBus TCP on Arduino are not very reliable but that doesn't mean that the protocol has this deficit.

Quote
My socket should be installed far from the CDP , hence I prefer to not use a Modbus RS485 protocol, but it seems that it's the most reliable .
Where is that information from? ModBus RTU and ModBus TCP show about the same reliability in practical use. Based on my experience I would even say that you can reach higher reliability using ModBus TCP because it doesn't have a strict timing dependency.

Quote
Could you please give me your opinions to choose the best method ?
Tell us the complete specification of your project and stop starting thread by thread which simply splits up the context.
What CDP are you using (links), what distance do you have to between the components, what equipment is already in place (networks, cables, etc.)?

pylon

The English manual is available here.

Some errors I found in your sketch (HTTP):

Code: [Select]
IPAddress  server (10,3,1,15);
IPAddress ip (10,0,1,60);


The default network mask if not specified in the Ethernet library is 255.255.255.0. So this setup will only work if you have a router in your network that is listening on the IP 10.0.1.1 and is able to route traffic to the specified server. The Arduino Ethernet library doesn't know anything about class-based routing (which is not used for the last 15 years at least).

Code: [Select]
  if (client.connect(server, 80)) {
   
    client.println("connected");
    client.println("GET /10.0.1.50 HTTP/1.1");
    client.println("Connection: close");
    client.println();

  } 


The GET line must be the first line sent to the server. In your code you send a "connected" to the server which will disturb it for sure.
Also I doubt that your browser will show you anything if you point it to the URL

http://10.3.1.15/10.0.1.50

That looks like a mix of different IP addresses. On which URL do you expect to get anything from the CDR?


The code that is looking for the power value might work, that depends on the page that is returned. Do you have an example page (HTML) that you may post here?

Quote
I mean by real time the instantaneous response of request , the real power at that moment ( up to 30s).
I'm absolutely sure we will match that goal with the HTTP based solution if the value are available on the web pages.

noiasca

just to get a clearer picture of your planed architecture:

The CDP0 reads the inverter(s) via modbus RTU and you want to read the CDP0 by parsing the CDP0's TCP/IP (http) "website"?

And I just browsed through your sketch ... you are dealing with 3 IPs
10.3.1.15  "server"
10.0.1.60  "ip"
10.0.1.50  "in the client's GET request ... "

so what is your servers IP in reality?

DE: Wie man Fragen postet:
1. was hat man (Sketch und Hardware)
2. was SOLL es machen
3. was macht es: IST (Fehlverhalten, Fehlermeldungen, Serial.Output ...)
4. Eine Frage stellen bzw. erklären was man erwartet

pylon

Quote
The IP adress of the server is really 10.3.1.15, the CDP isn't in the same network of the server. What should I do in this case ?
Use the 5 parameter begin method for the Ethernet object:

Code: [Select]
  void begin(uint8_t *mac_address, IPAddress local_ip, IPAddress dns_server, IPAddress gateway, IPAddress subnet);


Set the dns_server parameter equally as the gateway as your router probably has a DNS forwarder service.

Quote
A piece of html code (load power)  is in the attachements.
Unfortunately that's not HTML code but a screen shot having the developer tools open. But probably the rest of the code looks similar and in that case your finder search strings won't work. Please post the complete HTML source (it looks like you're using an older version of Firefox, so use Ctrl+U and then Save As...), I will then try to find correct finder search strings.

Quote
I try the Modbus TCP protocol but it doesn't get data until I press 4 ( Fc to read input registers) , I've forced 4 in the code but the communication failed.
In that code you use 10.0.1.50 for the server IP. Do you know what IP you CDP has, in this post you told us it's a 10.3.1.15.

The library you're using has the server IP fixed in the library source code:
Code: [Select]
  byte ServerIp[] = {192,168,200,163};

So you won't get any data from your server with that library.

LamySae

#5
Nov 16, 2017, 12:36 pm Last Edit: Jan 20, 2018, 01:28 pm by LamySae
Thank you for the clarification.


Quote
byte ServerIp[] = {192,168,200,163};
I didn't find any serverIP in the code source(.cpp)  of the library. I set all the slaveIP as 10.0.1.50

pylon

Quote
For the Modbus TCP code, I use 10.0.1.50 for the slave IP which is the CDP in this case. I don't need the server IP ( 10.3.1.15) in the Modbus code.
In ModBus TCP the server is the slave. What IP does the CDP have? If your "server" is not the CDP, what is it then?

Quote
I didn't find any serverIP in the code source(.cpp)  of the library. I set all the slaveIP as 10.0.1.50
Post a link to the library you're using. I've just used Google as you didn't provide the necessary information. in that library the posted code is in line 18 of MgsModbus.cpp.

Quote
You can find it in attachments.
It's more complicated than I expected. The HTML is dynamically updated using Javascript, so you won't find the data in the HTML code the server transmits. The advantage if this is that you probably won't have to parse HTML code to find the values but you can request it in JSON format (I guess).
You have to find out reading the different Javascript files ("./cgi/list_data.cgi" is the first candidate to check I would say).

noiasca

I assume one of these JavaScripts will do the AJAX

Code: [Select]

        <script type="text/javascript" src="jquery.ui.i18n.all.js"></script>
<script type="text/javascript" src="./cgi/list_data.cgi"></script>
<script type="text/javascript" src="update.4.01.js"></script>


So check which of these scripts to the update of the id's, and I assume within these scripts you find the resource how to get the data from the CDP. Then do a call in the same way like the JavaScript within your browser. Check what you are getting back, propably a nice JSON object, then parse the JSON with the JSON library.

DE: Wie man Fragen postet:
1. was hat man (Sketch und Hardware)
2. was SOLL es machen
3. was macht es: IST (Fehlverhalten, Fehlermeldungen, Serial.Output ...)
4. Eine Frage stellen bzw. erklären was man erwartet

pylon

Quote
I was talking about the serverIP (10.3.1.15) in the http request code , I don't need it in the Modbus code. I'm using the MgsModbus library . Please see the attachments.
What the IP of the CDR? Is it possible that the HTML file was not delivered by the CDR but some other server? So what's behind 10.3.1.15? What's behind 10.0.1.50?

You modified the Mudbus library, did you? The fixed IP is not the only problem that library has... If you modified it, it might be the time to post your modified version.

Quote
I've moved on requesting data from the database which already reads data from CDP registers in Modbus TCP. I guess the delay of waiting database to read from CDP then respond to the Arduino would be meaningful.
Please explain how that database come into the run. Do you have additional equipment you didn't mention earlier? And if your "database" already have a ModBus TCP connection why should the Arduino open an additional one? Please give us more information about the complete project.


BTW: Never, never post code as screenshots! There is a button in the editor (</>) especially for posting code.

Watcher

Sorry to intervene in the thread, but as I am also trying to interrogate a Solar Inverter with TCP modbus, could someone explain the terms Server Vs Master referring to the modbus terminology?

I find confusing explanations on the net where sometimes the term Server is used and in other cases the term Master...

My Solar inverter documentation is defines the inverter as being the Modbus Server. Obviously the arduino must then be the client. Who will be the Master?

In addition, what would be the recommended library to use?

Thanks and sorry again to hijack the thread! :)


LamySae

Hi Watcher,
According to Modbus TCP Terminology, the master is the client (arduino) and the slave is the server (solar inverter) in your case.

We use the term master/slave in Modbus RTU terminology and client/server in Modbus TCP .
I used the MgsModbus Library with ethernet shield, It works very well but actually I have to work with wifi module . Unfortunately I didn't find any library for Modbus TCP master, all the libraries work with slave.

You can get the MgsModbus library from this link http://myarduinoprojects.com/modbus.html

Good luck!

Watcher

Hi Watcher,
According to Modbus TCP Terminology, the master is the client (arduino) and the slave is the server (solar inverter) in your case.

We use the term master/slave in Modbus RTU terminology and client/server in Modbus TCP .
I used the MgsModbus Library with ethernet shield, It works very well but actually I have to work with wifi module . Unfortunately I didn't find any library for Modbus TCP master, all the libraries work with slave.

You can get the MgsModbus library from this link http://myarduinoprojects.com/modbus.html

Good luck!
Thanks for the info.

The link you provided has an example (example.zip) with one arduino as master and the other as slave.
Did you check it out?

LamySae

In MgsModbus.cpp file, change serverIP to the IP adress of your solar inverter.
In MgsModbus_test_master.ino, change IP adress and mac adress to the ethernet shield ones.
In MB.req method, change register adress and all the bytes of the packets that you want to send .

Watcher

In MgsModbus.cpp file, change serverIP to the IP adress of your solar inverter.
In MgsModbus_test_master.ino, change IP adress and mac adress to the ethernet shield ones.
In MB.req method, change register adress and all the bytes of the packets that you want to send .
Do you think this will also work with wifi, ie a  esp8266 module instead of an ethernet shield?

LamySae

I'm still looking for another library for esp8266 modbus TCP master

Go Up