|
LightHub 4.6.0
Open-source smart home controller firmware
|
Main controller interface of LightHub. More...
#include "options.h"#include "streamlog.h"#include "DallasTemperature.h"#include <ModbusMaster.h>#include "owTerm.h"#include "dmx.h"#include <Ethernet.h>#include "Arduino.h"#include "utils.h"#include "textconst.h"#include <PubSubClient.h>#include <SPI.h>#include <string.h>#include "aJSON.h"#include <Cmd.h>#include "stdarg.h"#include "item.h"#include "inputs.h"Go to the source code of this file.
Classes | |
| union | UID |
| Chip unique ID (20 bytes), viewable as 5 longs or 20 bytes. More... | |
Enumerations | |
| enum | lan_status { INITIAL_STATE = 0 , AWAITING_ADDRESS = 1 , HAVE_IP_ADDRESS = 2 , LIBS_INITIALIZED = 3 , IP_READY_CONFIG_LOADED_CONNECTING_TO_BROKER = 4 , RETAINING_COLLECTING = 5 , OPERATION = 6 , OPERATION_NO_MQTT = 7 , DO_REINIT = -10 , REINIT = - 11 , DO_RECONNECT = 12 , RECONNECT = 13 , READ_RE_CONFIG = 14 , DO_READ_RE_CONFIG = 15 , DO_NOTHING = -15 , DO_GET = -16 , GET = -17 , GET_IN_PROGRESS = 18 , AWAITING_CONFIG = 19 } |
| LAN/MQTT boot-up and runtime state machine states. More... | |
Functions | |
| bool | isNotRetainingStatus () |
| Checks whether the controller is not in the retain/collecting phase. | |
| void | mqttCallback (char *topic, byte *payload, unsigned int length) |
| MQTT receive callback: dispatches incoming messages to item command processing or config handling. | |
| lan_status | lanLoop () |
| One iteration of the LAN/MQTT state machine; advances the ethernet/WiFi/MQTT boot sequence and returns the new state. | |
| int | loadConfigFromHttp () |
| Downloads the device JSON config from the config server (HTTP GET with If-None-Match ETag), parses and applies it. | |
| 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. | |
| 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 | setupMacAddress () |
| Resolves the controller MAC address (from flash or chip UID) and stores it in the system config. | |
| void | printMACAddress () |
| Prints the current MAC address to the info log. | |
| void | Changed (int i, DeviceAddress addr, float currentTemp) |
| 1-Wire temperature change callback. | |
| void | modbusIdle (void) |
| Idle hook invoked by the Modbus code between serial operations to let the main system breathe. | |
| 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. | |
| bool | applyConfig () |
| Applies the loaded JSON config tree to the running system (items, inputs, topics, drivers). | |
| 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 | cmdFunctionSetMac (int arg_cnt, char **args) |
| CLI command "mac": changes the controller MAC address. | |
| int | cmdFunctionGet (int arg_cnt, char **args) |
| CLI command "get": re-downloads the config from the portal. | |
| int | cmdFunctionLoglevel (int arg_cnt, char **args) |
| CLI command "log": changes serial/UDP log levels. | |
| void | printBool (bool arg) |
| Prints a bool as "+" or "-" to the info log. | |
| 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 | setup_main () |
| Application setup: init serial, flash config, MAC, LAN, HTTP/CLI listeners and all drivers (runs once at boot). | |
| 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 | inputLoop (short) |
| 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 | thermoLoop (void) |
| Thermostat control loop: checks temperature readings and drives heater relays (on/off/error bypass) with overheat alarms. | |
| short | thermoSetCurTemp (char *name, float t) |
| Updates the current-temperature store of a thermostat by name. | |
| void | printConfigSummary () |
| Prints a summary of the current network/system config. | |
| void | setupCmdArduino () |
| Registers the serial CLI commands (help, save, load, get, mac, ip, kill, reboot, log, ...) with the Cmd library. | |
| void | printFirmwareVersionAndBuildOptions () |
| Prints firmware version, revision and build options at boot. | |
| 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 long). | |
| void | resetHard () |
| Hard-resets the board (watchdog or MCU reset). | |
| bool | cleanConf (short locksAlowed=0) |
| Frees the current config tree and its driver resources. | |
| void | printCurentLanConfig () |
| Prints the current LAN configuration to the serial port. | |
| int16_t | attachMaturaTimer () |
| Attaches the Matura timer (interrupt-based timing helper). | |
| void | setFirstBroker () |
| Selects the first configured MQTT broker for connection. | |
| void | setNextBroker () |
| Moves to the next configured MQTT broker (failover). | |
Variables | |
| Streamlog | debugSerial |
| Streamlog | infoSerial |
| Streamlog | errorSerial |
| lan_status | lanStatus |
| Current state of the LAN/MQTT state machine. | |
Main controller interface of LightHub.
Declares the application entry points (setup_main/loop_main), the LAN/MQTT state machine (lan_status, lanLoop) and its initialization routines (onInitialStateInitLAN, onMQTTConnect, ip_ready_config_loaded_connecting_to_broker), remote config handling (loadConfigFromHttp, loadConfigFromEEPROM, applyConfig), the serial CLI command handlers (cmdFunction*) and the periodic polling loops (pollingLoop, thermoLoop, inputLoop) that drive items, thermostats and inputs.
| enum lan_status |
LAN/MQTT boot-up and runtime state machine states.
Positive values are boot/operation states; negative and high values are transient actions requested by loop_main (reinit, reconnect, config re-read, get).
| 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).
| void Changed | ( | int | i, |
| DeviceAddress | addr, | ||
| float | currentTemp ) |
1-Wire temperature change callback.
| i | Sensor index. |
| addr | DeviceAddress of the sensor. |
| currentTemp | Newly read temperature in Celsius. |
| bool cleanConf | ( | short | locksAlowed = 0 | ) |
Frees the current config tree and its driver resources.
| locksAlowed | Number of config locks that may be active. |
| 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 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 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 cmdFunctionSetMac | ( | int | arg_cnt, |
| char ** | args ) |
CLI command "mac": changes the controller MAC address.
| arg_cnt | Number of arguments. |
| args | Argument strings (new MAC). |
| bool disabledDisconnected | ( | const aJsonObject * | thermoExtensionArray, |
| int | thermoLatestCommand ) |
Checks whether a thermostat must be stopped (disabled or its temperature sensor disconnected for too long).
| thermoExtensionArray | Thermostat extension array from config. |
| thermoLatestCommand | Last received thermostat command. |
| 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.
| 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.
| bool IsThermostat | ( | const aJsonObject * | item | ) |
Checks whether a config array entry is a thermostat item.
| item | aJsonObject config array to check. |
| 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. |
| 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 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 thermoLoop | ( | void | ) |
Thermostat control loop: checks temperature readings and drives heater relays (on/off/error bypass) with overheat alarms.
| short thermoSetCurTemp | ( | char * | name, |
| float | t ) |
Updates the current-temperature store of a thermostat by name.
| name | Name of the thermostat item. |
| t | New temperature in Celsius. |
|
extern |
|
extern |
|
extern |
|
extern |
Current state of the LAN/MQTT state machine.