mirror of
https://github.com/anklimov/lighthub
synced 2025-12-08 04:39:49 +03:00
wifimanager esp8266, RESTART_LAN_ON_MQTT_ERRORS option, option RESET_PIN for restart on lan init error
This commit is contained in:
@@ -150,7 +150,9 @@ platformio device monitor -b 115200
|
||||
* LAN_INIT_DELAY=2000 // set lan init delay for Wiznet ethernet shield
|
||||
* ESP_WIFI_AP=MYAP // esp wifi access point name
|
||||
* ESP_WIFI_PWD=MYPWD // esp wifi access point password
|
||||
* WIFI_MANAGER_DISABLE //Disable wifi manager for esp8266
|
||||
* DHT_DISABLE //disable DHT Input support
|
||||
* RESTART_LAN_ON_MQTT_ERRORS //reinit LAN if many mqtt errors occured
|
||||
|
||||
|
||||
|
||||
@@ -172,5 +174,7 @@ platformio device monitor -b 115200
|
||||
* Default MQTT topic to publish device status: /myhome/s_out
|
||||
* Default Alarm output topic /alarm
|
||||
* DHT support enabled
|
||||
* Wifi manager for esp8266 enabled
|
||||
* RESTART_LAN_ON_MQTT_ERRORS disabled
|
||||
|
||||
If you've using Arduino IDE to compile & flash firmware, it will use Default options above and you will not able to configure additional compilers options except edit "options.h" file
|
||||
|
||||
@@ -181,7 +181,6 @@ void mqttCallback(char *topic, byte *payload, unsigned int length) {
|
||||
} //valid item
|
||||
}
|
||||
|
||||
|
||||
void printIPAddress(IPAddress ipAddress) {
|
||||
for (byte thisByte = 0; thisByte < 4; thisByte++) {
|
||||
Serial.print(ipAddress[thisByte], DEC);
|
||||
@@ -377,16 +376,19 @@ void ip_ready_config_loaded_connecting_to_broker() {
|
||||
Serial.print(mqttClient.state());
|
||||
Serial.println(F(" try again in 5 seconds"));
|
||||
nextLanCheckTime = millis() + 5000;
|
||||
#ifdef RESET_PIN
|
||||
#ifdef RESTART_LAN_ON_MQTT_ERRORS
|
||||
mqttErrorRate++;
|
||||
if(mqttErrorRate>50){
|
||||
Serial.print(F("Too many MQTT connection errors. Restart LAN"));
|
||||
mqttErrorRate=0;
|
||||
#ifdef RESET_PIN
|
||||
resetHard();
|
||||
#endif
|
||||
lanStatus=INITIAL_STATE;
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
lanStatus = RECONNECT;//12;
|
||||
}
|
||||
}
|
||||
@@ -394,6 +396,7 @@ void ip_ready_config_loaded_connecting_to_broker() {
|
||||
|
||||
void onInitialStateInitLAN() {
|
||||
#ifdef __ESP__
|
||||
#ifdef WIFI_MANAGER_DISABLE
|
||||
if(!wifiInitialized) {
|
||||
WiFi.mode(WIFI_STA);
|
||||
Serial.print(F("WIFI AP/Password:"));
|
||||
@@ -404,16 +407,16 @@ void onInitialStateInitLAN() {
|
||||
WiFi.begin(QUOTE(ESP_WIFI_AP), QUOTE(ESP_WIFI_PWD));
|
||||
wifiInitialized = true;
|
||||
}
|
||||
|
||||
#endif
|
||||
if (WiFi.status() == WL_CONNECTED) {
|
||||
Serial.println("WiFi connected");
|
||||
Serial.println("IP address: ");
|
||||
Serial.println(WiFi.localIP());
|
||||
lanStatus=HAVE_IP_ADDRESS;//1;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#else
|
||||
#if not defined(__ESP__)
|
||||
IPAddress ip, dns, gw, mask;
|
||||
int res = 1;
|
||||
Serial.println(F("Starting lan"));
|
||||
@@ -464,12 +467,12 @@ void (*softRebootFunc)(void) = 0;
|
||||
|
||||
void resetHard() {
|
||||
#ifdef RESET_PIN
|
||||
Serial.print(F("Reset Wiznet5100 shield with digital pin "));
|
||||
Serial.print(F("Reset Arduino with digital pin "));
|
||||
Serial.println(QUOTE(RESET_PIN));
|
||||
delay(50);
|
||||
delay(500);
|
||||
pinMode(RESET_PIN, OUTPUT);
|
||||
digitalWrite(RESET_PIN,LOW);
|
||||
delay(25);
|
||||
delay(500);
|
||||
digitalWrite(RESET_PIN,HIGH);
|
||||
delay(500);
|
||||
#endif
|
||||
@@ -1006,7 +1009,7 @@ void postTransmission() {
|
||||
}
|
||||
|
||||
void setup_main() {
|
||||
setupCmdArduino();
|
||||
setupCmdArduino();
|
||||
printFirmwareVersionAndBuildOptions();
|
||||
|
||||
#ifdef SD_CARD_INSERTED
|
||||
@@ -1017,17 +1020,17 @@ void setup_main() {
|
||||
|
||||
#ifdef _modbus
|
||||
#ifdef CONTROLLINO
|
||||
//set PORTJ pin 5,6 direction (RE,DE)
|
||||
DDRJ |= B01100000;
|
||||
//set RE,DE on LOW
|
||||
PORTJ &= B10011111;
|
||||
//set PORTJ pin 5,6 direction (RE,DE)
|
||||
DDRJ |= B01100000;
|
||||
//set RE,DE on LOW
|
||||
PORTJ &= B10011111;
|
||||
#else
|
||||
pinMode(TXEnablePin, OUTPUT);
|
||||
pinMode(TXEnablePin, OUTPUT);
|
||||
#endif
|
||||
modbusSerial.begin(MODBUS_SERIAL_BAUD);
|
||||
node.idle(&modbusIdle);
|
||||
node.preTransmission(preTransmission);
|
||||
node.postTransmission(postTransmission);
|
||||
modbusSerial.begin(MODBUS_SERIAL_BAUD);
|
||||
node.idle(&modbusIdle);
|
||||
node.preTransmission(preTransmission);
|
||||
node.postTransmission(postTransmission);
|
||||
#endif
|
||||
|
||||
delay(20);
|
||||
@@ -1042,10 +1045,16 @@ pinMode(TXEnablePin, OUTPUT);
|
||||
#ifdef _artnet
|
||||
ArtnetSetup();
|
||||
#endif
|
||||
/*
|
||||
SPI.begin();
|
||||
while (Ethernet.maintain() == NO_LINK && millis()<3000UL) {delay(500);Serial.print(F("."));}
|
||||
*/
|
||||
|
||||
#ifndef WIFI_MANAGER_DISABLE
|
||||
WiFiManager wifiManager;
|
||||
#if defined(ESP_WIFI_AP) and defined(ESP_WIFI_PWD)
|
||||
wifiManager.autoConnect(QUOTE(ESP_WIFI_AP), QUOTE(ESP_WIFI_PWD));
|
||||
#else
|
||||
wifiManager.autoConnect();
|
||||
#endif
|
||||
#endif
|
||||
|
||||
delay(LAN_INIT_DELAY);//for LAN-shield initializing
|
||||
//TODO: checkForRemoteSketchUpdate();
|
||||
}
|
||||
@@ -1120,7 +1129,11 @@ void printFirmwareVersionAndBuildOptions() {
|
||||
Serial.println("(-)HARDRESET, using soft");
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef RESTART_LAN_ON_MQTT_ERRORS
|
||||
Serial.println(F("(+)RESTART_LAN_ON_MQTT_ERRORS"));
|
||||
#else
|
||||
Serial.println("(-)RESTART_LAN_ON_MQTT_ERRORS");
|
||||
#endif
|
||||
}
|
||||
|
||||
void setupMacAddress() {
|
||||
|
||||
@@ -67,6 +67,13 @@
|
||||
#include <FS.h> //this needs to be first, or it all crashes and burns...
|
||||
#include <EEPROM.h>
|
||||
#include <ESP8266HTTPClient.h>
|
||||
|
||||
#ifndef WIFI_MANAGER_DISABLE
|
||||
#include <WiFiManager.h>
|
||||
#include <DNSServer.h>
|
||||
#include <ESP8266WebServer.h>
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef _owire
|
||||
|
||||
@@ -129,6 +129,7 @@
|
||||
#undef _artnet
|
||||
#endif
|
||||
|
||||
#ifdef WIFI_MANAGER_DISABLE
|
||||
#ifndef ESP_WIFI_AP
|
||||
#define ESP_WIFI_AP mywifiap
|
||||
#endif
|
||||
@@ -136,5 +137,6 @@
|
||||
#ifndef ESP_WIFI_PWD
|
||||
#define ESP_WIFI_PWD mywifipass
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define DHT_POLL_DELAY_DEFAULT 15000
|
||||
@@ -92,6 +92,7 @@ lib_deps =
|
||||
Adafruit Unified Sensor
|
||||
DHT sensor library for ESPx
|
||||
DHT sensor library
|
||||
WifiManager
|
||||
|
||||
|
||||
[env:megaatmega2560-5500]
|
||||
|
||||
Reference in New Issue
Block a user