main.h
Go to the documentation of this file.
#pragma once
#include "options.h"
#if defined(M5STACK)
#include <M5Stack.h>
#endif
#if defined(__SAM3X8E__)
#include <watchdog.h>
#include <ArduinoHttpClient.h>
//#include "TimerInterrupt_Generic.h"
#endif
#if defined(ARDUINO_ARCH_AVR)
#include "HTTPClient.h"
//#include <ArduinoHttpClient.h>
#include <avr/pgmspace.h>
#include <avr/wdt.h>
#endif
#if defined(ARDUINO_ARCH_ESP8266)
#include <FS.h> //this needs to be first, or it all crashes and burns...
#ifndef FS_STORAGE
#include <ESP_EEPROM.h>
#endif
//#include <ESP8266HTTPClient.h>
//#include <ArduinoHttpClient.h>
//#include "HttpClient.h"
//#include <WiFiManager.h>
//#include <DNSServer.h>
//#include <ESP8266WebServer.h>
//#include <ESP8266WiFi.h>
#include <user_interface.h>
//#define Ethernet WiFi
#endif
#if defined ARDUINO_ARCH_ESP32
#include <FS.h> //this needs to be first, or it all crashes and burns...
//#include "SPIFFS.h"
//#include <EEPROM.h>
//#include <NRFFlashStorage.h>
//#include "HttpClient.h"
//#include <ArduinoHttpClient.h>
//#include <HTTPClient.h>
//#include <WiFi.h>
//#include <WiFiClient.h>
//#include <WiFiClientSecure.h>
//#include <WebServer.h>
//#include <WiFiManager.h>
//include <DNSServer.h>
//#define Ethernet WiFi
#endif
#ifdef NRF5
//#include <NRFFlashStorage.h>
#include <ArduinoHttpClient.h>
#endif
#ifdef ARDUINO_ARCH_STM32
#include "HttpClient.h"
//#include "UIPEthernet.h"
//#include <NRFFlashStorage.h>
//#include <EEPROM.h>
#endif
#include "streamlog.h"
extern Streamlog debugSerial;
extern Streamlog infoSerial;
extern Streamlog errorSerial;
#if defined(__SAM3X8E__)
#define wdt_res() watchdogReset()
#define wdt_en()
#define wdt_dis()
#endif
//#ifndef DHCP_RETRY_INTERVAL
//#define DHCP_RETRY_INTERVAL 60000
//#endif
#if defined(ESP8266)
#define wdt_en() wdt_enable(WDTO_8S)
#define wdt_dis() wdt_disable()
#define wdt_res() wdt_reset()
#endif
#ifdef ARDUINO_ARCH_ESP32
#define wdt_res()
#define wdt_en()
#define wdt_dis()
#endif
#if defined(NRF5)
#define wdt_res()
#define wdt_en()
#define wdt_dis()
#endif
#if defined(ARDUINO_ARCH_STM32)
#define wdt_res()
#define wdt_en()
#define wdt_dis()
#endif
//#if defined(ESP8266)
//#define wdt_res()
//#define wdt_en()
//#define wdt_dis()
//#endif
#if defined(ARDUINO_ARCH_AVR)
#if defined(WATCH_DOG_TICKER_DISABLE)
#define wdt_en() wdt_disable()
#define wdt_dis() wdt_disable()
#define wdt_res() wdt_disable()
#else
#define wdt_en() wdt_enable(WDTO_8S)
#define wdt_dis() wdt_disable()
#define wdt_res() wdt_reset()
#endif
#endif
#ifndef OWIRE_DISABLE
#include "DallasTemperature.h"
#endif
#ifdef _modbus
#include <ModbusMaster.h>
#endif
#ifdef _owire
#include "owTerm.h"
#endif
#if defined(_dmxin) || defined(_dmxout) || defined (_artnet)
#include "dmx.h"
#endif
#ifdef WIFI_ENABLE
#if defined(ARDUINO_ARCH_ESP32)
#include <WiFi.h>
#include <HTTPClient.h>
#include <WiFiClient.h>
#include <WiFiClientSecure.h>
#include <WiFiManager.h>
#include <WebServer.h>
#include <ESPmDNS.h>
#else
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <WiFiManager.h>
#include <DNSServer.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
#endif
#define Ethernet WiFi
#else //Wired connection
#ifdef Wiz5500
#include <Ethernet2.h>
#else
#ifdef UIPETHERNET
#include "UIPEthernet.h"
#else
#include <Ethernet.h>
#endif
#endif
#endif
#ifdef _artnet
#include <Artnet.h>
#endif
#ifdef SD_CARD_INSERTED
#include "sd_card_w5100.h"
#endif
#ifdef MDNS_ENABLE
#ifndef WIFI_ENABLE
#include <ArduinoMDNS.h>
#endif
#endif
#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"
#ifdef _artnet
extern Artnet *artnet;
#endif
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
};
extern lan_status lanStatus;
typedef union {
uint32_t UID_Long[5];
uint8_t UID_Byte[20];
} UID;
bool isNotRetainingStatus();
void mqttCallback(char *topic, byte *payload, unsigned int length);
void printMACAddress();
lan_status lanLoop();
#ifndef OWIRE_DISABLE
void Changed(int i, DeviceAddress addr, float currentTemp);
#endif
void modbusIdle(void);
int cmdFunctionHelp(int arg_cnt, char **args);
int cmdFunctionKill(int arg_cnt, char **args);
void applyConfig();
int cmdFunctionLoad(int arg_cnt, char **args);
int loadConfigFromEEPROM();
int cmdFunctionSave(int arg_cnt, char **args);
int cmdFunctionSetMac(int arg_cnt, char **args);
int cmdFunctionGet(int arg_cnt, char **args);
int cmdFunctionLoglevel(int arg_cnt, char **args);
void printBool(bool arg);
/*
void saveFlash(short n, char *str);
int loadFlash(short n, char *str, short l=MAXFLASHSTR);
void saveFlash(short n, IPAddress& ip);
int ipLoadFromFlash(short n, IPAddress &ip);
*/
int loadConfigFromHttp();
void preTransmission();
void postTransmission();
void setup_main();
void loop_main();
void owIdle(void);
void modbusIdle(void);
void inputLoop(short);
void inputSetup(void);
void pollingLoop(void);
void thermoLoop(void);
short thermoSetCurTemp(char *name, float t);
void modbusIdle(void);
void printConfigSummary();
void setupCmdArduino();
void setupMacAddress();
void printFirmwareVersionAndBuildOptions();
bool IsThermostat(const aJsonObject *item);
bool disabledDisconnected(const aJsonObject *thermoExtensionArray, int thermoLatestCommand);
void resetHard();
void onInitialStateInitLAN();
void ip_ready_config_loaded_connecting_to_broker();
void printCurentLanConfig();
//void printFreeRam();
ip_ready_config_loaded_connecting_to_broker
void ip_ready_config_loaded_connecting_to_broker()
Definition: main.cpp:864
modbusIdle
void modbusIdle(void)
Definition: main.cpp:2406
owTerm.h
DO_NOTHING
@ DO_NOTHING
Definition: main.h:217
printMACAddress
void printMACAddress()
Definition: main.cpp:435
setupMacAddress
void setupMacAddress()
Definition: main.cpp:2263
REINIT
@ REINIT
Definition: main.h:212
RETAINING_COLLECTING
@ RETAINING_COLLECTING
Definition: main.h:208
cmdFunctionLoad
int cmdFunctionLoad(int arg_cnt, char **args)
Definition: main.cpp:1386
inputLoop
void inputLoop(short)
Definition: main.cpp:2443
IsThermostat
bool IsThermostat(const aJsonObject *item)
errorSerial
Streamlog errorSerial
options.h
IP_READY_CONFIG_LOADED_CONNECTING_TO_BROKER
@ IP_READY_CONFIG_LOADED_CONNECTING_TO_BROKER
Definition: main.h:207
printConfigSummary
void printConfigSummary()
Definition: main.cpp:1354
OPERATION_NO_MQTT
@ OPERATION_NO_MQTT
Definition: main.h:210
OPERATION
@ OPERATION
Definition: main.h:209
dmx.h
AWAITING_ADDRESS
@ AWAITING_ADDRESS
Definition: main.h:204
onInitialStateInitLAN
void onInitialStateInitLAN()
Definition: main.cpp:981
printCurentLanConfig
void printCurentLanConfig()
Definition: main.cpp:1191
textconst.h
printBool
void printBool(bool arg)
Definition: main.cpp:1639
lan_status
lan_status
Definition: main.h:202
utils.h
INITIAL_STATE
@ INITIAL_STATE
Definition: main.h:203
thermoSetCurTemp
short thermoSetCurTemp(char *name, float t)
mqttCallback
void mqttCallback(char *topic, byte *payload, unsigned int length)
Definition: main.cpp:370
setup_main
void setup_main()
Definition: main.cpp:1941
cmdFunctionLoglevel
int cmdFunctionLoglevel(int arg_cnt, char **args)
Definition: main.cpp:1479
setupCmdArduino
void setupCmdArduino()
Definition: main.cpp:2295
LIBS_INITIALIZED
@ LIBS_INITIALIZED
Definition: main.h:206
cmdFunctionKill
int cmdFunctionKill(int arg_cnt, char **args)
Definition: main.cpp:1202
RECONNECT
@ RECONNECT
Definition: main.h:214
loop_main
void loop_main()
Definition: main.cpp:2316
streamlog.h
printFirmwareVersionAndBuildOptions
void printFirmwareVersionAndBuildOptions()
Definition: main.cpp:2062
preTransmission
void preTransmission()
Definition: main.cpp:1894
Changed
void Changed(int i, DeviceAddress addr, float currentTemp)
Definition: main.cpp:1115
owIdle
void owIdle(void)
Definition: main.cpp:2377
DO_READ_RE_CONFIG
@ DO_READ_RE_CONFIG
Definition: main.h:216
infoSerial
Streamlog infoSerial
loadConfigFromHttp
int loadConfigFromHttp()
Definition: main.cpp:1653
Streamlog
Definition: streamlog.h:32
applyConfig
void applyConfig()
Definition: main.cpp:1216
inputs.h
debugSerial
Streamlog debugSerial
lanLoop
lan_status lanLoop()
Definition: main.cpp:523
cmdFunctionHelp
int cmdFunctionHelp(int arg_cnt, char **args)
Definition: main.cpp:1171
cmdFunctionGet
int cmdFunctionGet(int arg_cnt, char **args)
Definition: main.cpp:1599
READ_RE_CONFIG
@ READ_RE_CONFIG
Definition: main.h:215
pollingLoop
void pollingLoop(void)
Definition: main.cpp:2523
UID
Definition: main.h:222
cmdFunctionSetMac
int cmdFunctionSetMac(int arg_cnt, char **args)
Definition: main.cpp:1586
loadConfigFromEEPROM
int loadConfigFromEEPROM()
Definition: main.cpp:1397
isNotRetainingStatus
bool isNotRetainingStatus()
Definition: main.cpp:224
lanStatus
lan_status lanStatus
Definition: main.cpp:80
thermoLoop
void thermoLoop(void)
Definition: main.cpp:2593
resetHard
void resetHard()
Definition: main.cpp:1100
disabledDisconnected
bool disabledDisconnected(const aJsonObject *thermoExtensionArray, int thermoLatestCommand)
postTransmission
void postTransmission()
Definition: main.cpp:1903
inputSetup
void inputSetup(void)
Definition: main.cpp:2503
cmdFunctionSave
int cmdFunctionSave(int arg_cnt, char **args)
Definition: main.cpp:1434
HAVE_IP_ADDRESS
@ HAVE_IP_ADDRESS
Definition: main.h:205
DO_REINIT
@ DO_REINIT
Definition: main.h:211
item.h
DO_RECONNECT
@ DO_RECONNECT
Definition: main.h:213