# LightHub: main.cpp File Reference

main.cpp File Reference
`#include "main.h"`
`#include "statusled.h"`
`#include <Dhcp.h>`
Include dependency graph for main.cpp:

## Functions

PubSubClient | mqttClient (ethClient)
void | cleanConf ()
bool | isNotRetainingStatus ()
void | mqttCallback (char *topic, byte *payload, unsigned int length)
void | printMACAddress ()
char * | getStringFromConfig (aJsonObject *a, int i)
char * | getStringFromConfig (aJsonObject *a, char *name)
void | setupOTA (void)
void | setupSyslog ()
lan_status | lanLoop ()
void | onMQTTConnect ()
void | ip_ready_config_loaded_connecting_to_broker ()
void | onInitialStateInitLAN ()
void | resetHard ()
void | Changed (int i, DeviceAddress addr, float currentTemp)
void | cmdFunctionHelp (int arg_cnt, char **args)
void | printCurentLanConfig ()
void | cmdFunctionKill (int arg_cnt, char **args)
void | cmdFunctionReboot (int arg_cnt, char **args)
void | applyConfig ()
void | printConfigSummary ()
void | cmdFunctionLoad (int arg_cnt, char **args)
int | loadConfigFromEEPROM ()
void | cmdFunctionReq (int arg_cnt, char **args)
int | mqttConfigRequest (int arg_cnt, char **args)
int | mqttConfigResp (char *as)
void | cmdFunctionSave (int arg_cnt, char **args)
void | cmdFunctionIp (int arg_cnt, char **args)
void | cmdFunctionClearEEPROM (int arg_cnt, char **args)
void | cmdFunctionPwd (int arg_cnt, char **args)
void | cmdFunctionSetMac (int arg_cnt, char **args)
void | cmdFunctionGet (int arg_cnt, char **args)
void | printBool (bool arg)
void | saveFlash (short n, char *str)
int | loadFlash (short n, char *str, short l)
void | saveFlash (short n, IPAddress &ip)
int | ipLoadFromFlash (short n, IPAddress &ip)
lan_status | loadConfigFromHttp (int arg_cnt, char **args)
void | preTransmission ()
void | postTransmission ()
void | setup_main ()
void | printFirmwareVersionAndBuildOptions ()
void | publishStat ()
void | setupMacAddress ()
void | setupCmdArduino ()
void | loop_main ()
void | owIdle (void)
void | ethernetIdle (void)
void | modbusIdle (void)
void | inputLoop (void)
void | inputSetup (void)
void | pollingLoop (void)
bool | isThermostatWithMinArraySize (aJsonObject *item, int minimalArraySize)
bool | thermoDisabledOrDisconnected (aJsonObject *thermoExtensionArray, int thermoStateCommand)
void | thermoLoop (void)
short | thermoSetCurTemp (char *name, float t)

## Variables

EthernetClient | ethClient
Streamlog debugSerial & | debugSerialPort
statusLED | LED (ledRED)
lan_status | lanStatus = INITIAL_STATE
const char configserver[] | PROGMEM = CONFIG_SERVER
char * | deviceName = NULL
aJsonObject * | topics = NULL
aJsonObject * | root = NULL
aJsonObject * | items = NULL
aJsonObject * | inputs = NULL
aJsonObject * | mqttArr = NULL
aJsonObject * | modbusObj = NULL
aJsonObject * | owArr = NULL
aJsonObject * | dmxArr = NULL
uint32_t | nextPollingCheck = 0
uint32_t | nextInputCheck = 0
uint32_t | nextLanCheckTime = 0
uint32_t | nextThermostatCheck = 0
uint32_t | nextSensorCheck =0
uint32_t | WiFiAwaitingTime =0
aJsonObject * | pollingItem = NULL
bool | owReady = false
bool | configOk = false
bool | configLoaded = false
bool | initializedListeners = false
int8_t | ethernetIdleCount =0
int8_t | configLocked = 0
ModbusMaster | node
byte | mac [6]
bool | wifiInitialized
int | mqttErrorRate

## Function Documentation

## applyConfig()

void applyConfig | ( |  | ) |

## Changed()

void Changed | ( | int | i,
|  | DeviceAddress | addr,
|  | float | currentTemp
| ) |  |

TODO: Refactore using Items interface

## cleanConf()

void cleanConf | ( |  | ) |

## cmdFunctionClearEEPROM()

void cmdFunctionClearEEPROM | ( | int | arg_cnt,
|  | char ** | args
| ) |  |

## cmdFunctionGet()

void cmdFunctionGet | ( | int | arg_cnt,
|  | char ** | args
| ) |  |

## cmdFunctionHelp()

void cmdFunctionHelp | ( | int | arg_cnt,
|  | char ** | args
| ) |  |

## cmdFunctionIp()

void cmdFunctionIp | ( | int | arg_cnt,
|  | char ** | args
| ) |  |

## cmdFunctionKill()

void cmdFunctionKill | ( | int | arg_cnt,
|  | char ** | args
| ) |  |

## cmdFunctionLoad()

void cmdFunctionLoad | ( | int | arg_cnt,
|  | char ** | args
| ) |  |

## cmdFunctionPwd()

void cmdFunctionPwd | ( | int | arg_cnt,
|  | char ** | args
| ) |  |

## cmdFunctionReboot()

void cmdFunctionReboot | ( | int | arg_cnt,
|  | char ** | args
| ) |  |

## cmdFunctionReq()

void cmdFunctionReq | ( | int | arg_cnt,
|  | char ** | args
| ) |  |

## cmdFunctionSave()

void cmdFunctionSave | ( | int | arg_cnt,
|  | char ** | args
| ) |  |

## cmdFunctionSetMac()

