13#include <TimerThree.h>
20#include <StaticThreadController.h>
23#include "src/Modules_Web/MainModule_Web.h"
59 pinMode(LED_BUILTIN, OUTPUT);
72 logToSerials(F(
"Setting up ESP-link connection"),
true, 0);
76 setSyncInterval(86400);
92 logToSerials(F(
"Setting up interrupt handler"),
false, 0);
93 Timer3.initialize(500);
99 logToSerials(F(
"Setting up wireless transceiver"),
false, 0);
107 Wireless.setRetries(WirelessDelay, WirelessRetry);
116 logToSerials(F(
"Setup ready, starting loops:"),
true, 0);
156 static bool ledStatus;
157 ledStatus = !ledStatus;
158 digitalWrite(LED_BUILTIN, ledStatus);
175 if (PushingBoxRestAPI.begin(
"api.pushingbox.com") == 0)
193 URLHandler *GrowBoxHandler = WebServer.createURLHandler(
"/Main.html.json");
198 URLHandler *SettingsHandler = WebServer.createURLHandler(
"/Settings.html.json");
203 URLHandler *HempyHandler = WebServer.createURLHandler(
"/Hempy.html.json");
247 static uint8_t MqttSubTopicLength = strlen(
MqttSubTopic) - 1;
252 String
mqttData = (*res).popString();
255 mqttTopic.remove(0, MqttSubTopicLength);
258 Main1->commandEventTrigger(command, data);
259 Main1->reportToMqttTrigger(
true);
262static bool SyncInProgress =
false;
269 time_t NTPResponse = 0;
272 SyncInProgress =
true;
273 uint32_t LastRefresh = millis();
275 while (NTPResponse == 0 && millis() - LastRefresh < 15000)
277 NTPResponse = ESPCmd.GetTime();
278 if (NTPResponse == 0) {
284 SyncInProgress =
false;
285 if (NTPResponse == 0)
293 setSyncInterval(86400);
305 Main1->websiteLoadEventTrigger(Url);
314 Main1->websiteRefreshEventTrigger(Url);
324 if (strcmp_P(Button, (PGM_P)F(
"RestoreDef")) == 0)
330 Main1->commandEventTrigger(Button, NULL);
342 Main1->commandEventTrigger(Field, WebServer.getArgString());
351 Main1->settingsEvent_Load(Url);
359 Main1->settingsEvent_Refresh(Url);
373 if (strcmp_P(Button, (PGM_P)F(
"RestoreDef")) == 0)
379 Main1->settingsEvent_Command(Button, NULL);
395 Main1->settingsEvent_Command(Field, WebServer.getArgString());
Definitions for ELClientCmd.
Definitions for ELClientMqtt.
Definitions for ELClientRes.
Definitions for ELClientWebServer.
Definitions for ELClient.
void logToSerials(const __FlashStringHelper *ToPrint, bool BreakLine, uint8_t Indent)
< Logging
void restoreDefaults()
Load sketch default settings into EEPROM.
void saveSettings(Settings *ToSave)
Store settings in EEPROM - Only updates changed bits.
Settings * loadSettings(bool ResetEEPROM)
Load settings from EEPROM.
#define MqttSubTopic
Subscribe to messages of this topic and all sub-topic.
#define MqttLwtMessage
Subscribers will get this message under the topic specified by MqttLwtTopic when the MQTT client goes...
#define MqttLwtTopic
When the connection is lost the MQTT broker will publish a final message to this topic....
void settingsButtonCallback(char *Button)
Called when a button is pressed on the /Settings.html web page.
RF24 Wireless(WirelessCEPin, WirelessCSNPin)
Wireless communication with Modules over nRF24L01+.
void resetWebServer()
(re-)Initialize the ESP-link connection
void settingsRefreshCallback(__attribute__((unused)) char *Url)
Called when the /Settings.html website is refreshing on the ESP-link webserver.
void fieldCallback(char *Field)
Called when a field on the website is submitted.
void mqttDisconnected(__attribute__((unused)) void *response)
char CurrentTime[MaxWordLength]
Buffer for storing current time in text format.
char LongMessage[MaxLongTextLength]
Temp storage for assembling long messages (REST API, MQTT reporting)
void mqttConnected(__attribute__((unused)) void *response)
void processTimeCriticalStuff()
time_t getNtpTime()
Update the time over ESP-link using NTP (Network Time Protocol)
HardwareSerial & ESPSerial
Reference to the ESP Link Serial output : Mega 2560 Rev3 Serial:0(RX) 1(TX), Serial1:19(RX1) 18(TX1),...
void buttonCallback(char *Button)
Called when a button is pressed.
void mqttReceived(void *response)
void mqttPublished(__attribute__((unused)) void *response)
char ShortMessage[MaxShotTextLength]
Temp storage for assembling short text messages (Log entries, Error messages,etc)
bool MqttConnected
Track the connection state to the MQTT broker configured on the ESP-link's REST/MQTT tab.
void settingsLoadCallback(__attribute__((unused)) char *Url)
Called when the /Settings.html website is loading on the ESP-link webserver.
MainModule * Main1
Represents a Grow Box with all components (Lights, DHT sensors, Power sensor, Aero/Hempy/Reservoir wi...
Settings * ModuleSettings
This object will store the settings loaded from the EEPROM. Persistent between reboots.
HardwareSerial & ArduinoSerial
Reference to the Arduino Serial output : Mega 2560 Rev3 Serial:0(RX) 1(TX) also showed on USB,...
ELClientWebServer WebServer & ESPLink
ESP-link - WebServer API.
bool & Debug
True - Turns on extra debug messages on the Serial Output.
void settingsFieldCallback(char *Field)
Called when a field on the /Settings.html website is submitted.
void heartBeat()
Turns the integrated LED on the Arduino board ON/OFF.
void refreshCallback(__attribute__((unused)) char *Url)
Called when a website is refreshing on the ESP-link webserver.
void loadCallback(__attribute__((unused)) char *Url)
Called when a website is loading on the ESP-link webserver.
void setupMqtt()
Sets up the MQTT relay.
bool & Metric
True - Use metric units, False - Use imperial units.
void ignoreCallback(__attribute__((unused)) char *Url)
Ignores the incoming load/refresh event. Used when embedding another module's web interface that alre...
void getWirelessStatus()
Prints the nRF24L01+ wireless transceiver's status to the Serial log.
constexpr uint8_t WirelessPayloadSize
Size of the wireless packages exchanged with the Main module. Max 32 bytes are supported on nRF24L01+...
constexpr uint8_t MaxShotTextLength
Default char * buffer length for storing mutiple words. Memory intense!
constexpr uint8_t MaxWordLength
Default char * buffer length for storing a word + null terminator. Memory intense!
constexpr uint16_t MaxLongTextLength
Default char * buffer length for storing a long text. Memory intense!
String popString()
Extract a string from the response packet.
void attach(T *item, retT(T::*method)(argT))
void mqttData(void *response)
bool Metric
Switch between Imperial/Metric units. If changed update the default temp and pressure values below to...
struct MainModuleSettings Main1
bool Debug
Logs debug messages to serial and web outputs.
FP< void, char * > setFieldCb
callback for setting a field from a HTML form
FP< void, char * > loadCb
Callback for HTML page loading.
FP< void, char * > buttonCb
callback for a HTML button press
FP< void, char * > refreshCb
Callback for HTML page refresh.