|
LightHub 4.6.0
Open-source smart home controller firmware
|
#include "main.h"#include "statusled.h"#include "flashstream.h"#include "config.h"#include <Dhcp.h>Macros | |
| #define | ESP_EEPROM_SIZE 4096-10 |
Enumerations | |
| enum | heaterMode { HEATER_HEAT , HEATER_OFF , HEATER_ERROR } |
Functions | |
| PubSubClient | mqttClient (ethClient) |
| bool | cleanConf (short locksAlowed) |
| Frees the current config tree and its driver resources. | |
| bool | isNotRetainingStatus () |
| Checks whether the controller is not in the retain/collecting phase. | |
| uint16_t | httpHandler (Client &client, String request, uint8_t method, long contentLength, bool authorized, String &response) |
| int | inTopic (char *topic, topicType tt) |
| void | mqttCallback (char *topic, byte *payload, unsigned int length) |
| MQTT receive callback: dispatches incoming messages to item command processing or config handling. | |
| void | printMACAddress () |
| Prints the current MAC address to the info log. | |
| void | setupOTA (void) |
| void | setupSyslog () |
| lan_status | lanLoop () |
| One iteration of the LAN/MQTT state machine; advances the ethernet/WiFi/MQTT boot sequence and returns the new state. | |
| void | onMQTTConnect () |
| Called on (re)connect to the MQTT broker: sets up topics, subscribes and publishes retained states. | |
| void | setFirstBroker () |
| Selects the first configured MQTT broker for connection. | |
| void | setNextBroker () |
| Moves to the next configured MQTT broker (failover). | |
| void | ip_ready_config_loaded_connecting_to_broker () |
| State handler for IP_READY_CONFIG_LOADED_CONNECTING_TO_BROKER: connects to the configured MQTT broker(s). | |
| void | onInitialStateInitLAN () |
| Initial LAN setup: initializes ethernet/WiFi and starts the address acquisition sequence. | |
| void | printCurentLanConfig () |
| Prints the current LAN configuration to the serial port. | |
| void | resetHard () |
| Hard-resets the board (watchdog or MCU reset). | |
| int | cmdFunctionHelp (int arg_cnt, char **args) |
| CLI command "help": lists available CLI commands. | |
| int | cmdFunctionKill (int arg_cnt, char **args) |
| CLI command "kill": aborts the current long operation. | |
| int | cmdFunctionReboot (int arg_cnt, char **args) |
| int | cmdFunctionSearch (int arg_cnt, char **args) |
| bool | applyConfig () |
| Applies the loaded JSON config tree to the running system (items, inputs, topics, drivers). | |
| void | printConfigSummary () |
| Prints a summary of the current network/system config. | |
| int | cmdFunctionLoad (int arg_cnt, char **args) |
| CLI command "load": loads the config from the portal or flash. | |
| int | loadConfigFromEEPROM () |
| Loads the last saved config from flash into the config tree. | |
| int | cmdFunctionSave (int arg_cnt, char **args) |
| CLI command "save": persists the current config tree to flash. | |
| int | cmdFunctionLoglevel (int arg_cnt, char **args) |
| CLI command "log": changes serial/UDP log levels. | |
| int | cmdFunctionIp (int arg_cnt, char **args) |
| int | cmdFunctionOTAPwd (int arg_cnt, char **args) |
| int | cmdFunctionGet (int arg_cnt, char **args) |
| CLI command "get": re-downloads the config from the portal. | |
| int | cmdFunctionSetMac (int arg_cnt, char **args) |
| CLI command "mac": changes the controller MAC address. | |
| int | cmdFunctionClearEEPROM (int arg_cnt, char **args) |
| int | cmdFunctionPwd (int arg_cnt, char **args) |
| void | printBool (bool arg) |
| Prints a bool as "+" or "-" to the info log. | |
| void | headerHandlerProc (String header) |
| int | loadConfigFromHttp () |
| Downloads the device JSON config from the config server (HTTP GET with If-None-Match ETag), parses and applies it. | |
| void | preTransmission () |
| Marks that an Ethernet transmission is about to happen; disables time-sensitive drivers as needed. | |
| void | postTransmission () |
| Marks that an Ethernet transmission has finished; re-enables drivers and handles lost-time compensation. | |
| void | TimerHandler (void) |
| int16_t | attachMaturaTimer () |
| Attaches the Matura timer (interrupt-based timing helper). | |
| void | setup_main () |
| Application setup: init serial, flash config, MAC, LAN, HTTP/CLI listeners and all drivers (runs once at boot). | |
| void | printFirmwareVersionAndBuildOptions () |
| Prints firmware version, revision and build options at boot. | |
| void | publishStat () |
| void | setupMacAddress () |
| Resolves the controller MAC address (from flash or chip UID) and stores it in the system config. | |
| void | setupCmdArduino () |
| Registers the serial CLI commands (help, save, load, get, mac, ip, kill, reboot, log, ...) with the Cmd library. | |
| void | loop_main () |
| Application main loop: runs the LAN/MQTT state machine, CLI poller, item polling, thermostat, input, DMX and CAN iterations. | |
| void | owIdle (void) |
| Idle hook invoked by the 1-Wire/DS2482 code between operations. | |
| void | ethernetIdle (void) |
| void | modbusIdle (void) |
| Idle hook invoked by the Modbus code between serial operations to let the main system breathe. | |
| void | inputLoop (short cause) |
| Polls digital/analog inputs and processes their events. | |
| void | inputSensorsLoop () |
| Polls periodic sensors (DHT, ultrasonic, ...) connected to inputs. | |
| void | inputSetup (void) |
| Sets up input channels from the loaded config. | |
| void | inputStop (void) |
| Stops and releases all input channels. | |
| void | pollingLoop (void) |
| Periodic item polling: refreshes states and publishes changes. | |
| void | thermoRelay (int pin, heaterMode on) |
| void | thermoLoop (void) |
| Thermostat control loop: checks temperature readings and drives heater relays (on/off/error bypass) with overheat alarms. | |
Variables | |
| Streamlog debugSerial & | debugSerialPort |
| flashStream | sysConfStream |
| long | timer0_overflow_count |
| EthernetClient | ethClient |
| StatusLED | statusLED (ledRED) |
| lan_status | lanStatus = INITIAL_STATE |
| const char configserver[] | PROGMEM = CONFIG_SERVER |
| uint8_t | brokers = 0 |
| char * | deviceName = NULL |
| aJsonObject * | topics = NULL |
| aJsonObject * | root = NULL |
| aJsonObject * | items = NULL |
| aJsonObject * | inputs = NULL |
| aJsonObject * | brokersArr = NULL |
| aJsonObject * | mqttArr = NULL |
| aJsonObject * | modbusObj = NULL |
| aJsonObject * | owArr = NULL |
| aJsonObject * | dmxArr = NULL |
| volatile uint32_t | timerPollingCheck = 0 |
| volatile uint32_t | timerInputCheck = 0 |
| volatile uint32_t | timerLanCheckTime = 0 |
| volatile uint32_t | timerThermostatCheck = 0 |
| volatile uint32_t | timerSensorCheck =0 |
| volatile unsigned long | timerCount =0 |
| volatile int16_t | timerNumber =-1 |
| volatile int8_t | timerHandlerBusy =0 |
| volatile uint32_t | cryptoSalt =0 |
| volatile uint32_t | ultrasonicInputCheck =0 |
| aJsonObject * | pollingItem = NULL |
| volatile bool | owReady = false |
| volatile bool | configOk = false |
| volatile bool | configLoaded = false |
| volatile bool | initializedListeners = false |
| volatile uint8_t | DHCP_failures = 0 |
| volatile int8_t | ethernetIdleCount =0 |
| volatile int8_t | configLocked = 0 |
| ModbusMaster | node |
| bool | wifiInitialized |
| int8_t | mqttErrorRate =0 |
| const char * | headerKeys [] ={"ETag"} |
| volatile int8_t | inputLoopBusy = 0 |
| #define ESP_EEPROM_SIZE 4096-10 |
| enum heaterMode |
| bool applyConfig | ( | ) |
Applies the loaded JSON config tree to the running system (items, inputs, topics, drivers).
| int16_t attachMaturaTimer | ( | ) |
Attaches the Matura timer (interrupt-based timing helper).
| bool cleanConf | ( | short | locksAlowed = 0 | ) |
Frees the current config tree and its driver resources.
| locksAlowed | Number of config locks that may be active. |
| int cmdFunctionClearEEPROM | ( | int | arg_cnt, |
| char ** | args ) |
| int cmdFunctionGet | ( | int | arg_cnt, |
| char ** | args ) |
CLI command "get": re-downloads the config from the portal.
| arg_cnt | Number of arguments. |
| args | Argument strings. |
| int cmdFunctionHelp | ( | int | arg_cnt, |
| char ** | args ) |
CLI command "help": lists available CLI commands.
| arg_cnt | Number of arguments. |
| args | Argument strings. |
| int cmdFunctionIp | ( | int | arg_cnt, |
| char ** | args ) |
| int cmdFunctionKill | ( | int | arg_cnt, |
| char ** | args ) |
CLI command "kill": aborts the current long operation.
| arg_cnt | Number of arguments. |
| args | Argument strings. |
| int cmdFunctionLoad | ( | int | arg_cnt, |
| char ** | args ) |
CLI command "load": loads the config from the portal or flash.
| arg_cnt | Number of arguments. |
| args | Argument strings. |
| int cmdFunctionLoglevel | ( | int | arg_cnt, |
| char ** | args ) |
CLI command "log": changes serial/UDP log levels.
| arg_cnt | Number of arguments. |
| args | Argument strings (levels). |
| int cmdFunctionOTAPwd | ( | int | arg_cnt, |
| char ** | args ) |
| int cmdFunctionPwd | ( | int | arg_cnt, |
| char ** | args ) |
| int cmdFunctionReboot | ( | int | arg_cnt, |
| char ** | args ) |
| int cmdFunctionSave | ( | int | arg_cnt, |
| char ** | args ) |
CLI command "save": persists the current config tree to flash.
| arg_cnt | Number of arguments. |
| args | Argument strings. |
| int cmdFunctionSearch | ( | int | arg_cnt, |
| char ** | args ) |
| int cmdFunctionSetMac | ( | int | arg_cnt, |
| char ** | args ) |
CLI command "mac": changes the controller MAC address.
| arg_cnt | Number of arguments. |
| args | Argument strings (new MAC). |
| void ethernetIdle | ( | void | ) |
| void headerHandlerProc | ( | String | header | ) |
| uint16_t httpHandler | ( | Client & | client, |
| String | request, | ||
| uint8_t | method, | ||
| long | contentLength, | ||
| bool | authorized, | ||
| String & | response ) |
| void inputLoop | ( | short | cause | ) |
Polls digital/analog inputs and processes their events.
| cause | Why the loop is running (e.g. CHECK_INPUT). |
| void inputSensorsLoop | ( | ) |
Polls periodic sensors (DHT, ultrasonic, ...) connected to inputs.
| void inputSetup | ( | void | ) |
Sets up input channels from the loaded config.
| void inputStop | ( | void | ) |
Stops and releases all input channels.
| int inTopic | ( | char * | topic, |
| topicType | tt ) |
| void ip_ready_config_loaded_connecting_to_broker | ( | ) |
State handler for IP_READY_CONFIG_LOADED_CONNECTING_TO_BROKER: connects to the configured MQTT broker(s).
| bool isNotRetainingStatus | ( | ) |
Checks whether the controller is not in the retain/collecting phase.
| lan_status lanLoop | ( | ) |
One iteration of the LAN/MQTT state machine; advances the ethernet/WiFi/MQTT boot sequence and returns the new state.
| int loadConfigFromEEPROM | ( | ) |
Loads the last saved config from flash into the config tree.
| int loadConfigFromHttp | ( | ) |
Downloads the device JSON config from the config server (HTTP GET with If-None-Match ETag), parses and applies it.
| void loop_main | ( | ) |
Application main loop: runs the LAN/MQTT state machine, CLI poller, item polling, thermostat, input, DMX and CAN iterations.
| void modbusIdle | ( | void | ) |
Idle hook invoked by the Modbus code between serial operations to let the main system breathe.
| void mqttCallback | ( | char * | topic, |
| byte * | payload, | ||
| unsigned int | length ) |
MQTT receive callback: dispatches incoming messages to item command processing or config handling.
| topic | MQTT topic of the received message. |
| payload | Message payload (not necessarily null-terminated). |
| length | Payload length in bytes. |
| PubSubClient mqttClient | ( | ethClient | ) |
| void onInitialStateInitLAN | ( | ) |
Initial LAN setup: initializes ethernet/WiFi and starts the address acquisition sequence.
| void onMQTTConnect | ( | ) |
Called on (re)connect to the MQTT broker: sets up topics, subscribes and publishes retained states.
strncat(buf,item->name,sizeof(buf)); strncat(buf,",",sizeof(buf));
| void owIdle | ( | void | ) |
Idle hook invoked by the 1-Wire/DS2482 code between operations.
| void pollingLoop | ( | void | ) |
Periodic item polling: refreshes states and publishes changes.
| void postTransmission | ( | ) |
Marks that an Ethernet transmission has finished; re-enables drivers and handles lost-time compensation.
| void preTransmission | ( | ) |
Marks that an Ethernet transmission is about to happen; disables time-sensitive drivers as needed.
| void printBool | ( | bool | arg | ) |
Prints a bool as "+" or "-" to the info log.
| arg | Value to print. |
| void printConfigSummary | ( | ) |
Prints a summary of the current network/system config.
| void printCurentLanConfig | ( | ) |
Prints the current LAN configuration to the serial port.
| void printFirmwareVersionAndBuildOptions | ( | ) |
Prints firmware version, revision and build options at boot.
| void printMACAddress | ( | ) |
Prints the current MAC address to the info log.
| void publishStat | ( | ) |
| void resetHard | ( | ) |
Hard-resets the board (watchdog or MCU reset).
| void setFirstBroker | ( | ) |
Selects the first configured MQTT broker for connection.
| void setNextBroker | ( | ) |
Moves to the next configured MQTT broker (failover).
| void setup_main | ( | ) |
Application setup: init serial, flash config, MAC, LAN, HTTP/CLI listeners and all drivers (runs once at boot).
| void setupCmdArduino | ( | ) |
Registers the serial CLI commands (help, save, load, get, mac, ip, kill, reboot, log, ...) with the Cmd library.
| void setupMacAddress | ( | ) |
Resolves the controller MAC address (from flash or chip UID) and stores it in the system config.
| void setupOTA | ( | void | ) |
| void setupSyslog | ( | ) |
| void thermoLoop | ( | void | ) |
Thermostat control loop: checks temperature readings and drives heater relays (on/off/error bypass) with overheat alarms.
| void thermoRelay | ( | int | pin, |
| heaterMode | on ) |
| void TimerHandler | ( | void | ) |
| uint8_t brokers = 0 |
| aJsonObject* brokersArr = NULL |
| volatile bool configLoaded = false |
| volatile int8_t configLocked = 0 |
| volatile bool configOk = false |
| volatile uint32_t cryptoSalt =0 |
| Streamlog infoSerial& debugSerialPort |
| char* deviceName = NULL |
| volatile uint8_t DHCP_failures = 0 |
| aJsonObject* dmxArr = NULL |
| EthernetClient ethClient |
| volatile int8_t ethernetIdleCount =0 |
| const char* headerKeys[] ={"ETag"} |
| volatile bool initializedListeners = false |
| volatile int8_t inputLoopBusy = 0 |
| aJsonObject* inputs = NULL |
| aJsonObject* items = NULL |
| lan_status lanStatus = INITIAL_STATE |
| aJsonObject* modbusObj = NULL |
| aJsonObject* mqttArr = NULL |
| int8_t mqttErrorRate =0 |
| ModbusMaster node |
| aJsonObject* owArr = NULL |
| volatile bool owReady = false |
| aJsonObject* pollingItem = NULL |
| const char verval_P [] PROGMEM = CONFIG_SERVER |
| aJsonObject* root = NULL |
| systemConfig sysConf & sysConfStream |
|
extern |
| volatile unsigned long timerCount =0 |
| volatile int8_t timerHandlerBusy =0 |
| volatile uint32_t timerInputCheck = 0 |
| volatile uint32_t timerLanCheckTime = 0 |
| volatile int16_t timerNumber =-1 |
| volatile uint32_t timerPollingCheck = 0 |
| volatile uint32_t timerSensorCheck =0 |
| volatile uint32_t timerThermostatCheck = 0 |
| aJsonObject* topics = NULL |
| volatile uint32_t ultrasonicInputCheck =0 |
| bool wifiInitialized |