Arduino Findernet Opta All In One Industrial IoT gateway
Arduino library for the Arduino Opta series https://opta.findernet.com/fr/arduino
The goal of this library is to implement an easy to use MQTT/Modbus gateway and more for industrial equipments.
Web page and config are inspired by "Remoto" (27-12-2024) by Alberto Perro under CERN-OHL-P license at https://github.com/albydnc/remoto
- Support Opta RS485 AFX00001, Opta Wifi AFX00002, Opta Lite AFX00003
- Support for digital expansion board Arduino Pro Opta Ext D16O8E AFX0000 and Arduino Pro Opta Ext D16O8S AFX00006
- Support OTA firmware update (wifi and ethernet)
- Partition formating (first boot or on demand) with Wifi firmware update
- Configurable Ethernet with DHCP or static IP
- Configurable Wifi STA or AP and with DHCP or static IP
- Configurable bidirectionnal MQTT Client with password support
- Configurable Modbus RTU or TCP, Client or Server
- Abstract inputs and ouputs structure to expose many informations
- Inputs and outputs counter and timer
- RS485 helpers
- Serial monitor and commands
- Password protected Web server for visualization and configuration
- Persistent configuration storage in flash memory
- Watchdog
- Multithreading loop
- Lots of simple methods to deal with inputs/outputs/storage...
- Fast MQTT publishing of input change state
- ...
- Support for analog expansions boards
- Code documentation
- More examples
- Bootloader check
Full documentation is in docs: getting started, configuration, inputs and outputs, web interface, serial commands, MQTT, Modbus, RS485, OTA, board and programming.
As this library is for industrial usage, expansion numbering and input numbering and output numbering start at 0, not 1 as printed on Opta device. This means that the first input of the opta board is named as I0.0 in industry.
- For now, only digital expansions are supported.
- Just plug in expansion and reboot Opta, Inputs and Ouputs are automatically added.
- First expansion has number 1, second has 2, ... the main board (The Opta device) has number 0.
Wifi AP mode
If Wifi SSID is not configured and Wifi is set as prefered network, the Wifi goes into Access Point mode.
Default SSID is optalinker + device ID and password is optalinker.
Wifi STA mode
If Wifi SSID and password are configured and Wifi is set as prefered network, the wifi goes into Standard mode.
Ethernet mode
If Ethernet is set as prefered network, wifi is disbaled.
DHCP
If DHCP mode is enabled in configuration, connection is tried to be established with dynamic IP,
else configured static IP address is used. By default static IP is 192.168.1.231.
Network settings are configured in setup process and can not be changed without a device reboot.
This library display activity on serial port and also support several commands.
These commands are not case sensitive.
print version: Send to serial monitor the OptaLinker library versionprint config: Send to serial monitor the contents of device configuration backup fileprint io: Send to serial monitor the contents of io backup fileprint store: Send to serial monitor the list of flash memory stored fileprint loop: Send to serial monitor the number of loops per secondprint ip: Send to serial monitor the device IPv4 addressprint boot: Send to serial monitor the number of boot of the deviceswitch dhcp: Switch ethernet DHCP mode in configurationswitch wifi: Switch Wifi/Ethernet mode in configurationprint time: Send to serial monitor the device timeupdate time: Query NTP server to update device local timecheck ota: Send to serial monitor OTA state and version, and request an OTA update checkflash memory: Create/format partitions and rebootreset config: Reset to default device configuration and rebootreset io: Reset all IO counters (no reboot)publish mqtt: Publish to MQTT device informations and IO statesreboot: Reboot device
You should do a REBOOT after SWITCH DHCP, SWITCH WIFI actions to take effect.
This library has MQTT client that supports MQTT 3.1.1 and broker with password credentials.
MQTT broker IP, port, user, password, topic, delay can be configured through web server interface (recommanded) or define.h file.
Publishing inputs statistics topics:
<base_topic><device_id>/input/state/xThe digital state of the input<base_topic><device_id>/input/voltage/xThe voltage (mV) of the input<base_topic><device_id>/input/pulse/xThe total number of pulse of the input<base_topic><device_id>/input/partialPulse/xThe partial number of pulse of the input (resetable)<base_topic><device_id>/input/high/xThe total time (s) of high level of the input<base_topic><device_id>/input/partialHigh/xThe partial time (s) of high level of the input (resetable)<base_topic><device_id>/input/low/xThe total time (s) of low level of the input<base_topic><device_id>/input/partialLow/xThe partial time (s) of low level of the input (resetable)
On state change, state and voltage are always published, pulse and partialPulse on high state, timers on low state.
Timers are also refreshed every minute.
Publishing outputs statistics topics:
<base_topic><device_id>/output/state/xThe digital state of the output<base_topic><device_id>/output/voltage/xThe voltage of the output (not implemented)<base_topic><device_id>/output/pulse/xThe total number of pulse of the output<base_topic><device_id>/output/partialPulse/xThe partial number of pulse of the output (resetable)<base_topic><device_id>/output/high/xThe total time (s) of high level of the output<base_topic><device_id>/output/partialHigh/xThe partial time (s) of high level of the output (resetable)<base_topic><device_id>/output/low/xThe total time (s) of low level of the output<base_topic><device_id>/output/partialLow/xThe partial time (s) of low level of the output (resetable)
Publishing device informations topics:
<base_topic><device_id>/device/typeThe human readable device type (Opta Lite...)<base_topic><device_id>/device/ipThe device IPv4 address<base_topic><device_id>/device/revisionThe device OptaLinker library version (in form of concat version like 10401)<base_topic><device_id>/device/otaThe device OTA update state (0 = none, 1 = requested, 2 = up to date, 3 = success, 4 = ongoing, 5 = failed)<base_topic><device_id>/rs485The RS485 received values<base_topic><device_id>/watchdogThe device watchdog send a timestamp every minute
Command output state and device counters and device information topics:
<base_topic><device_id>/input/get = xTo update MQTT value for an input<base_topic><device_id>/input/reset = xTo reset partial counters for an input<base_topic><device_id>/output/get = xTo update MQTT value for an output<base_topic><device_id>/output/reset = xTo reset partial counters for an ouput<base_topic><device_id>/output/set/xTo set state of an output with value0= OFF,1= ON<base_topic><device_id>/device/getTo force device information publishing (value doesn't matter)<base_topic>distant/ota/versionTo alert board about a firmware update version (for all devices using this base topic), the board then checks the version file next to its firmware URL<base_topic>distant/watchdogTo alert board about distant server is alive
Base topic must end with / (default opta/).
In notation, x mean Input or Output uniq ID, it is made of "Expansion number" and "Input Number" starting at 0 for main board.
For example to set the output O1.3 of the device 98 (device 98, expansion 1, Output 3, the ouput print as 4 on the device) to 1 : opta/98/output/set/103 = 1.
All messages are published as retained, with QoS 1 by default.
QoS 1 waits for broker acknowledgment on each message, with lots of expansions you can use linker.mqtt->setPublishQos(0) to publish faster.
Input state can also be published on demand by sending an HTTP request to the /publish URL.
This library support one of these modbus types at a time:
- Modbus TCP server (Ethernet or Wifi)
- Modbus TCP client (Ethernet or Wifi)
- Modbus RTU server (Rs485)
- Modbus RTU client (Rs485)
To use modbus RTU (client or server), RS485 must be disabled in configuration.
See dedicated Modbus document
This library OTA update feature is not written to work with ArduinoIotCould plateforme but it may work with...
OTA file
To learn more about OTA and on how to create .ota file, see official documentation at https://docs.arduino.cc/tutorials/portenta-h7/over-the-air-update/
The simplest way to create an OTA file is the OptaLinker OTA tool: it compiles your sketch and creates its .ota file in one step,
installing arduino-cli, Opta core and libraries by itself. See extra/tools/README.md.
Windows executables are attached to each release in optalinker-ota-windows.zip (optalinker-ota-gui.exe window version, optalinker-ota.exe command line version).
The OptaLinker library also contains the original python tools to create OTA file from an exported binary. Available in "extra" directory. (There is also a compiled dll version for Windows 11) There is also some .ota files from example .ino sketch to test OTA update.
OTA workflow
On web server device configuration page, there is a field named "Firmware file URL", you must fill in with the URL of your firmware .ota file.
OptaLinker library reads the firmware version in a version file next to the firmware file: firmware.json ({"version":10401}) for firmware.ota,
1 minute after boot then every hour. It also listens on MQTT topic <base topic>distant/ota/version to check now (this version is used if there is no version file).
To test a firmware on one device, put it on a second URL with its version file and set this URL on the test device only.
It is also possible to announce new firmware through modbus Holding Registers. (see modbus documentation)
Every hour, device check if a newer firmware version are available and if so, launch OTA update process.
In background, the firmware is downloaded and uncompressed, the bootloader is edited and if all is OK, device reboot and install new Firmware.
Important note
The update is processed in background and may take up to 10 minutes, during process the board is still active and works normally except the Web server is offline. (as both Web server and OTA process use same HTTP client.)
If an OTA update fails, the device does not retry it until next reboot. (Arduino_Portenta_OTA can not be started twice, see arduino-libraries/Arduino_Portenta_OTA#55)
This library provides a web interface for visualization and configuration through a web server with basic authentication. Web server is available in both Ethernet and Wifi mode.
- Default static IP address for web server is
192.168.1.231 - Default user and password for web interface are
admin:adminand can be changed in configuration.
Available web server entrypoints are:
GET /: HTML IO visualization pagePOST /form: send new json data to this URL to udpate configurationGET /config: json device configuration dataGET /data: json device information dataGET /io: json device IO dataGET /device: HTML device configration pageGET /favicon.ico: Icon for HTML pagesGET /publish: Publish to MQTT device and inputs state
Note: All pages require basic authentication !
During boot:
- Fast blink Green : Waiting for user to press button to fully reset device
- Fast blink Green to Red : Device is going to reboot
- Fix Green and red : Device is doning a long task (connection...)
After boot:
- Fix Green and Red with no blue : Connecting networks (this freeze device)
- Fast blink Green to Red : Device is going to reboot
- Fast short blink Green and Red : heartbeat
- Slow blink Red : No network connection
- Slow blink Green : No MQTT connection (network connection is OK)
- Fix Green : MQTT connection OK
Wifi device:
- Fix Blue : Wifi in STA mode
- Slow blink Blue : Wifi in AP mode
- No Blue : Not in Wifi mode
Button pushed duration make different actions :
During boot:
- +5s : On fast blink green LED, user can reset device to default by pressing button more than 5 seconds
After boot:
- +5s : User can reset device to default by pressing button more than 5 seconds
- +1s : Without network, user can switch WIFI mode by pressing button more then 1 second
- -1s : Without network, user can change DHCP mode by pressing button less than 1 second
- -1s : With MQTT connected, user can publish device information and IO states by pressing button less than 1 second
- -1s : With network and MQTT connection, user can force publishing input state to MQTT by pressing button less than 1 second
Note that actions take effect on button release. WIFI and DHCP actions reboot device.
A watchog is present. If device does not respond until 30s, the device reboot. (Maximum timeout of Opta board is 32270 milliseconds and cannot be stop.)
There is a bug on USB, there is no way to detect if cable is disconnected. And on cable disconnetion, board reboot after about 10 seconds.
For Arduino Finder Opta on its M7 core.
From Arduino IDE menu: Tools > Boards > Boards Manager, you must install:
Arduino Mbed OS Opta Boards4.6.0 by Arduino
From Arduino IDE menu: Tools > Manage libraries, you must install:
ArduinoHttpClientby Arduino at https://github.com/arduino-libraries/ArduinoHttpClientArduinojsonby Benoit Blanchon at https://github.com/bblanchon/ArduinoJson.gitArduinoRS485by Arduino at https://github.com/arduino-libraries/ArduinoRS485ArduinoModbusby Arduino at https://docs.arduino.cc/libraries/arduinomodbus/Arduino_KVStoreby arduino at https://github.com/arduino-libraries/Arduino_KVStoreArduino_Opta_Blueprintby Daniele Aimo at https://github.com/arduino-libraries/Arduino_Opta_BlueprintArduino_Portenta_OTAby Arduino at https://github.com/arduino-libraries/Arduino_Portenta_OTAMQTTby Joel Gaehwiler at https://github.com/256dpi/arduino-mqttNTPClientby Fabrice Weinberg at https://github.com/arduino-libraries/NTPClient
- Tools > Boards > Arduino Mbed OS Opta Boards > Opta
- Tools > Security > None
- Tools > Flash split > 2Mb M7
- Tools > Target core > Main Core
- Copy folder
OptaLinkerto your Arduino IDElibrariesfolder, - Restart your Arduino IDE
- Select your Opta board and port
- In menu go to: file > Examples > Examples from Custom Libraries > Opta Linker and select an example.
- Upload sketch to your Opta board. Enjoy.
To use OptaLinker in your sketch, see example OptaLinkerSimple.ino
Note: In your .ino loop() function, do not forget to add yield(); function to its end or your loop will become very slow.
- Alberto Perro (remoto author)
- Jean-Christian Paul Denis (OptaLinker author)
- Claude (Anthropic AI assistant)
You are welcome to contribute to this code.
CERN-OHL-P-2.0 license