Waveshare RS485 TO ETH Manual Download Page 1

485 TO ETH (B) User Manual

1

/

36

www.waveshare.com

RS485 TO ETH (B)

MQTT and JSON Manual

Summary of Contents for RS485 TO ETH

Page 1: ...485 TO ETH B User Manual 1 36 www waveshare com RS485 TO ETH B MQTT and JSON Manual ...

Page 2: ...ed JSON design 11 3 3 Read the bits of the byte register 13 3 4 01 and 02 function codes 14 3 5 Show design results 15 3 6 Excel editing 16 3 7 Brackets and arrays 17 3 8 Cannot read and clear 21 3 9 Device offline 22 3 10 Pan and zoom 23 3 11 Data change reporting 23 3 12 JSON issuance 24 3 13 645 Timing of the agreement 25 4 JSON to Modbus RTU 26 5 MQTT 28 5 1 Device configuration 28 5 2 Data Te...

Page 3: ...rotocol get the time automatically 7 Support unsigned data and signed data support decimal point representation and support 4 byte length data 8 All configurations can be completed in interface configuration and the user s independent configuration does not need to be customized 9 In addition to choosing MQTT the protocol can support HTTP POST and GET methods 2 JSON SIMPLE EXAMPLE 2 1 MODBUS RTU T...

Page 4: ... Frequency 2 356 A phase active power 4 Unsigned 3 decimal place is reserved 358 B phase active power 4 360 C phase active power 4 362 Total active power 4 The so called signed means that the highest bit of 2 bytes or 4 bytes is the sign bit for example 0xFFFF will be recognized as 1 Keeping 2 decimal places means that after the data is converted as an integer the decimal point moves from the righ...

Page 5: ...ocket simulated server receiving data Use Vircom to configure the device Figure 2 Device configuration Click Modify configuration to connect the device to the SocketDlgTest tool Enter device editing again dialog box Click the Firmware and Configuration button ...

Page 6: ...irectory such as the MQTTHTTPD directory To prevent the previous design from remaining please click the Clear All button first so that the previous design content can be cleared The design file will be saved in this directory and can be downloaded to the device by clicking the download button later Click the JSON Configuration button Figure 4 JSON configuration main interface ...

Page 7: ...gned content 3 Delete all Delete all Modbus registers designed by the Add View button to facilitate the restart of the design 4 Save JSON settings After the design is completed only click this button to save the data to the download directory just now and then download it to the inside of the device Now click the Add View button For the first row of the previous Modbus table Register address Param...

Page 8: ... of Modbus RTU parameters b Fixed string For example in the form of DevName MyDev enter MyDev in the fixed string on the right and the JSON name is DevName so that a fixed string of JSON nodes can be generated c Device ID If the JSON node name is DevID the string of the sent node is DevID 285301020304 where 285301020304 is the MAC address or unique number of the device d Current time If the JSON n...

Page 9: ... node 2 1 b Return to the previous level If the current node is nested at the Nth level clicking this button will return to the design of the N 1 level node and stay on a new node at the N 1 level c Design the next one Click to enter the next local JSON node If there is no next node in the previous design the Already Added checkbox will be cancelled indicating that it is a new node d Save the desi...

Page 10: ...aveshare com Figure 6 Download Then click OK and the device will automatically restart If there is no restart please restart manually 2 4 CREATE A NEW MODBUS ANALOG METER Here Modbus Slave is used to simulate a meter Figure 7 Test results ...

Page 11: ...ectory where httpd txt is located create an empty txt file with the content as down NTP NTP_SERVER1 a1 a2 a3 a4 NTP_SERVER2 b1 b2 b3 b4 NTP_SERVER3 c1 c2 c3 c4 RE_ARUIRE_TIME 0 NTP_SERVER1 NTP_SERVER2 NTP_SERVER3 are the IP of the NTP time server Address fill in according to the actual situation Up to 3 servers can be set up but you must NTP_SERVER1 starts to write if there is only one write NTP_S...

