22#if defined(__SAM3X8E__)
24 #if not defined (NOIP)
25 #include <ArduinoHttpClient.h>
30#if defined(ARDUINO_ARCH_AVR)
31 #if not defined (NOIP)
32 #include "HTTPClient.h"
35#include <avr/pgmspace.h>
39#if defined(ARDUINO_ARCH_ESP8266)
42#include <ESP_EEPROM.h>
51#include <user_interface.h>
55#if defined (ARDUINO_ARCH_ESP32)
75#include <ArduinoHttpClient.h>
78#if defined (ARDUINO_ARCH_STM32) and not defined (NOIP)
79#include "HttpClient.h"
90#if defined(__SAM3X8E__)
91#define wdt_res() watchdogReset()
101#define wdt_en() wdt_enable(WDTO_8S)
102#define wdt_dis() wdt_disable()
103#define wdt_res() wdt_reset()
106#ifdef ARDUINO_ARCH_ESP32
118#if defined(ARDUINO_ARCH_STM32)
129#if defined(ARDUINO_ARCH_AVR)
130#if defined(WATCH_DOG_TICKER_DISABLE)
131#define wdt_en() wdt_disable()
132#define wdt_dis() wdt_disable()
133#define wdt_res() wdt_disable()
135#define wdt_en() wdt_enable(WDTO_8S)
136#define wdt_dis() wdt_disable()
137#define wdt_res() wdt_reset()
142#include "DallasTemperature.h"
146#include <ModbusMaster.h>
153#if defined(_dmxin) || defined(_dmxout) || defined (_artnet)
159 #if defined(ARDUINO_ARCH_ESP32)
161 #include <HTTPClient.h>
162 #include <WiFiClient.h>
163 #include <WiFiClientSecure.h>
164 #include <WiFiManager.h>
165 #include <WebServer.h>
168 #include <ESP8266WiFi.h>
169 #include <ESP8266HTTPClient.h>
170 #include <WiFiManager.h>
171 #include <DNSServer.h>
172 #include <ESP8266WebServer.h>
173 #include <ESP8266mDNS.h>
177#if not defined (NOIP)
179 #include <Ethernet2.h>
182 #include "UIPEthernet.h"
184 #include <Ethernet.h>
195#ifdef SD_CARD_INSERTED
196#include "sd_card_w5100.h"
201 #include <ArduinoMDNS.h>
212 #if not defined (NOIP)
213 #include <PubSubClient.h>
227extern Artnet *artnet;
274#if not defined (NOIP)
282void mqttCallback(
char *topic,
byte *payload,
unsigned int length);
330void Changed(
int i, DeviceAddress addr,
float currentTemp);
lan_status lanStatus
Definition main.cpp:104
Definition streamlog.h:35
DMX input/output (and Art-Net) support.
IP<->UART Modbus gateway (Modbus TCP/UDP over RS485).
Item (virtual channel) system of LightHub.
short thermoSetCurTemp(char *name, float t)
int cmdFunctionLoglevel(int arg_cnt, char **args)
CLI command "log": changes serial/UDP log levels.
Definition main.cpp:1686
void setNextBroker()
Moves to the next configured MQTT broker (failover).
Definition main.cpp:1069
bool applyConfig()
Applies the loaded JSON config tree to the running system (items, inputs, topics, drivers).
Definition main.cpp:1418
bool cleanConf(short locksAlowed)
Frees the current config tree and its driver resources.
Definition main.cpp:180
void preTransmission()
Marks that an Ethernet transmission is about to happen; disables time-sensitive drivers as needed.
Definition main.cpp:2136
void printFirmwareVersionAndBuildOptions()
Prints firmware version, revision and build options at boot.
Definition main.cpp:2532
void setupMacAddress()
Resolves the controller MAC address (from flash or chip UID) and stores it in the system config.
Definition main.cpp:2817
void thermoLoop(void)
Thermostat control loop: checks temperature readings and drives heater relays (on/off/error bypass) w...
Definition main.cpp:3259
void printBool(bool arg)
Prints a bool as "+" or "-" to the info log.
Definition main.cpp:1861
void inputSetup(void)
Sets up input channels from the loaded config.
Definition main.cpp:3135
void postTransmission()
Marks that an Ethernet transmission has finished; re-enables drivers and handles lost-time compensati...
Definition main.cpp:2145
int cmdFunctionLoad(int arg_cnt, char **args)
CLI command "load": loads the config from the portal or flash.
Definition main.cpp:1600
void owIdle(void)
Idle hook invoked by the 1-Wire/DS2482 code between operations.
Definition main.cpp:2954
void inputLoop(short cause)
Polls digital/analog inputs and processes their events.
Definition main.cpp:3053
void mqttCallback(char *topic, byte *payload, unsigned int length)
MQTT receive callback: dispatches incoming messages to item command processing or config handling.
Definition main.cpp:393
int cmdFunctionHelp(int arg_cnt, char **args)
CLI command "help": lists available CLI commands.
Definition main.cpp:1367
int cmdFunctionKill(int arg_cnt, char **args)
CLI command "kill": aborts the current long operation.
Definition main.cpp:1395
int16_t attachMaturaTimer()
Attaches the Matura timer (interrupt-based timing helper).
Definition main.cpp:2254
int cmdFunctionGet(int arg_cnt, char **args)
CLI command "get": re-downloads the config from the portal.
Definition main.cpp:1772
int loadConfigFromHttp()
Downloads the device JSON config from the config server (HTTP GET with If-None-Match ETag),...
Definition main.cpp:1877
void loop_main()
Application main loop: runs the LAN/MQTT state machine, CLI poller, item polling, thermostat,...
Definition main.cpp:2879
void resetHard()
Hard-resets the board (watchdog or MCU reset).
Definition main.cpp:1353
int loadConfigFromEEPROM()
Loads the last saved config from flash into the config tree.
Definition main.cpp:1613
bool isNotRetainingStatus()
Checks whether the controller is not in the retain/collecting phase.
Definition main.cpp:246
void setup_main()
Application setup: init serial, flash config, MAC, LAN, HTTP/CLI listeners and all drivers (runs once...
Definition main.cpp:2355
void setFirstBroker()
Selects the first configured MQTT broker for connection.
Definition main.cpp:1062
void modbusIdle(void)
Idle hook invoked by the Modbus code between serial operations to let the main system breathe.
Definition main.cpp:3008
void inputSensorsLoop()
Polls periodic sensors (DHT, ultrasonic, ...) connected to inputs.
Definition main.cpp:3109
void printCurentLanConfig()
Prints the current LAN configuration to the serial port.
Definition main.cpp:1340
void setupCmdArduino()
Registers the serial CLI commands (help, save, load, get, mac, ip, kill, reboot, log,...
Definition main.cpp:2850
lan_status lanLoop()
One iteration of the LAN/MQTT state machine; advances the ethernet/WiFi/MQTT boot sequence and return...
Definition main.cpp:613
void printMACAddress()
Prints the current MAC address to the info log.
Definition main.cpp:543
int cmdFunctionSave(int arg_cnt, char **args)
CLI command "save": persists the current config tree to flash.
Definition main.cpp:1660
int cmdFunctionSetMac(int arg_cnt, char **args)
CLI command "mac": changes the controller MAC address.
Definition main.cpp:1818
void printConfigSummary()
Prints a summary of the current network/system config.
Definition main.cpp:1568
void onInitialStateInitLAN()
Initial LAN setup: initializes ethernet/WiFi and starts the address acquisition sequence.
Definition main.cpp:1198
void pollingLoop(void)
Periodic item polling: refreshes states and publishes changes.
Definition main.cpp:3186
void ip_ready_config_loaded_connecting_to_broker()
State handler for IP_READY_CONFIG_LOADED_CONNECTING_TO_BROKER: connects to the configured MQTT broker...
Definition main.cpp:1077
void inputStop(void)
Stops and releases all input channels.
Definition main.cpp:3161
void onMQTTConnect()
Called on (re)connect to the MQTT broker: sets up topics, subscribes and publishes retained states.
Definition main.cpp:927
bool IsThermostat(const aJsonObject *item)
Checks whether a config array entry is a thermostat item.
bool disabledDisconnected(const aJsonObject *thermoExtensionArray, int thermoLatestCommand)
Checks whether a thermostat must be stopped (disabled or its temperature sensor disconnected for too ...
lan_status
LAN/MQTT boot-up and runtime state machine states.
Definition main.h:237
@ INITIAL_STATE
Definition main.h:238
@ GET
Definition main.h:254
@ DO_GET
Definition main.h:253
@ IP_READY_CONFIG_LOADED_CONNECTING_TO_BROKER
Definition main.h:242
@ LIBS_INITIALIZED
Definition main.h:241
@ AWAITING_CONFIG
Definition main.h:256
@ DO_REINIT
Definition main.h:246
@ GET_IN_PROGRESS
Definition main.h:255
@ REINIT
Definition main.h:247
@ DO_RECONNECT
Definition main.h:248
@ DO_NOTHING
Definition main.h:252
@ OPERATION_NO_MQTT
Definition main.h:245
@ HAVE_IP_ADDRESS
Definition main.h:240
@ RETAINING_COLLECTING
Definition main.h:243
@ DO_READ_RE_CONFIG
Definition main.h:251
@ OPERATION
Definition main.h:244
@ RECONNECT
Definition main.h:249
@ READ_RE_CONFIG
Definition main.h:250
@ AWAITING_ADDRESS
Definition main.h:239
void Changed(int i, DeviceAddress addr, float currentTemp)
1-Wire temperature change callback.
1-Wire temperature sensing for thermostats.
Topic/suffix string constants.
Chip unique ID (20 bytes), viewable as 5 longs or 20 bytes.
Definition main.h:263
uint8_t UID_Byte[20]
Definition main.h:265
uint32_t UID_Long[5]
Definition main.h:264
Utility helpers of LightHub.