Modbus TCP

I note that the Fieldbus Gateway is available soon which supports Modbus TCP.

Is a class for Modbus TCP be available? I only see the RTU in

The modbus TCP on the fieldbus accelerator is via the wiznet interface - as modbus-tcp isn’t exactly secure, we recommend it is on a dedicated point to point interface like this.

Modbus will be becoming an officially supported library which will work for multiple transports including RTU and TCP. Release 34 added a whole load of features which help make a good RTU implementation, and those will be supported too.

Link the the Mudbus Library

Thanks for this.

We have been using the Modbus TCP library and we are seeing a critical error that we notice has been fixed on the contributing branch given below. Can this be pulled into the Electric Imp library?

The fix has been released in v1.0.1. Please give it a try and let me know if you have any questions.

Thanks, we will pick this up. We have been using the fix for a couple of weeks - it looks good.

The Modbus TCP library does not gracefully handle sending and disconnect, where the modbus connection has subsequently failed. This results in these two errors:

  • ERROR: the index ‘transmit’ does not exist
  • ERROR: the index ‘close’ does not exist

Testing for ‘transmit’ and ‘close’ in _connection would solve this problem, e.g.:

function _send(PDU, properties) {
    _transactions[_transactionCount] <- properties;
    local ADU = _createADU(PDU);
    // with or without success in transmission of data, the transaction count would be advanced
    _transactionCount = (_transactionCount + 1) % MAX_TRANSACTION_COUNT;
    if ("transmit" in _connection) {
        _connection.transmit(ADU, function(error) {
            if (error) {
                _callbackHandler(error, null, properties.callback);
            } else {
                _log(ADU, "Outgoing ADU: ");
    } else {
        // don't attempt to transmit if connection no longer exists
        local error = "CONNECTION_NO_LONGER_ACTIVE";
        _callbackHandler(error, null, properties.callback);

function disconnect(callback = null) {
    _shouldRetry = false;
    if ("close" in _connection) {
    } else if (callback) {