ModbusRTU extension

Ok, I see. Thank you very much for sharing!
I will take a look on it. :slight_smile:
Would it be a big effort to use the bluetooth interface instead of serial line?

I have examined the library that I have modified and used for my extensions. It had a Bluetooth serial class, but it only implements BT server (slave), so the external device has to initialize the connection. I think this is possible with HC-05, (not with HC-06) but this does not seems to be so useful.
One solution is to make a new Modbus extension that only do the Modbus formatting and checking. You can then use SerialOTG or a Bluetooth extensions for the communication. But this needs some work.

I have updated my ModbusRTU extension with support for BT and WIFI. I have added ModbusTCP protocol. You can also bridge ModbusRTU over BT or WIFI.

It implements single 16b read/write and a function to calculate modbusRTU CRC. You can use this to implement other Modbus functions.

The new extension can be found at:

I received the following email by @rkl099

Hello, I want to update information about my contributions to Appinventor

Modbus by rkl099. Support for Modbus RTU/TCP over serial, BT and WIFI

Direct link: GitHub - rkl099/Appinventor-Modbus: Appinventor ModbusRTU and ModbusTCP 1.1. Extension and app to implement single 16b/32b register read and 16b write. Uppdated for Andoid12

Thank you for listing extensions to Appinventor

Thank you @rkl099, now added in the extensions directory App Inventor Extensions | Pura Vida Apps

I have added read of one 32bit register to the Modbus extension (user request).

The wifi can connect to Modbus tcp, but the 4G network cannot be used

I have never tested that.
Can you describe your application? Do you use static or dynamic IP? Firewall, routers, ports etc?

The mobile phone uses Wi Fi to connect to the Internet to remotely control the Modbus TCP device.Modbus TCP devices use static ip.Modbus TCP devices without firewalls and routers use port 502.Using Wi Fi to connect to the Internet can successfully remote control.
The Modbus TCP device cannot be connected to the Internet using a 4G network.

If I understand your problem, you can't connect to the remote. That is, you can't open the connection in the app.
I can't see any real reason for this except:
You have to turn off WIFI.
The connection takes to long time. (limited to 0.5 sec in the library, but can be extended by a program change)

An updated version 1.5beta is now available on my rkl099/Appinventor-Debug directory.
The time to connect to a server has been changed from 0.5s to 5 sec, and some changes to select the driver. Please test and report.

Hello, I am interested for modbus TCP.
Is that possible with your work ?
Best regards

Yes, it's possible. You can study my example and the documentation at GitHub - rkl099/Appinventor-Modbus: Appinventor ModbusRTU and ModbusTCP 1.1. Extension and app to implement single 16b/32b register read and 16b write. Appinventor_Debug has a test release, but the changes are mainly in the serial part. Main limitations are: only a few functions are implemented. You can only have one outstanding request. Timeout must be programmed in your app.

With this extension I can use the modbus function code for coil writing

Only function codes 0x03, 0x04 and 0x06 have been implemented. Not single coil write 0x05 or any read/write of multiple data (except for read double register using fc 0x03). Please see the documentation.
It is possible to implement single coil read and single coil write, but i have no way of testing it.

I need to send the command to trigger the output coils in modbus. How can I write with function 0x06?

For the moment you have to write a program in the PLC (device) that copy a value in a holding register to a coil. Then use 0x06, write single holding register to write the data that shall be transferred to the coil.

Hello everyone
I want to read data running on plc with mit app
I looked at the examples on the forum but I couldn't succeed. The connection is established, but when I want to read data, I see the value -2.
Can you help with this ?

From your mail:

word type
D0 plc adres
1000 hexadecimal adress
44097 modbus adress

44097 mean read input register 4097 using function code 4 (16bit word).
The test program does not accept this format. Use address 4097 and FC4 instead.

D0 implies that it is a Modbus serial subnet bridged from this TCP unit. Normally it is 0 for direct Modbus/TCP addressing. The test program just send what is entered.

The test program uses decimal notation.

Note: Some PLC:s number the registers from 0 and some from 1. I guess that you should use dec 4096 in this example (Hex 1000)

1 Like

Thank you very much for your reply. I will try again tomorrow and get back to you.

Hello again
Data reading was successful.
Thank you very much for sharing this valuable information with us.