Local rules and equipment
Rules that run on the board itself, with or without network, and Modbus meters and drives on an RS-485 port. Both are set up in the console, not in the sketch.
Local rules
A local rule watches a reading and sets an output after a hold time, with a deadband on the way back. It can stay tripped until someone resets it, and it can refuse remote commands to its output while tripped. A network-loss rule puts outputs in a safe state when the board has been offline for a set time. Set them up on the device page, Controller tab: the board receives them, keeps them in flash and runs them on its own.
Safety
Local rules run on the controller even without network. They do not replace hardwired safety devices.
Rules are kept in flash on ESP32, ESP8266, STM32, Raspberry Pi Pico, Mega and UNO R4, so they keep running after a power cut without network. The Arduino Zero takes them again from the cloud when it connects. The Uno R3 and Blue Pill have no room for local rules.
Modbus equipment
Wire an RS-485 transceiver (a MAX485 module, for example) to a spare serial port, open the port at the equipment's speed, and hand it to the library. dePin drives the transceiver's DE and RE pins; use -1 for an adapter that switches direction by itself.
#include <maxwelltrack.h>
#define DEVICE_ID "YOUR_DEVICE_ID"
#define AUTH_TOKEN "YOUR_ACCESS_TOKEN"
#define RS485_DE 4
void onPump(String key, String value) {
digitalWrite(26, value.toInt() ? HIGH : LOW); // a rule or a dashboard switch
}
void setup() {
pinMode(26, OUTPUT);
Serial2.begin(9600, SERIAL_8N1, 16, 17); // ESP32: RX 16, TX 17
MaxwellTrack.useModbus(Serial2, RS485_DE);
MaxwellTrack.onWrite("pump", onPump);
MaxwellTrack.begin(DEVICE_ID, AUTH_TOKEN, "WiFi name", "WiFi password");
}
void loop() {
MaxwellTrack.run();
}Which meters, drives and controllers to read, their registers, word order, scale and reporting are chosen on the Controller tab: pick a model to load its registers, or add a custom register. The board reports a reading when it changes by its deadband, and at least every few minutes. A unit that stops answering is shown in the console, and Find equipment lists the addresses that answer. Writable registers follow dashboard controls.
Modbus works on ESP32, STM32, Raspberry Pi Pico, SAMD, Mega, UNO R4 and Nano R4 (Serial1, pins 0 and 1). Not on the ESP8266, which has no second serial port that can receive, nor on the Uno R3 or Blue Pill. The full example is 05.Controller/ModbusController.
For a whole site, equipment on Modbus TCP, OPC UA or CAN, or a local operator screen, use a site gateway instead.
Something unclear or out of date on this page? Tell support.