Page 12: ...till need to click Design Next After entering step 1 3 click Return to the previous level This 1 3 step will be automatically abandoned 4 Go to step 2 Enter the keyword data here then select JSON Nesting as the source and then click the Design Nested JSON button 5 Go to step 2 1 here design id MyData123456 enter the keyword id select the source as a fixed string then enter MyData123456 in the fixe...

Page 13: ...te and go to the next to delete this useless node 11 Back to the JSON to Modbus RTU setting interface click Save JSON Settings Then download it to the inside of the device and use it When the TCP connection is established the data is received header DEVID 2850002F0EEC time 2019 05 13 23 41 26 data id MyData123456 alarm alarm1 123 4C alarm2 567 8C value 2345 Note that if you are editing the current...

Page 14: ... of the Boolean value is different For example we designed bit1 bit2 bit8 bit9 bit16 when the register content is 0x8183 we get the following json data return bit1 1 bit2 1 bit8 1 bit9 1 bit16 1 3 4 01 AND 02 FUNCTION CODES You can set the JSON node for the bit register of the 01 02 function code but each JSON node needs to set the register address once so the number of bits read each time is one ...

Page 15: ...nd the number of reserved decimal places cannot be selected 3 5 SHOW DESIGN RESULTS Now click Save JSON Design to design and you can see the content of the designed JSON format in the display box which is convenient for overview of the design At the same time there is an index for comparison when entering Add View Figure 11 shows the results ...

Page 16: ... order to facilitate editing you can export the content of the design to CSV format then edit with EXCELL then save it as CSV and then import it However CSV has formatting issues Figure 13 Data format error At this time you can save the CSV as XLS format for editing After editing save as CSV format and import ...

Page 17: ...and the second element is data 1 Here we treat the bracketed array similarly to nested JSON but this nested JSON does not require keyword names and colons The design steps are as follows Figure 14 Array object Since reqBody itself is an object not an array unit the node type is selected as an object Data not array data Since its content is an array according to the brackets are braces The idea is ...

Page 18: ...t Modbus registers and other parameters Then click Go to Next to design the second element of the array and the method is similar After designing the second element since there is no more design click Save all and exit Go back to the previous interface and click Save JSON Settings then download it The data posted is reqBody 2 3 Now look at a more complicated example reqBody workshop_id 1008 machin...

Page 19: ... is a JSON itself Figure 16 Step 1 Here in 1 1 the previous example 1 is to select the node type as array data and then directly design the data in Modbus format but the data content here is a JSON object so you need to select the data source as nested JSON and then click Design nested JSON Figure 17 Step 1 1 ...

Page 20: ...ne_code Figure 18 Step 1 1 1 Figure 19 Step 1 1 2 Note here that you need to click Go to the next in the empty content node that is 1 1 3 click Return to the previous level to enter 1 2 1 1 3 here is actually a non existent node 1 2 is also an array type and the data source is nested JSON please refer to step 1 1 After that until 1 2 2 click Save all and exit directly ...

Page 21: ... last uploaded data is as follows among which the workshop_id is read from the Modbus register Figure 21 Step 1 1 3 3 8 CANNOT READ AND CLEAR When a register cannot be read a data value of 0 can be used to indicate that the data has not been read Figure 22 Clear data ...

Page 22: ... 0 it is impossible to judge whether the device is offline or the data is 0 In addition sometimes the device has multiple registers that need to be read so a separate JSON keyword should be used such as online1 0 as 0 or 1 to indicate that the device is online For this you can design online1 as follows First design all the registers and then add a JSON node Figure 23 Device online The name here is...

Page 23: ...s RTU data source the data length is 2 03 or 04 function code Floating point output The number of decimal points can be selected from 0 to 4 The most important thing is to check the option to enable pan and zoom Enter an integer in the minus integer the range is 32768 to 32767 divided by the float Enter a floating point number in Points 3 11 DATA CHANGE REPORTING In some cases in order to reduce d...

