I have managed to use node-red to simulate a slave device using a TCP connection, but now I want to do it via serial connection. I am using a dell gateway running mbpoll to simulate the master connected to a raspberry pi running node-red to simulate the slave via RS485. Is it possible for me to use node-red on the raspberry pi to simulate the slave device, so it responds to requests from the gateway with values like a sensor would?
Based on your previous questions you are using node-red-contrib-modbus; this node does not support Modbus RTU as per the node descriptions:
modbus-server - Node to provide a Modbus TCP server based on node-modbus (jsmodbus) for testing.
modbus-flex-server - Node to provide a flexible Modbus TCP server based on modbus-serial for testing.
There may be another module out there that does support RTU slaves but I am not aware of one. As such I think your options are:
Modify the existing note to add support for RTP.
Use a gateway. There may be software that will do this (its not all that complicated) but I've not found anything freely available. There are a range of hardward gateways (some fairly cheap) that support comms between an RTU master and a TCP slave - e.g. 1 or 2.
Related
My requirement is, there are four ethernet switches connected in a straight daisy chain manner. But no ring/loop is formed. To each switch's PHY ports, there are I/O modules connected. A main CPU is interfaced to the first switch.
My problem is how will the main CPU the location of these ports(I/O modules)? Is there a way to send the MAC table data to another device/switch connected in the same network via a port.
Thanks
Need any other possible ways to implement this.
Is it possible to build a modbus-RTU ethernet gateway using a linux box or arduino?
I have plc slaves linked together using modbus RTU, and I want to connect one of them over TCP with my pc as master.
I wonder if I can use a linux box (rasbery pi/raspbian) connected to a router, as a modbus-to-tcp converter by piping the usb port to my local ip on some port, as one plc will be connected in modbus rtu to the linux box`s usb port.
Piping command will be something Like this:
nc -l 5626 > /dev/ttyUSB0 < /dev/ttyUSB0
My goal is to connect a pc (networked with the linux box) to that plc through the linux box using modbus.
Yes you can use a linux box with ethernet port.
Its not a simple 'nc' is it.
First things first, you need to know, Does your PLC's support Modbus TCP or Modbus RTU over TCP.
bcos both the formats are not the same, they are not interchangeable.
once you ascertain this, you need to write a TCP Client to Connect to the Slaves as they run the Servers.
If they don't support Modbus TCP yet, you need to write a TCP servers as well.
on top of that, you have the handshaking delays and half open connections and what not.
If it is a commercial device, you need to look at the setup it will be running as well.
Hope this helps
I'm not entirely sure as to what your requirements are, but you may want to have a look at the following library. It's a Modbus TCP->RTU library I assume you can use.
https://github.com/3cky/mbusd
Best Regards
While it's certainly possible to build a Modbus TCP/RTU gateway, you won't be able to do it with a simple nc command, for two reasons:
The actual Modbus protocol data unit (PDU), merely containing the Modbus function code and data, is embedded in an application data unit (ADU) so the request reaches the correct device free of communication errors. This ADU is different for RTU and TCP. Generically, the ADU looks like this:
------------------------------------------
| Additional address | PDU | Error check |
------------------------------------------
For RTU, the "Additional address" is a single byte identifying the unit/slave on the serial line, and the "Error check" is a 16-bit CRC.
For TCP, the "Additional address" is the 7-byte Modbus application protocol header (MBAP), consisting of transaction identifier, protocol identifier, and a length field (2 bytes each), plus a single byte identifying the unit/slave (usually 255, though for a gateway, this would be the ID of the RTU slave behind it). The "Error check" is empty (zero bytes) as that is already taken care of by TCP.
The communication semantics are different for RTU and TCP.
For RTU, you write a request to the serial line, wait for the reply, and only then write the next request. There must be 3½ characters of silence between frames.
For TCP, you can in principle have multiple connections being served concurrently. If you tried to forward two TCP requests to the serial line simultaneously, chaos would ensue.
Still, you can build a working gateway with a slightly more complicated program than nc:
Accept connections on TCP port 5626 (note that the actually recommended port number for Modbus TCP is 502), convert the received TCP ADUs to RTU ADUs and put them into a queue together with a back channel.
Another part of your program takes one item at a time from that queue, sends the ADU over the serial line and reports the result back through the back channel. Then it goes on the to the next item, and so on.
The results arriving on the back channels are converted to TCP ADUs and sent back on the respective TCP connection.
This would certainly work on a Raspberry Pi, and possibly also on Arduino, depending on how large you want your queue to be.
Sources:
http://www.modbus.org/docs/Modbus_Application_Protocol_V1_1b.pdf
http://www.modbus.org/docs/Modbus_Messaging_Implementation_Guide_V1_0b.pdf
everywhere I look, if it comes to MQTT messaging, it is all over Ethernet. Unfortunately, I do not have Ethernet wires available.
I am automating my home, wanting to use mqtt as messaging service. My buttons give a signal (like light 'on') to an arduino board running a mqtt client. How do i put out the mqtt message on the serial lines so the transmitted message can be straight forwardly be picked up by an mqtt broker, without using the ethernet cables?
As I was looking for the same answer and didn't find anything to my liking, I decided to write an implementation that enables any Bluetooth, USB or pure serial port communication to send MQTT message. You can find the result here : https://github.com/vortex314/serial2mqtt
It enables any linux machine ( Raspberry Pi 1, Raspi 3 , PC ) to act as a gateway.
It's written in C++ so should be lightweight enough for small devices.
Hope this helps.
Update 27/6 : build folder contains pre-build version for Linux Intel and Raspberry.
I am trying to achieve similar goals for my house automation, although I do have Cat5e in the walls, so could use Ethernet.
Here are some possibilities for using MQTT over serial communication:
Use SLIP between the Arduino and the gateway. The SerialIP client library which implements TCP/IP over serial: http://playground.arduino.cc/Code/SerialIP . Although I have not tested if this works with a MQTT client library. Nick O'Leary's MQTT Client theoretically works with any implementation of the Arduino 'Client' class.
It may be possible to implement MQTT directly over serial, without TCP/IP, although I am not aware of any gateways to do this.
MQTT-SN (a slightly different protocol to MQTT) was designed for sending messages over unreliable transport, and may be better suited to a serial line. If you are interested in publish-only, I wrote a very basic library to send MQTT-SN packets over serial: https://github.com/njh/DangerMinusOne
You could use something like Node-RED on the Linux gateway, talking some other serial protocol (Firmata?) to the Arduino and then converting to MQTT using Node-RED.
I did start looking at MQTT over serial implementations but one of the problems I didn't resolve was how to deal with multiple devices:
Adding lots of serial ports to Linux is complex/expensive (well sort of https://twitter.com/njh/status/570298977310150656)
Reliable serial over longer distances requires extra components for RS-485
MQTT doesn't work well over half-duplex, without an extra layer of software to deal with a master polling slaves for messages
So I am current looking at implementing MQTT-SN for the ENC28j60 ethernet controller...
For SLIP there is also the backwards compatible SlipMux which could easily support MQTT packet types. See also: sending packets over serial comms java
You could build a simple proxy that converts MQTT packets to SlipMux packets on one side and decodes the packets on the other side. The MQTT implementation should not notice anything.
Is it possible to get sensor output from Arduino via Ethernet connection and to send data to Arduino via Ethernet?
So basically can "replace" serial port with Ethernet port?
The typical way to do this is with an Arduino Ethernet shield, a small hardware module that plugs into your Arduino board:
http://arduino.cc/en/Main/ArduinoEthernetShield
Updated:
One very common approach for client to server communication would be to use HTTP over TCP/IP. See this example on the Ardunio site of a simple client on an Ardunio connecting with a server (in this case google):
http://arduino.cc/en/Tutorial/WebClient
For your use case you can simply create your own server and modify the example to send data to it.
Alternatively you can skip the HTTP part and just use sockets - there is an open source example here:
https://github.com/billroy/socket.io-arduino-client
I would like to develop my own modem for a custom communication network that will be detectable on the serial port by PC automatically. What I'm uncertain about is the protocol part of the AT commands and how to make it work seamlessly so that computer will detect the modem automatically.
I plan to use ftdi UART to USB converter to interface my microcontroller with the PC using standard serial interface. The PC will then use AT commands to communicate with the microcontroller that will in turn connect to another microcontroller over radio tranceiver and establish a two way serial connection over radio. The idea is that the PC on the other end will run PPPD and listen on it's own modem connection for incoming call and then bridge the connection with it's other internet interface that is connected to internet. The first computer will get it's own IP address using PPPD and will be connected to internet over this custom microcontroller based modem.
But how do I implement the communication protocol between my controller and PC? What commands do I absolutely need to implement? How do I make sure that the computer recognises my controller which is connected over ftdi usb to serial adapter as a functional modem?
Where can I find a speciffication of the minimum command set that is required of a modem?
In practice linux usually discovers a 3G modem automatically for example. Does that have to do with the actual USB identifier of the modem? Is it possible to have linux automatically discover an ordinary serial port modem? I'm thinking that the modem will be sending an AT idle ping repeatedly when it's plugged in so that linux should be able to detect it.