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
|
* LAN_INIT_DELAY=2000 // set lan init delay for Wiznet ethernet shield
|
||||||
* ESP_WIFI_AP=MYAP // esp wifi access point name
|
* ESP_WIFI_AP=MYAP // esp wifi access point name
|
||||||
* ESP_WIFI_PWD=MYPWD // esp wifi access point password
|
* ESP_WIFI_PWD=MYPWD // esp wifi access point password
|
||||||
|
* WIFI_MANAGER_DISABLE //Disable wifi manager for esp8266
|
||||||
* DHT_DISABLE //disable DHT Input support
|
* 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 MQTT topic to publish device status: /myhome/s_out
|
||||||
* Default Alarm output topic /alarm
|
* Default Alarm output topic /alarm
|
||||||
* DHT support enabled
|
* 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
|
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
|
} //valid item
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void printIPAddress(IPAddress ipAddress) {
|
void printIPAddress(IPAddress ipAddress) {
|
||||||
for (byte thisByte = 0; thisByte < 4; thisByte++) {
|
for (byte thisByte = 0; thisByte < 4; thisByte++) {
|
||||||
Serial.print(ipAddress[thisByte], DEC);
|
Serial.print(ipAddress[thisByte], DEC);
|
||||||
@@ -377,16 +376,19 @@ void ip_ready_config_loaded_connecting_to_broker() {
|
|||||||
Serial.print(mqttClient.state());
|
Serial.print(mqttClient.state());
|
||||||
Serial.println(F(" try again in 5 seconds"));
|
Serial.println(F(" try again in 5 seconds"));
|
||||||
nextLanCheckTime = millis() + 5000;
|
nextLanCheckTime = millis() + 5000;
|
||||||
#ifdef RESET_PIN
|
#ifdef RESTART_LAN_ON_MQTT_ERRORS
|
||||||
mqttErrorRate++;
|
mqttErrorRate++;
|
||||||
if(mqttErrorRate>50){
|
if(mqttErrorRate>50){
|
||||||
Serial.print(F("Too many MQTT connection errors. Restart LAN"));
|
Serial.print(F("Too many MQTT connection errors. Restart LAN"));
|
||||||
mqttErrorRate=0;
|
mqttErrorRate=0;
|
||||||
|
#ifdef RESET_PIN
|
||||||
resetHard();
|
resetHard();
|
||||||
|
#endif
|
||||||
lanStatus=INITIAL_STATE;
|
lanStatus=INITIAL_STATE;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
lanStatus = RECONNECT;//12;
|
lanStatus = RECONNECT;//12;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -394,6 +396,7 @@ void ip_ready_config_loaded_connecting_to_broker() {
|
|||||||
|
|
||||||
void onInitialStateInitLAN() {
|
void onInitialStateInitLAN() {
|
||||||
#ifdef __ESP__
|
#ifdef __ESP__
|
||||||
|
#ifdef WIFI_MANAGER_DISABLE
|
||||||
if(!wifiInitialized) {
|
if(!wifiInitialized) {
|
||||||
WiFi.mode(WIFI_STA);
|
WiFi.mode(WIFI_STA);
|
||||||
Serial.print(F("WIFI AP/Password:"));
|
Serial.print(F("WIFI AP/Password:"));
|
||||||
@@ -404,16 +407,16 @@ void onInitialStateInitLAN() {
|
|||||||
WiFi.begin(QUOTE(ESP_WIFI_AP), QUOTE(ESP_WIFI_PWD));
|
WiFi.begin(QUOTE(ESP_WIFI_AP), QUOTE(ESP_WIFI_PWD));
|
||||||
wifiInitialized = true;
|
wifiInitialized = true;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
if (WiFi.status() == WL_CONNECTED) {
|
if (WiFi.status() == WL_CONNECTED) {
|
||||||
Serial.println("WiFi connected");
|
Serial.println("WiFi connected");
|
||||||
Serial.println("IP address: ");
|
Serial.println("IP address: ");
|
||||||
Serial.println(WiFi.localIP());
|
Serial.println(WiFi.localIP());
|
||||||
lanStatus=HAVE_IP_ADDRESS;//1;
|
lanStatus=HAVE_IP_ADDRESS;//1;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if not defined(__ESP__)
|
||||||
#else
|
|
||||||
IPAddress ip, dns, gw, mask;
|
IPAddress ip, dns, gw, mask;
|
||||||
int res = 1;
|
int res = 1;
|
||||||
Serial.println(F("Starting lan"));
|
Serial.println(F("Starting lan"));
|
||||||
@@ -464,12 +467,12 @@ void (*softRebootFunc)(void) = 0;
|
|||||||
|
|
||||||
void resetHard() {
|
void resetHard() {
|
||||||
#ifdef RESET_PIN
|
#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));
|
Serial.println(QUOTE(RESET_PIN));
|
||||||
delay(50);
|
delay(500);
|
||||||
pinMode(RESET_PIN, OUTPUT);
|
pinMode(RESET_PIN, OUTPUT);
|
||||||
digitalWrite(RESET_PIN,LOW);
|
digitalWrite(RESET_PIN,LOW);
|
||||||
delay(25);
|
delay(500);
|
||||||
digitalWrite(RESET_PIN,HIGH);
|
digitalWrite(RESET_PIN,HIGH);
|
||||||
delay(500);
|
delay(500);
|
||||||
#endif
|
#endif
|
||||||
@@ -1006,7 +1009,7 @@ void postTransmission() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void setup_main() {
|
void setup_main() {
|
||||||
setupCmdArduino();
|
setupCmdArduino();
|
||||||
printFirmwareVersionAndBuildOptions();
|
printFirmwareVersionAndBuildOptions();
|
||||||
|
|
||||||
#ifdef SD_CARD_INSERTED
|
#ifdef SD_CARD_INSERTED
|
||||||
@@ -1017,17 +1020,17 @@ void setup_main() {
|
|||||||
|
|
||||||
#ifdef _modbus
|
#ifdef _modbus
|
||||||
#ifdef CONTROLLINO
|
#ifdef CONTROLLINO
|
||||||
//set PORTJ pin 5,6 direction (RE,DE)
|
//set PORTJ pin 5,6 direction (RE,DE)
|
||||||
DDRJ |= B01100000;
|
DDRJ |= B01100000;
|
||||||
//set RE,DE on LOW
|
//set RE,DE on LOW
|
||||||
PORTJ &= B10011111;
|
PORTJ &= B10011111;
|
||||||
#else
|
#else
|
||||||
pinMode(TXEnablePin, OUTPUT);
|
pinMode(TXEnablePin, OUTPUT);
|
||||||
#endif
|
#endif
|
||||||
modbusSerial.begin(MODBUS_SERIAL_BAUD);
|
modbusSerial.begin(MODBUS_SERIAL_BAUD);
|
||||||
node.idle(&modbusIdle);
|
node.idle(&modbusIdle);
|
||||||
node.preTransmission(preTransmission);
|
node.preTransmission(preTransmission);
|
||||||
node.postTransmission(postTransmission);
|
node.postTransmission(postTransmission);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
delay(20);
|
delay(20);
|
||||||
@@ -1042,10 +1045,16 @@ pinMode(TXEnablePin, OUTPUT);
|
|||||||
#ifdef _artnet
|
#ifdef _artnet
|
||||||
ArtnetSetup();
|
ArtnetSetup();
|
||||||
#endif
|
#endif
|
||||||
/*
|
|
||||||
SPI.begin();
|
#ifndef WIFI_MANAGER_DISABLE
|
||||||
while (Ethernet.maintain() == NO_LINK && millis()<3000UL) {delay(500);Serial.print(F("."));}
|
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
|
delay(LAN_INIT_DELAY);//for LAN-shield initializing
|
||||||
//TODO: checkForRemoteSketchUpdate();
|
//TODO: checkForRemoteSketchUpdate();
|
||||||
}
|
}
|
||||||
@@ -1120,7 +1129,11 @@ void printFirmwareVersionAndBuildOptions() {
|
|||||||
Serial.println("(-)HARDRESET, using soft");
|
Serial.println("(-)HARDRESET, using soft");
|
||||||
#endif
|
#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() {
|
void setupMacAddress() {
|
||||||
|
|||||||
@@ -67,6 +67,13 @@
|
|||||||
#include <FS.h> //this needs to be first, or it all crashes and burns...
|
#include <FS.h> //this needs to be first, or it all crashes and burns...
|
||||||
#include <EEPROM.h>
|
#include <EEPROM.h>
|
||||||
#include <ESP8266HTTPClient.h>
|
#include <ESP8266HTTPClient.h>
|
||||||
|
|
||||||
|
#ifndef WIFI_MANAGER_DISABLE
|
||||||
|
#include <WiFiManager.h>
|
||||||
|
#include <DNSServer.h>
|
||||||
|
#include <ESP8266WebServer.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef _owire
|
#ifdef _owire
|
||||||
|
|||||||
@@ -129,6 +129,7 @@
|
|||||||
#undef _artnet
|
#undef _artnet
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef WIFI_MANAGER_DISABLE
|
||||||
#ifndef ESP_WIFI_AP
|
#ifndef ESP_WIFI_AP
|
||||||
#define ESP_WIFI_AP mywifiap
|
#define ESP_WIFI_AP mywifiap
|
||||||
#endif
|
#endif
|
||||||
@@ -136,5 +137,6 @@
|
|||||||
#ifndef ESP_WIFI_PWD
|
#ifndef ESP_WIFI_PWD
|
||||||
#define ESP_WIFI_PWD mywifipass
|
#define ESP_WIFI_PWD mywifipass
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
#define DHT_POLL_DELAY_DEFAULT 15000
|
#define DHT_POLL_DELAY_DEFAULT 15000
|
||||||
@@ -92,6 +92,7 @@ lib_deps =
|
|||||||
Adafruit Unified Sensor
|
Adafruit Unified Sensor
|
||||||
DHT sensor library for ESPx
|
DHT sensor library for ESPx
|
||||||
DHT sensor library
|
DHT sensor library
|
||||||
|
WifiManager
|
||||||
|
|
||||||
|
|
||||||
[env:megaatmega2560-5500]
|
[env:megaatmega2560-5500]
|
||||||
|
|||||||
Reference in New Issue
Block a user