Auto Discovery of the slave id of modbus device in a network - modbus

How to determine whether device connected to the network is modbus device after getting valid ip range through broadcasting mechanism or How to Auto Discover the slave id of modbus device connected to the gateway ?

In the context of Modbus TCP, slaveId is not used to identify a Modbus device. IpAddress is used to identify the Modbus device if the device supports Modbus TCP/UDP.
if you want to discover the Modbus devices in a LAN, as you mentioned, you can send a broadcast message to all the range of IP addresses. But, there is no predefined register address to poll. Each Modbus device may be configured different address location.
Send TCP connection request for each :502.
And then for each connected device, like the Modscan tool, you can write your custom logic to scan all the registers in each discovered Modbus device.

You can try using nmap:
here you can find the tutorial to use.
You can also use Metasploit-framework(msfconsole):
Modbus Client Utility, you can read/write to modus device
Modbus Version Scanner, to detect modbus service
Modbus find unit ID, it only works under modbus TCP/IP, it send the request "0x04" to all the modbus ID(0-254) and check the response.

Related

Is RTU over TCP a spec-conforming modbus application?

For a week I've played with cheap modbus RS485/Ethernet adapters like USR-TCP232-304. I was assuming they would "speak" modbus TCP on the ethernet side and modbus RTU over RS485. After countless experiments I've found what that these adapters are actually expecting is RTU over TCP on the ethernet side, so they're not repackaging the ADU/PDU but simply relay.
Is this a standardized way of doing modbus or do I simply misunderstand what's going on?
Looking at the datasheet for the USR-TCP232-304 I see no mention of Modbus support; it's a RS485 Serial to Ethernet Converter only. These units makes no attempt to understand the data flowing over the link (if they receive a byte via RS485 they send it via the TCP link and vice versa). They can be used to talk to pretty much any device that uses RS485 (there are a lot of other protocols that run over RS485).
Modbus RTU transmitted via this kind of unit is pretty common if not exactly standardised (it's not mentioned in the modbus spec to my knowledge). Often these devices include drivers that present themselves as a serial port so, from the applications perspective, there is no real difference between direct RS485 and going via one of these devices (other than timings).
It looks like the next model up includes a modbus gateway function that will act as a Modbus TCP server (and there are plenty of other options; they generally cost a bit more because of the additional processing required).

Communication Between ESP8266-01 and NUCLEO-F030R8

I've been tasked with figuring out how to get a mobile app to communicate with an MCU then in turn control a stepper motor. Right now I'm trying to get the WiFi module (ESP8266-01) and MCU (NUCLEO-F030R8) to play nice with each other. The catch is I have little to no experience and no education in this field. The closest experience I have is simple Arduino sketches from years ago (IE photo-resistor values driving a stepper motor) and making desktop applications with C#. I am using STM32CubeIDE but if there's a better option I can switch to that.
What I would very much like help on is send and receive simple data between a smartphone and the MCU via the WiFi module. I've read through documentation and other questions but still don't exactly know where to start.
I understand this is probably a large topic in its own right and a short blurb on the internet won't do it (and undoubtedly its multiple subcategories) justice. But I might as well ask.
Sorry if this is too much and thank you in advance.
This project would involve making the following connections.
The UART connection between STM32 and ESP8266.
The WiFi connection between ESP8266 and the mobile.
The application layer protocol between ESP8266 and the application running on the mobile.
For 1, you can actually program the ESP8266 using Arduino IDE and simply connect the UART TX/RX pins of ESP8266 with RX/TX pins of STM32 respectively. You can create a test project in which ESP8266 sends data to STM32 over UART to verify this connection.
For 2, you need to consider the wifi network mode i.e identify whether the wifi connection is going to be ad-hoc (mobile connects to ESP8266 directly) or in infrastructure mode (mobile and ESP8266 connected via a shared access point). You can configure the ESP8266 in both modes. You just have to program the SSID and password of the Wifi network in the ESP8266 (in case of ad-hoc, it is the SSID of the network advertised by ESP8266 and in the infrastructure mode, it is the SSID of the common AP). This wifi functionality is also easily programmable in Arduino IDE for ESP8266.
Finally, once the physical connection has been established between the ESP8266 and mobile device, you need an application-level protocol to connect the application running on the mobile with the ESP8266. You can either use socket connection between ESP8266 and mobile application or use a higher-level communication protocol for IoT devices like MQTT, which is also available in the Arduino IDE.
Final connection diagram could be something like this:
application -> mqtt msgs -> wifi packets -> esp8266 recv pkts -> parse mqtt msgs -> forward data to STM32 over UART

Forward Bluetooth socket to serial port

I've been trying to figure out how to turn my Raspberry Pi into a USB to Bluetooth serial adapter. I want to be able to send data over Bluetooth to the Pi which has a USB thermal printer registered at /dev/usb/lp0.
Using only standard command line apps such as hciconfig, hcitool, rfcomm, and sdptool I have been able to see the Pi as visible, and pair to it from an Android tablet using a Bluetooth SPP app on the Store. However, the tablet disconnects immediately, and no data is sent. rfcomm listen /dev/rfcomm0 1 also waits for a connection forever.
I think I'm able to achieve what I need without custom code, using solely standard command line apps, but I'm not entirely sure. socat will likely be of use to finally connect the sockets.
Figures that I'd get it right after posting. To anyone else looking to do something similar:
Pair with bluez-simple-agent
Create your serial port channel with sdptool add --channel=x sp
Listen for a connection on that channel with sudo rfcomm listen /dev/rfcomm0 x
Cross the streams with socat /dev/rfcomm0 /dev/usb/lp0
Beautiful. It's all so simple now.

How to send OSC commands from iPad/iPhone over the Internet (not Wi-Fi)

I am building an Arduino based servo driver that I want to control with OSC commands from my iPad over the Internet.
Is it possible to send OSC commands over 3G / UMTS with my iPad or iPhone to control a device? So I will not be limited by the router's range when I send OSC commands to the controller when both devices are part of the same Wi-Fi network.
It seems that the applications I downloaded (TouchOSC, iOSC) can only send OSC data over Wi-Fi, however I'd like to send the commands over the Internet (with port forwarding settings in my router).
I would get one of these. Look ma, no wi-fi :)
OSC typically uses UDP (User Datagram Protocol), even if some newer OSC implementations also allow TCP/IP messaging (also see Difference between TCP and UDP?).
Unfortunately (as far as I know), UDP does not work over 3G, which seems to be your problem. In other words: two mobile devices cannot talk to each other on a cellular network. So it has nothing to do with OSC apps not being able to do this, it's just not available from the cellular network.
However (I think, not tested), I see two workarounds here:
try to use TCP/IP instead of UDP to send your OSC packets
if you need UDP on the Arduino side, you could use a server in-between
Do port forwarding on your router to forward port x to the Arduino, and then use the IP address from whatsmyip.com and use that one in the touchOSC app when inputting the IP address. That may work.

Using iPhone as a TCP and UDP server - open ports?

I need to send and get packets via UDP and TCP in iPhones and the server. But, I figured that if I wanna send packets to a client (iPhone), he is... A kinda server.
So, let's say I'm sending and getting packets to iPhone via the port 2347. Do I need to open the port on the iPhone or something like that? Is there any Firewall built-in to the iPhone?
No firewall on the iPhone. However, 99% of the time, the phone will not have a publicly accessible IP. It may be on wifi behind a router, or it may be on the cellular network most probably behind a NAT pool. Either way, you don't have access to any of those pieces of equipment, nor do your users in the cellular context (and potentially some cases of wifi usage). Think about doing this another way.
There is no firewall on the iPhone by default. Provided you don't need the iPhone to act as a server, i.e., bind a port, you can have the server send packets back to the iPhone using the information in which they were received, i.e., IP and port, using the protocol of your choosing, e.g., TCP or UDP.