Attempting to fix disconnect on Adalight (ESP32, #194)
This commit is contained in:
parent
e754d21598
commit
bbe511dd15
@ -3,14 +3,14 @@
|
||||
#define NpbWrapper_h
|
||||
|
||||
//PIN CONFIGURATION
|
||||
#define LEDPIN 2 //strip pin. Any for ESP32, gpio2 or 3 is recommended for ESP8266 (gpio2/3 are labeled D4/RX on NodeMCU and Wemos)
|
||||
#define LEDPIN 2 //strip pin. Any for ESP32, gpio2 or 3 is recommended for ESP8266 (gpio2/3 are labeled D4/RX on NodeMCU and Wemos)
|
||||
//#define USE_APA102 // Uncomment for using APA102 LEDs.
|
||||
#define BTNPIN 0 //button pin. Needs to have pullup (gpio0 recommended)
|
||||
#define IR_PIN 4 //infrared pin (-1 to disable)
|
||||
#define RLYPIN 12 //pin for relay, will be set HIGH if LEDs are on (-1 to disable). Also usable for standby leds, triggers,...
|
||||
#define AUXPIN -1 //debug auxiliary output pin (-1 to disable)
|
||||
#define BTNPIN 0 //button pin. Needs to have pullup (gpio0 recommended)
|
||||
#define IR_PIN 4 //infrared pin (-1 to disable)
|
||||
#define RLYPIN 12 //pin for relay, will be set HIGH if LEDs are on (-1 to disable). Also usable for standby leds, triggers,...
|
||||
#define AUXPIN -1 //debug auxiliary output pin (-1 to disable)
|
||||
|
||||
#define RLYMDE 1 //mode for relay, 0: LOW if LEDs are on 1: HIGH if LEDs are on
|
||||
#define RLYMDE 1 //mode for relay, 0: LOW if LEDs are on 1: HIGH if LEDs are on
|
||||
|
||||
#ifdef USE_APA102
|
||||
#define CLKPIN 0
|
||||
|
@ -99,7 +99,7 @@
|
||||
|
||||
|
||||
//version code in format yymmddb (b = daily build)
|
||||
#define VERSION 1911261
|
||||
#define VERSION 1911301
|
||||
char versionString[] = "0.8.7-dev";
|
||||
|
||||
|
||||
@ -420,6 +420,10 @@ uint16_t ntpLocalPort = 2390;
|
||||
char* obuf;
|
||||
uint16_t olen = 0;
|
||||
|
||||
uint16_t savedPresets = 0;
|
||||
|
||||
byte errorFlag = 0;
|
||||
|
||||
String messageHead, messageSub;
|
||||
byte optionType;
|
||||
|
||||
|
@ -21,6 +21,11 @@
|
||||
//11-> 0.8.5-dev #mqttauth @TimothyBrown
|
||||
//12-> 0.8.7
|
||||
|
||||
void commit()
|
||||
{
|
||||
if (!EEPROM.commit()) errorFlag = 2;
|
||||
}
|
||||
|
||||
/*
|
||||
* Erase all configuration data
|
||||
*/
|
||||
@ -30,7 +35,7 @@ void clearEEPROM()
|
||||
{
|
||||
EEPROM.write(i, 0);
|
||||
}
|
||||
EEPROM.commit();
|
||||
commit();
|
||||
}
|
||||
|
||||
|
||||
@ -263,7 +268,7 @@ void saveSettingsToEEPROM()
|
||||
EEPROM.write(2522, mqttPort & 0xFF);
|
||||
EEPROM.write(2523, (mqttPort >> 8) & 0xFF);
|
||||
|
||||
EEPROM.commit();
|
||||
commit();
|
||||
}
|
||||
|
||||
|
||||
@ -541,12 +546,29 @@ void loadSettingsFromEEPROM(bool first)
|
||||
useHSB = useHSBDefault;
|
||||
|
||||
overlayCurrent = overlayDefault;
|
||||
|
||||
savedToPresets();
|
||||
}
|
||||
|
||||
|
||||
//PRESET PROTOCOL 20 bytes
|
||||
//0: preset purpose byte 0:invalid 1:valid preset 1.0
|
||||
//1:a 2:r 3:g 4:b 5:w 6:er 7:eg 8:eb 9:ew 10:fx 11:sx | custom chase 12:numP 13:numS 14:(0:fs 1:both 2:fe) 15:step 16:ix 17: fp 18-19:Zeros
|
||||
//determines which presets already contain save data
|
||||
void savedToPresets()
|
||||
{
|
||||
for (byte index = 1; index <= 16; index++)
|
||||
{
|
||||
uint16_t i = 380 + index*20;
|
||||
|
||||
if (EEPROM.read(i) == 1) {
|
||||
savedPresets |= 0x01 << (index-1);
|
||||
} else
|
||||
{
|
||||
savedPresets &= ~(0x01 << (index-1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool applyPreset(byte index, bool loadBri = true, bool loadCol = true, bool loadFX = true)
|
||||
{
|
||||
@ -594,7 +616,7 @@ void savePreset(byte index)
|
||||
|
||||
EEPROM.write(i+16, effectIntensity);
|
||||
EEPROM.write(i+17, effectPalette);
|
||||
EEPROM.commit();
|
||||
commit();
|
||||
}
|
||||
|
||||
|
||||
@ -636,5 +658,5 @@ void saveMacro(byte index, String mc, bool sing=true) //only commit on single sa
|
||||
{
|
||||
EEPROM.write(i, mc.charAt(i-s));
|
||||
}
|
||||
if (sing) EEPROM.commit();
|
||||
if (sing) commit();
|
||||
}
|
||||
|
@ -22,10 +22,10 @@ void handleSerial()
|
||||
static byte check = 0x00;
|
||||
static byte red = 0x00;
|
||||
static byte green = 0x00;
|
||||
static bool changed = false;
|
||||
|
||||
while (Serial.available() > 0)
|
||||
{
|
||||
yield();
|
||||
byte next = Serial.read();
|
||||
switch (state) {
|
||||
case AdaState::Header_A:
|
||||
@ -64,23 +64,18 @@ void handleSerial()
|
||||
break;
|
||||
case AdaState::Data_Blue:
|
||||
byte blue = next;
|
||||
changed = true;
|
||||
setRealtimePixel(pixel++, red, green, blue, 0);
|
||||
if (--count > 0) state = AdaState::Data_Red;
|
||||
else state = AdaState::Header_A;
|
||||
else {
|
||||
if (!realtimeActive && bri == 0) strip.setBrightness(briLast);
|
||||
arlsLock(realtimeTimeoutMs);
|
||||
|
||||
strip.show();
|
||||
state = AdaState::Header_A;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (changed)
|
||||
{
|
||||
if (!realtimeActive && bri == 0) strip.setBrightness(briLast);
|
||||
arlsLock(realtimeTimeoutMs);
|
||||
|
||||
yield();
|
||||
strip.show();
|
||||
changed = false;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -241,21 +241,23 @@ void handleConnection() {
|
||||
if (lastReconnectAttempt == 0) initConnection();
|
||||
|
||||
byte stac = 0;
|
||||
#ifdef ESP8266
|
||||
stac = wifi_softap_get_station_num();
|
||||
#else
|
||||
wifi_sta_list_t stationList;
|
||||
esp_wifi_ap_get_sta_list(&stationList);
|
||||
stac = stationList.num;
|
||||
#endif
|
||||
if (stac != stacO)
|
||||
{
|
||||
stacO = stac;
|
||||
DEBUG_PRINT("Connected AP clients: ");
|
||||
DEBUG_PRINTLN(stac);
|
||||
if (!WLED_CONNECTED && WLED_WIFI_CONFIGURED) { //trying to connect, but not connected
|
||||
if (stac) WiFi.disconnect(); //disable search so that AP can work
|
||||
else initConnection(); //restart search
|
||||
if (apActive) {
|
||||
#ifdef ESP8266
|
||||
stac = wifi_softap_get_station_num();
|
||||
#else
|
||||
wifi_sta_list_t stationList;
|
||||
esp_wifi_ap_get_sta_list(&stationList);
|
||||
stac = stationList.num;
|
||||
#endif
|
||||
if (stac != stacO)
|
||||
{
|
||||
stacO = stac;
|
||||
DEBUG_PRINT("Connected AP clients: ");
|
||||
DEBUG_PRINTLN(stac);
|
||||
if (!WLED_CONNECTED && WLED_WIFI_CONFIGURED) { //trying to connect, but not connected
|
||||
if (stac) WiFi.disconnect(); //disable search so that AP can work
|
||||
else initConnection(); //restart search
|
||||
}
|
||||
}
|
||||
}
|
||||
if (forceReconnect) {
|
||||
@ -272,7 +274,7 @@ void handleConnection() {
|
||||
interfacesInited = false;
|
||||
initConnection();
|
||||
}
|
||||
if (millis() - lastReconnectAttempt > 300000 && WLED_WIFI_CONFIGURED) initConnection();
|
||||
if (millis() - lastReconnectAttempt > ((stac) ? 300000 : 20000) && WLED_WIFI_CONFIGURED) initConnection();
|
||||
if (!apActive && millis() - lastReconnectAttempt > 12000 && (!wasConnected || apBehavior == 1)) initAP();
|
||||
} else if (!interfacesInited) { //newly connected
|
||||
DEBUG_PRINTLN("");
|
||||
|
@ -142,6 +142,8 @@ void serializeSegment(JsonObject& root, WS2812FX::Segment& seg, byte id)
|
||||
|
||||
void serializeState(JsonObject root)
|
||||
{
|
||||
if (errorFlag) root["error"] = errorFlag;
|
||||
|
||||
root["on"] = (bri > 0);
|
||||
root["bri"] = briLast;
|
||||
root["transition"] = transitionDelay/100; //in 100ms
|
||||
|
Loading…
Reference in New Issue
Block a user