Page 24: ...ther node of alarm2 with address 11 but uncheck the data change upload Normal data is uploaded once in 10 seconds If the bit of address 10 changes alarm at this time the report will be triggered immediately actually it takes several hundred milliseconds for the data to change due to the rotation and the upload will be slightly delayed But if the bit of address 11 changes the report will not be tri...

Page 25: ...ports 2 to 4 bytes that is 1 and 2 register writes The data must be integer without decimal point Here you can set the sending station address register address and the number of bytes If it is 4 bytes you can select the big endian format or the little endian format For data convenience if the corresponding method is temp 1234 you need to enter temp in the input box Here you need to enter the chara...

Page 26: ...ce occurs when the network is sent If the TCP is not established it will not be sent and there is no time service Figure 27 645 timing configuration The TIME 0 here is optional If it is filled in the time service will be sent after the device obtains the effective time If you do not fill in the time service will be sent under any circumstances If the time service is incorrect it will cause problem...

Page 27: ...se the 05 command to set the station address 02 and the coil starting with register 03 Then in JSON to Modbus interface click JSON Delivery Figure 28 Enter JSON to send The configuration interface is as follows pay attention to the alert on setting that needs to be written Figure 29 Configure coil ...

Page 28: ...that the keyword here only needs to enter power and you do not need to enter the following 12345 because this value is changed but you need to enter a colon If the quotation marks are in the issued data you also need to enter quotation marks 5 MQTT MQTT can be used alone or in conjunction with the JSON function When used alone the MQTT function transparently transmits serial port data to the MQTT ...

Page 29: ...ll pop up Figure 32 MQTT configuration 2 Here select Web Directory Download and then select an empty directory such as the MQTTHTTPD directory and then click Clear All to clear the previous design note that if the previous design was designed according to JSON do not clear all otherwise the previous design will be cleared JSON design Then click MQTT configuration ...

Page 30: ...s the topic subscribed by this device When other devices publish this topic the server will send it to this device If you are only publishing generally you do not need to fill in this field 6 Publish topic The topic of the data sent to the server when the device serial port is converted to MQTT 7 MQTT advanced parameters used to configure advanced parameters 8 Save MQTT settings After designing cl...

Page 31: ...l information information about the last will 7 Whether to save the last wish whether the server needs to keep the last wish message sent to the client when the client is abnormally offline 8 Last wish quality the delivery quality level of the last wish message sent by the server 9 Subscription quality The delivery quality level of the subscription In some cases it needs to be set to 0 to prevent ...

Page 32: ...lick OK and you will return to the device management dialog box You can see that the device s destination IP working mode and destination port have been automatically modified to the MQTT settings Figure 36 Automatic modification If there is no automatic modification you need to set the destination IP working mode and destination port in the device edit dialog box Then click Edit Settings ...

Page 33: ...guration is complete 5 2 DATA TEST After the connection is completed the LINK light usually the blue light in the middle of the device turns on It indicates that the device is normally connected to the MQTT server Now open the serial port tool Figure 38 Serial port sending and receiving ...

Page 34: ...e JSON and MQTT can achieve the following functions 1 The MQTT based protocol is used to establish a connection with the server and data communication is carried out in the form of subscription and publication 2 Support independent design and automatic collection of Modbus RTU registers 3 Support the conversion of specific Modbus register content into JSON format and send it regularly and actively...

Page 35: ...please select the second item HTTP POST if it is HTTP GET please select the third item HTTP GET 2 POST GET URL When choosing POST or GET you must fill in the URL For example if the URL is http sacom wri v2 remove the http in front and enter sacom wri v2 directly Other JSON structure design methods are the same as the methods introduced before After clicking the Save JSON Settings button if POST GE...

Page 36: ...anual 36 36 www waveshare com This POST GET design method is simple and practical and it can simply and quickly realize the transmission of Modbus RTU and other instrument data to the server by means of HTTP POST GET JSON ...

Reviews: