Arduino sketch for the Arduino Opta series https://opta.findernet.com/fr/arduino
The goal of this sketch is to implement an easy to use MQTT gateway for industrial equipments.
Based on "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
- 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 inputs (pulse, digital, analog)
- RS485 helpers
- Serial commands
- Password protected Web server for visualization and configuration
- Persistent configuration storage in flash memory
- Watchdog (variable between network reconnection and loop)
- Lots of simple methods to deal with inputs/outputs/storage...
- Lite and fast loop to keep MQTT publishing of input change state under 50ms
- Support for OTA update
- Support for Modbus
- Support for device expansions boards
Wifi AP MODE
If Wifi SSID is not configured and Wifi is set as prefered network, the Wifi goes into Access Point mode.
Default IP is 192.168.1.231, default SSID is opta99999 and password is opta2iot.
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.
Network settings are configured in setup process and can not be changed without a device reboot.
This sketch display activity on serial port and also support several commands.
These commands are not case sensitive.
CONFIG: Send to serial monitor the user configDHCP: Switch ethernet DHCP mode in configurationFORMAT: Create/format partitions (and reboot)INFO: Send to serial monitor the board informationsIP: Send to serial monitor the device IPLOOP: Send to serial monitor the number of loops per secondPUBLISH: Publish to MQTT device and inputs stateREBOOT: Reboot deviceRESET: Reset config to defaultTIME: Send to monitor the local timeUPDATE TIME: Query NTP server to update local timeVERSION: Send to serial monitor the library versionWIFI: Switch Wifi/Ethernet mode in configuration
You should do a REBOOT after DHCP, WIFI, RESET actions.
This sketch has MQTT client that supports MQTT 3.3.1 and broker with password credentials.
MQTT broker IP, port, user, password, topic, delay can be configured through web server interface or config.h file.
Publishing input state and device information topics:
<base_topic>/<device_id>/Ix/valfor input value<base_topic>/<device_id>/Ix/typefor input type (0 = analog, 1 = digital, 2 = pulse)<base_topic>/<device_id>/device/typefor the device type (Opta Lite...)<base_topic>/<device_id>/device/ipfor the device current IP<base_topic>/<device_id>/device/versionfor the device installed sketch version
Command output state and device information topics:
<base_topic>/<device_id>/Oxfor output value with0= OFF,1= ON<base_topic>/<device_id>/device/getto force device information publishing (value doesn't matter)
Input state can also be published on demand by sending an HTTP request to the /publish URL.
Each INPUTS can be set in three ways:
ANALOG: Send value between 0 and 10DIGITAL: Send value 0 or 1PULSE: Send only value 1, ideal for counting
This sketch 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 visualization pagePOST /form: send new json data to this URL to udpate configurationGET /config: json configuration dataGET /device: HTML device configration pageGET /style.css: CSS for HTML pagesGET /favicon.ico: Icon for HTML pagesGET /publish: Publish to MQTT device and inputs state
Note: All pages require basic authentication !
During boot:
- Fast blink Red : Waiting for user to press button to fully reset device
- Fast blink Green to Red : Device is going to reboot
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 : MQTT connection OK
- No Green and no Red : Network connection OK but no MQTT connection
Wifi device:
- Fix Blue : Wifi in STA mode
- Slow blink Blue : Wifi in AP mode
- No Blue : Not in Wifi mode
During boot:
- On fast blink red LEDS, user can reset device to default by pressing button more than 5 seconds
After boot:
- User can reset device to default by pressing button more than 5 seconds
- Without network, user can switch WIFI mode by pressing button around 2 seconds
- Without network, user can change DHCP mode by pressing button less than 1 second
- 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 configurable watchog is present to reboot device on problem. There are two timeout that switch automatically :
- Configurable timeout for the loop (should be greater than 1 second)
- Fixed maximum timeout for the setup and for long operation like network connection.
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 afeter 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 Boardsby Arduino
From Arduino IDE menu: Tools > Manage libraries, you must install:
ArduinoHttpClientby Arduino at https://github.com/arduino-libraries/ArduinoHttpClientArduinoMqttClientby Arduino at https://github.com/arduino-libraries/ArduinoMqttClientArduinoJsonby Benoit Blanchon at https://github.com/bblanchon/ArduinoJson.gitArduinoRS485by Arduino at https://github.com/arduino-libraries/ArduinoRS485base64by Densaugeo at https://github.com/Densaugeo/base64_arduino
- Tools > Boards > Arduino Mbed OS Opta Boards > Opta
- Tools > Security > None
- Tools > Flash split > 2Mb M7
- Tools > Target core > Main Core
- Copy folder
opta2iotto your Arduino IDElibrariesfolder, - Restart your Arduino IDE
- Select your Opta board and port
- In menu go to: file > Examples > Examples from Custom Libraries > Opta Industrial IoT and select an example.
- Upload sketch to your Opta board. Enjoy.
To use opta2iot in your sketch, follow steps above, add this line at the begining of your sketch:
#include "opta2iot.h"
- Alberto Perro (source author)
- Jean-Christian Paul Denis (opta2iot author)
You are welcome to contribute to this code.
CERN-OHL-P-2.0 license