void cmdFunctionSetMac | ( | int | arg_cnt,
|  | char ** | args
| ) |  |

## ethernetIdle()

void ethernetIdle | ( | void |  | ) |

## getStringFromConfig() [1/2]

char* getStringFromConfig | ( | aJsonObject * | a,
|  | char * | name
| ) |  |

## getStringFromConfig() [2/2]

char* getStringFromConfig | ( | aJsonObject * | a,
|  | int | i
| ) |  |

## inputLoop()

void inputLoop | ( | void |  | ) |

## inputSetup()

void inputSetup | ( | void |  | ) |

## ip_ready_config_loaded_connecting_to_broker()

void ip_ready_config_loaded_connecting_to_broker | ( |  | ) |

## ipLoadFromFlash()

int ipLoadFromFlash | ( | short | n,
|  | IPAddress & | ip
| ) |  |

## isNotRetainingStatus()

bool isNotRetainingStatus | ( |  | ) |

## isThermostatWithMinArraySize()

bool isThermostatWithMinArraySize | ( | aJsonObject * | item,
|  | int | minimalArraySize
| ) |  |

## lanLoop()

lan_status lanLoop | ( |  | ) |

## loadConfigFromEEPROM()

int loadConfigFromEEPROM | ( |  | ) |

## loadConfigFromHttp()

lan_status loadConfigFromHttp | ( | int | arg_cnt,
|  | char ** | args
| ) |  |

## loadFlash()

int loadFlash | ( | short | n,
|  | char * | str,
|  | short | l
| ) |  |

## loop_main()

void loop_main | ( |  | ) |

## modbusIdle()

void modbusIdle | ( | void |  | ) |

## mqttCallback()

void mqttCallback | ( | char * | topic,
|  | byte * | payload,
|  | unsigned int | length
| ) |  |

## mqttClient()

PubSubClient mqttClient | ( | ethClient |  | ) |

## mqttConfigRequest()

int mqttConfigRequest | ( | int | arg_cnt,
|  | char ** | args
| ) |  |

## mqttConfigResp()

int mqttConfigResp | ( | char * | as | ) |

## onInitialStateInitLAN()

void onInitialStateInitLAN | ( |  | ) |

## onMQTTConnect()

void onMQTTConnect | ( |  | ) |

strncat(buf,item->name,sizeof(buf)); strncat(buf,",",sizeof(buf));

mqttClient.publish(topic,buf,true);

## owIdle()

void owIdle | ( | void |  | ) |

## pollingLoop()

void pollingLoop | ( | void |  | ) |

## postTransmission()

void postTransmission | ( |  | ) |

## preTransmission()

void preTransmission | ( |  | ) |

## printBool()

void printBool | ( | bool | arg | ) |

## printConfigSummary()

void printConfigSummary | ( |  | ) |

## printCurentLanConfig()

void printCurentLanConfig | ( |  | ) |

## printFirmwareVersionAndBuildOptions()

void printFirmwareVersionAndBuildOptions | ( |  | ) |

## printMACAddress()

void printMACAddress | ( |  | ) |

## publishStat()

void publishStat | ( |  | ) |

## resetHard()

void resetHard | ( |  | ) |

## saveFlash() [1/2]

void saveFlash | ( | short | n,
|  | char * | str
| ) |  |

## saveFlash() [2/2]

void saveFlash | ( | short | n,
|  | IPAddress & | ip
| ) |  |

## setup_main()

void setup_main | ( |  | ) |

## setupCmdArduino()

void setupCmdArduino | ( |  | ) |

## setupMacAddress()

void setupMacAddress | ( |  | ) |

## setupOTA()

void setupOTA | ( | void |  | ) |

## setupSyslog()

void setupSyslog | ( |  | ) |

## thermoDisabledOrDisconnected()

bool thermoDisabledOrDisconnected | ( | aJsonObject * | thermoExtensionArray,
|  | int | thermoStateCommand
| ) |  |

## thermoLoop()

void thermoLoop | ( | void |  | ) |

## thermoSetCurTemp()

short thermoSetCurTemp | ( | char * | name,
|  | float | t
| ) |  |

## Variable Documentation

## configLoaded

bool configLoaded = false

## configLocked

int8_t configLocked = 0

## configOk

bool configOk = false

## debugSerialPort

Streamlog infoSerial& debugSerialPort

## deviceName

char* deviceName = NULL

## dmxArr

aJsonObject* dmxArr = NULL

## ethClient

EthernetClient ethClient

## ethernetIdleCount

int8_t ethernetIdleCount =0

## initializedListeners

bool initializedListeners = false

## inputs

aJsonObject* inputs = NULL

## items

aJsonObject* items = NULL

## lanStatus

lan_status lanStatus = INITIAL_STATE

## LED

statusLED LED(ledRED)

## mac

byte mac[6]

## modbusObj

aJsonObject* modbusObj = NULL

## mqttArr

aJsonObject* mqttArr = NULL

## mqttErrorRate

int mqttErrorRate

## nextInputCheck

uint32_t nextInputCheck = 0

## nextLanCheckTime

uint32_t nextLanCheckTime = 0

## nextPollingCheck

uint32_t nextPollingCheck = 0

## nextSensorCheck

uint32_t nextSensorCheck =0

## nextThermostatCheck

uint32_t nextThermostatCheck = 0

## node

ModbusMaster node

## owArr

aJsonObject* owArr = NULL

## owReady

bool owReady = false

## pollingItem

aJsonObject* pollingItem = NULL

## PROGMEM

const char verval_P [] PROGMEM = CONFIG_SERVER

## root

aJsonObject* root = NULL

## topics

aJsonObject* topics = NULL

## WiFiAwaitingTime

uint32_t WiFiAwaitingTime =0

## wifiInitialized

bool wifiInitialized