From 5071f6754022e99db3fd24c630addba2f542125a Mon Sep 17 00:00:00 2001 From: Nils Bernhardt Date: Sat, 3 Mar 2018 14:55:30 +0100 Subject: [PATCH 01/23] Bugfixes --- espArtLeDNode/ajax.ino | 1 - espArtLeDNode/espArtLeDNode.ino | 68 +++++-- espArtLeDNode/startFunctions.ino | 324 +++++++++++++++++-------------- espArtLeDNode/store.h | 36 ++-- espArtLeDNode/ws2812Driver.cpp | 8 +- 5 files changed, 254 insertions(+), 183 deletions(-) diff --git a/espArtLeDNode/ajax.ino b/espArtLeDNode/ajax.ino index d3c5ef5..d3fd75e 100644 --- a/espArtLeDNode/ajax.ino +++ b/espArtLeDNode/ajax.ino @@ -741,4 +741,3 @@ void ajaxLoad(uint8_t page, JsonObject& jsonReply) { jsonReply["message"] = "Invalid or incomplete data received."; } } - diff --git a/espArtLeDNode/espArtLeDNode.ino b/espArtLeDNode/espArtLeDNode.ino index e124cfc..5cc9c84 100644 --- a/espArtLeDNode/espArtLeDNode.ino +++ b/espArtLeDNode/espArtLeDNode.ino @@ -30,7 +30,7 @@ extern "C" { extern struct rst_info resetInfo; } -#define FIRMWARE_VERSION "v1.0.2" +#define FIRMWARE_VERSION "v1.0.3-dev1" #define ART_FIRM_VERSION 0x0200 // Firmware given over Artnet (2 bytes) @@ -138,7 +138,9 @@ byte* dataIn; void setup(void) { //pinMode(4, OUTPUT); //digitalWrite(4, LOW); - + Serial.begin(74880); // to match bootloader baudrate + Serial.setDebugOutput(true); + //ESP.wdtEnable(3500);//enable SW WDT // Make direction input to avoid boot garbage being sent out pinMode(DMX_DIR_A, OUTPUT); digitalWrite(DMX_DIR_A, LOW); @@ -177,12 +179,12 @@ void setup(void) { SPIFFS.begin(); // Check if SPIFFS formatted - if (SPIFFS.exists("/formatted.txt")) { - SPIFFS.format(); + if (!SPIFFS.exists("/formatted.txt")) { // if formated.txt does not exits + SPIFFS.format(); // format the file system - File f = SPIFFS.open("/formatted.txt", "w"); - f.print("Formatted"); - f.close(); + File f = SPIFFS.open("/formatted.txt", "w"); // open new file formatted.txt + f.print("Formatted"); // write "Formatted into file + f.close(); // save file } // Load our saved values or store defaults @@ -190,23 +192,34 @@ void setup(void) { eepromLoad(); // Store our counters for resetting defaults - if (resetInfo.reason != REASON_DEFAULT_RST && resetInfo.reason != REASON_EXT_SYS_RST && resetInfo.reason != REASON_SOFT_RESTART) + /* if (resetInfo.reason != REASON_DEFAULT_RST && resetInfo.reason != REASON_EXT_SYS_RST && resetInfo.reason != REASON_SOFT_RESTART) deviceSettings.wdtCounter++; else deviceSettings.resetCounter++; + */ + + deviceSettings.wdtCounter = 0; + + deviceSettings.resetCounter =0; // Store values - eepromSave(); + // eepromSave(); // Start wifi wifiStart(); + + delay(10); // Start web server webStart(); - + switch (resetInfo.reason) { + case REASON_DEFAULT_RST: // normal start + case REASON_EXT_SYS_RST: + case REASON_SOFT_RESTART: + // Don't start our Artnet or DMX in firmware update mode or after multiple WDT resets - if (!deviceSettings.doFirmwareUpdate && deviceSettings.wdtCounter <= 3) { + if (!deviceSettings.doFirmwareUpdate) {// && deviceSettings.wdtCounter <= 3) { // We only allow 1 DMX input - and RDM can't run alongside DMX in if (deviceSettings.portAmode == TYPE_DMX_IN && deviceSettings.portBmode == TYPE_RDM_OUT) @@ -223,19 +236,37 @@ void setup(void) { portSetup(); } else - deviceSettings.doFirmwareUpdate = false; + deviceSettings.doFirmwareUpdate = false; + break; + + case REASON_WDT_RST: + break; + case REASON_EXCEPTION_RST: + break; + case REASON_SOFT_WDT_RST: + break; + case REASON_DEEP_SLEEP_AWAKE: + // not used + break; + } delay(10); } void loop(void){ // If the device lasts for 6 seconds, clear our reset timers - if (deviceSettings.resetCounter != 0 && millis() > 6000) { + /* if (deviceSettings.resetCounter != 0 && millis() > 6000) { deviceSettings.resetCounter = 0; deviceSettings.wdtCounter = 0; eepromSave(); } - + */ + //connect wifi if not connected + if (WiFi.status() != WL_CONNECTED) { + delay(1); + wifiStart(); + return; + } webServer.handleClient(); // Get the node details and handle Artnet @@ -296,7 +327,13 @@ void loop(void){ while (millis() < n) webServer.handleClient(); - ESP.restart(); + //eepromSave();//save settings before reboot + delay(10); + + WiFi.forceSleepBegin(); + wdt_reset(); + ESP.restart(); + while(1){wdt_reset();delay(10);} } #ifdef STATUS_LED_PIN @@ -587,4 +624,3 @@ void doStatusLedOutput() { void setStatusLed(uint8_t num, uint32_t col) { memcpy(&statusLedData[num*3], &col, 3); } - diff --git a/espArtLeDNode/startFunctions.ino b/espArtLeDNode/startFunctions.ino index 3e0b937..6576d1b 100644 --- a/espArtLeDNode/startFunctions.ino +++ b/espArtLeDNode/startFunctions.ino @@ -16,74 +16,74 @@ If not, see http://www.gnu.org/licenses/ void doNodeReport() { if (nextNodeReport > millis()) return; - + char c[ARTNET_NODE_REPORT_LENGTH]; if (nodeErrorTimeout > millis()) nextNodeReport = millis() + 2000; else nextNodeReport = millis() + 5000; - + if (nodeError[0] != '\0' && !nodeErrorShowing && nodeErrorTimeout > millis()) { - + nodeErrorShowing = true; strcpy(c, nodeError); - + } else { nodeErrorShowing = false; - + strcpy(c, "OK: PortA:"); switch (deviceSettings.portAmode) { case TYPE_DMX_OUT: sprintf(c, "%s DMX Out", c); break; - + case TYPE_RDM_OUT: sprintf(c, "%s RDM Out", c); break; - + case TYPE_DMX_IN: sprintf(c, "%s DMX In", c); break; - + case TYPE_WS2812: if (deviceSettings.portApixMode == FX_MODE_12) - sprintf(c, "%s 12chan", c); - sprintf(c, "%s WS2812 %ipixels", c, deviceSettings.portAnumPix); + sprintf(c, "%s 12chan", c); + sprintf(c, "%s WS2812 %ipixels", c, deviceSettings.portAnumPix); break; } - - #ifndef ONE_PORT - sprintf(c, "%s. PortB:", c); - - switch (deviceSettings.portBmode) { - case TYPE_DMX_OUT: - sprintf(c, "%s DMX Out", c); - break; - - case TYPE_RDM_OUT: - sprintf(c, "%s RDM Out", c); - break; - - case TYPE_WS2812: - if (deviceSettings.portBpixMode == FX_MODE_12) - sprintf(c, "%s 12chan", c); - sprintf(c, "%s WS2812 %ipixels", c, deviceSettings.portBnumPix); - break; - } - #endif + +#ifndef ONE_PORT + sprintf(c, "%s. PortB:", c); + + switch (deviceSettings.portBmode) { + case TYPE_DMX_OUT: + sprintf(c, "%s DMX Out", c); + break; + + case TYPE_RDM_OUT: + sprintf(c, "%s RDM Out", c); + break; + + case TYPE_WS2812: + if (deviceSettings.portBpixMode == FX_MODE_12) + sprintf(c, "%s 12chan", c); + sprintf(c, "%s WS2812 %ipixels", c, deviceSettings.portBnumPix); + break; + } +#endif } - + artRDM.setNodeReport(c, ARTNET_RC_POWER_OK); } void portSetup() { if (deviceSettings.portAmode == TYPE_DMX_OUT || deviceSettings.portAmode == TYPE_RDM_OUT) { - #ifndef ESP_01 - setStatusLed(STATUS_LED_A, BLUE); - #endif - +#ifndef ESP_01 + setStatusLed(STATUS_LED_A, BLUE); +#endif + dmxA.begin(DMX_DIR_A, artRDM.getDMX(portA[0], portA[1])); if (deviceSettings.portAmode == TYPE_RDM_OUT && !dmxA.rdmEnabled()) { dmxA.rdmEnable(ESTA_MAN, ESTA_DEV); @@ -92,10 +92,10 @@ void portSetup() { } } else if (deviceSettings.portAmode == TYPE_DMX_IN) { - #ifndef ESP_01 - setStatusLed(STATUS_LED_A, CYAN); - #endif - +#ifndef ESP_01 + setStatusLed(STATUS_LED_A, CYAN); +#endif + dmxA.begin(DMX_DIR_A, artRDM.getDMX(portA[0], portA[1])); dmxA.dmxIn(true); dmxA.setInputCallback(dmxIn); @@ -104,32 +104,32 @@ void portSetup() { memset(dataIn, 0, 512); } else if (deviceSettings.portAmode == TYPE_WS2812) { - #ifndef ESP_01 - setStatusLed(STATUS_LED_A, GREEN); - #endif - +#ifndef ESP_01 + setStatusLed(STATUS_LED_A, GREEN); +#endif + digitalWrite(DMX_DIR_A, HIGH); pixDriver.setStrip(0, DMX_TX_A, deviceSettings.portAnumPix, deviceSettings.portApixConfig); } - - #ifndef ONE_PORT - if (deviceSettings.portBmode == TYPE_DMX_OUT || deviceSettings.portBmode == TYPE_RDM_OUT) { - setStatusLed(STATUS_LED_B, BLUE); - - dmxB.begin(DMX_DIR_B, artRDM.getDMX(portB[0], portB[1])); - if (deviceSettings.portBmode == TYPE_RDM_OUT && !dmxB.rdmEnabled()) { - dmxB.rdmEnable(ESTA_MAN, ESTA_DEV); - dmxB.rdmSetCallBack(rdmReceivedB); - dmxB.todSetCallBack(sendTodB); - } - - } else if (deviceSettings.portBmode == TYPE_WS2812) { - setStatusLed(STATUS_LED_B, GREEN); - - digitalWrite(DMX_DIR_B, HIGH); - pixDriver.setStrip(1, DMX_TX_B, deviceSettings.portBnumPix, deviceSettings.portBpixConfig); + +#ifndef ONE_PORT + if (deviceSettings.portBmode == TYPE_DMX_OUT || deviceSettings.portBmode == TYPE_RDM_OUT) { + setStatusLed(STATUS_LED_B, BLUE); + + dmxB.begin(DMX_DIR_B, artRDM.getDMX(portB[0], portB[1])); + if (deviceSettings.portBmode == TYPE_RDM_OUT && !dmxB.rdmEnabled()) { + dmxB.rdmEnable(ESTA_MAN, ESTA_DEV); + dmxB.rdmSetCallBack(rdmReceivedB); + dmxB.todSetCallBack(sendTodB); } - #endif + + } else if (deviceSettings.portBmode == TYPE_WS2812) { + setStatusLed(STATUS_LED_B, GREEN); + + digitalWrite(DMX_DIR_B, HIGH); + pixDriver.setStrip(1, DMX_TX_B, deviceSettings.portBnumPix, deviceSettings.portBpixConfig); + } +#endif pixDriver.allowInterruptSingle = WS2812_ALLOW_INT_SINGLE; pixDriver.allowInterruptDouble = WS2812_ALLOW_INT_DOUBLE; @@ -147,7 +147,7 @@ void artStart() { // Add Group portA[0] = artRDM.addGroup(deviceSettings.portAnet, deviceSettings.portAsub); - + bool e131 = (deviceSettings.portAprot == PROT_ARTNET_SACN) ? true : false; // WS2812 uses TYPE_DMX_OUT - the rest use the value assigned @@ -158,66 +158,66 @@ void artStart() { artRDM.setE131(portA[0], portA[1], e131); artRDM.setE131Uni(portA[0], portA[1], deviceSettings.portAsACNuni[0]); - + // Add extra Artnet ports for WS2812 if (deviceSettings.portAmode == TYPE_WS2812 && deviceSettings.portApixMode == FX_MODE_PIXEL_MAP) { if (deviceSettings.portAnumPix > 170) { portA[2] = artRDM.addPort(portA[0], 1, deviceSettings.portAuni[1], TYPE_DMX_OUT, deviceSettings.portAmerge); - + artRDM.setE131(portA[0], portA[2], e131); artRDM.setE131Uni(portA[0], portA[2], deviceSettings.portAsACNuni[1]); } if (deviceSettings.portAnumPix > 340) { portA[3] = artRDM.addPort(portA[0], 2, deviceSettings.portAuni[2], TYPE_DMX_OUT, deviceSettings.portAmerge); - + artRDM.setE131(portA[0], portA[3], e131); artRDM.setE131Uni(portA[0], portA[3], deviceSettings.portAsACNuni[2]); } if (deviceSettings.portAnumPix > 510) { portA[4] = artRDM.addPort(portA[0], 3, deviceSettings.portAuni[3], TYPE_DMX_OUT, deviceSettings.portAmerge); - + artRDM.setE131(portA[0], portA[4], e131); artRDM.setE131Uni(portA[0], portA[4], deviceSettings.portAsACNuni[3]); } } - #ifndef ONE_PORT - // Add Group - portB[0] = artRDM.addGroup(deviceSettings.portBnet, deviceSettings.portBsub); - e131 = (deviceSettings.portBprot == PROT_ARTNET_SACN) ? true : false; - - // WS2812 uses TYPE_DMX_OUT - the rest use the value assigned - if (deviceSettings.portBmode == TYPE_WS2812) - portB[1] = artRDM.addPort(portB[0], 0, deviceSettings.portBuni[0], TYPE_DMX_OUT, deviceSettings.portBmerge); - else - portB[1] = artRDM.addPort(portB[0], 0, deviceSettings.portBuni[0], deviceSettings.portBmode, deviceSettings.portBmerge); - - artRDM.setE131(portB[0], portB[1], e131); - artRDM.setE131Uni(portB[0], portB[1], deviceSettings.portBsACNuni[0]); - - // Add extra Artnet ports for WS2812 - if (deviceSettings.portBmode == TYPE_WS2812 && deviceSettings.portBpixMode == FX_MODE_PIXEL_MAP) { - if (deviceSettings.portBnumPix > 170) { - portB[2] = artRDM.addPort(portB[0], 1, deviceSettings.portBuni[1], TYPE_DMX_OUT, deviceSettings.portBmerge); - - artRDM.setE131(portB[0], portB[2], e131); - artRDM.setE131Uni(portB[0], portB[2], deviceSettings.portBsACNuni[1]); - } - if (deviceSettings.portBnumPix > 340) { - portB[3] = artRDM.addPort(portB[0], 2, deviceSettings.portBuni[2], TYPE_DMX_OUT, deviceSettings.portBmerge); - - artRDM.setE131(portB[0], portB[3], e131); - artRDM.setE131Uni(portB[0], portB[3], deviceSettings.portBsACNuni[2]); - } - if (deviceSettings.portBnumPix > 510) { - portB[4] = artRDM.addPort(portB[0], 3, deviceSettings.portBuni[3], TYPE_DMX_OUT, deviceSettings.portBmerge); - - artRDM.setE131(portB[0], portB[4], e131); - artRDM.setE131Uni(portB[0], portB[4], deviceSettings.portBsACNuni[3]); - } +#ifndef ONE_PORT + // Add Group + portB[0] = artRDM.addGroup(deviceSettings.portBnet, deviceSettings.portBsub); + e131 = (deviceSettings.portBprot == PROT_ARTNET_SACN) ? true : false; + + // WS2812 uses TYPE_DMX_OUT - the rest use the value assigned + if (deviceSettings.portBmode == TYPE_WS2812) + portB[1] = artRDM.addPort(portB[0], 0, deviceSettings.portBuni[0], TYPE_DMX_OUT, deviceSettings.portBmerge); + else + portB[1] = artRDM.addPort(portB[0], 0, deviceSettings.portBuni[0], deviceSettings.portBmode, deviceSettings.portBmerge); + + artRDM.setE131(portB[0], portB[1], e131); + artRDM.setE131Uni(portB[0], portB[1], deviceSettings.portBsACNuni[0]); + + // Add extra Artnet ports for WS2812 + if (deviceSettings.portBmode == TYPE_WS2812 && deviceSettings.portBpixMode == FX_MODE_PIXEL_MAP) { + if (deviceSettings.portBnumPix > 170) { + portB[2] = artRDM.addPort(portB[0], 1, deviceSettings.portBuni[1], TYPE_DMX_OUT, deviceSettings.portBmerge); + + artRDM.setE131(portB[0], portB[2], e131); + artRDM.setE131Uni(portB[0], portB[2], deviceSettings.portBsACNuni[1]); } - #endif + if (deviceSettings.portBnumPix > 340) { + portB[3] = artRDM.addPort(portB[0], 2, deviceSettings.portBuni[2], TYPE_DMX_OUT, deviceSettings.portBmerge); + + artRDM.setE131(portB[0], portB[3], e131); + artRDM.setE131Uni(portB[0], portB[3], deviceSettings.portBsACNuni[2]); + } + if (deviceSettings.portBnumPix > 510) { + portB[4] = artRDM.addPort(portB[0], 3, deviceSettings.portBuni[3], TYPE_DMX_OUT, deviceSettings.portBmerge); + + artRDM.setE131(portB[0], portB[4], e131); + artRDM.setE131Uni(portB[0], portB[4], deviceSettings.portBsACNuni[3]); + } + } +#endif // Add required callback functions artRDM.setArtDMXCallback(dmxHandle); @@ -236,7 +236,7 @@ void artStart() { artRDM.setNodeReport("OK: Device started", ARTNET_RC_POWER_OK); nextNodeReport = millis() + 4000; break; - + case REASON_WDT_RST: artRDM.setNodeReport("ERROR: (HWDT) Unexpected device restart", ARTNET_RC_POWER_FAIL); strcpy(nodeError, "Restart error: HWDT"); @@ -259,7 +259,7 @@ void artStart() { // not used break; } - + // Start artnet artRDM.begin(); @@ -267,15 +267,15 @@ void artStart() { } void webStart() { - webServer.on("/", [](){ + webServer.on("/", []() { artRDM.pause(); webServer.send_P(200, typeHTML, mainPage); webServer.sendHeader("Connection", "close"); yield(); artRDM.begin(); }); - - webServer.on("/style.css", [](){ + + webServer.on("/style.css", []() { artRDM.pause(); File f = SPIFFS.open("/style.css", "r"); @@ -285,62 +285,62 @@ void webStart() { webServer.send_P(200, typeCSS, css); else size_t sent = webServer.streamFile(f, typeCSS); - + f.close(); webServer.sendHeader("Connection", "close"); - + yield(); artRDM.begin(); }); - + webServer.on("/ajax", HTTP_POST, ajaxHandle); - + webServer.on("/upload", HTTP_POST, webFirmwareUpdate, webFirmwareUpload); - webServer.on("/style", [](){ + webServer.on("/style", []() { webServer.send_P(200, typeHTML, cssUploadPage); webServer.sendHeader("Connection", "close"); }); - - webServer.on("/style_delete", [](){ + + webServer.on("/style_delete", []() { if (SPIFFS.exists("/style.css")) SPIFFS.remove("/style.css"); - + webServer.send(200, "text/plain", "style.css deleted. The default style is now in use."); webServer.sendHeader("Connection", "close"); }); - webServer.on("/style_upload", HTTP_POST, [](){ + webServer.on("/style_upload", HTTP_POST, []() { webServer.send(200, "text/plain", "Upload successful!"); - }, [](){ + }, []() { HTTPUpload& upload = webServer.upload(); - - if(upload.status == UPLOAD_FILE_START){ + + if (upload.status == UPLOAD_FILE_START) { String filename = upload.filename; - if(!filename.startsWith("/")) filename = "/"+filename; + if (!filename.startsWith("/")) filename = "/" + filename; fsUploadFile = SPIFFS.open(filename, "w"); filename = String(); - - } else if(upload.status == UPLOAD_FILE_WRITE){ - if(fsUploadFile) + + } else if (upload.status == UPLOAD_FILE_WRITE) { + if (fsUploadFile) fsUploadFile.write(upload.buf, upload.currentSize); - - } else if(upload.status == UPLOAD_FILE_END){ - if(fsUploadFile) { + + } else if (upload.status == UPLOAD_FILE_END) { + if (fsUploadFile) { fsUploadFile.close(); - + if (upload.filename != "/style.css") SPIFFS.rename(upload.filename, "/style.css"); } } }); - + webServer.onNotFound([]() { webServer.send(404, "text/plain", "Page not found"); }); - + webServer.begin(); - + yield(); } @@ -348,37 +348,59 @@ void wifiStart() { // If it's the default WiFi SSID, make it unique if (strcmp(deviceSettings.hotspotSSID, "espArtNetNode") == 0 || deviceSettings.hotspotSSID[0] == '\0') sprintf(deviceSettings.hotspotSSID, "espArtNetNode_%05u", (ESP.getChipId() & 0xFF)); - + if (deviceSettings.standAloneEnable) { startHotspot(); deviceSettings.ip = deviceSettings.hotspotIp; deviceSettings.subnet = deviceSettings.hotspotSubnet; deviceSettings.broadcast = {~deviceSettings.subnet[0] | (deviceSettings.ip[0] & deviceSettings.subnet[0]), ~deviceSettings.subnet[1] | (deviceSettings.ip[1] & deviceSettings.subnet[1]), ~deviceSettings.subnet[2] | (deviceSettings.ip[2] & deviceSettings.subnet[2]), ~deviceSettings.subnet[3] | (deviceSettings.ip[3] & deviceSettings.subnet[3])}; - + return; } - + if (deviceSettings.wifiSSID[0] != '\0') { - WiFi.begin(deviceSettings.wifiSSID, deviceSettings.wifiPass); - WiFi.mode(WIFI_STA); - WiFi.hostname(deviceSettings.nodeName); + // Bring up the WiFi connection + WiFi.mode( WIFI_STA ); + WiFi.persistent( false );//prevent excesive writing to flash + //WiFi.setOutputPower(17); + WiFi.setAutoConnect(true); + WiFi.setAutoReconnect(true); + WiFi.hostname(deviceSettings.nodeName); + WiFi.begin(deviceSettings.wifiSSID, deviceSettings.wifiPass); + unsigned long endTime = millis() + (deviceSettings.hotspotDelay * 1000); + while (WiFi.status() != WL_CONNECTED) { + // Check to see if + if (WiFi.status() == WL_CONNECT_FAILED) { + // Serial.println("Failed to connect to WiFi. Please verify credentials: "); + // delay(1000); + startHotspot(); + } + delay(100); + // Serial.print("."); + //delay(500); + //// Serial.println("..."); + // Only try for 5 seconds. + if (millis() >= endTime) { + // Serial.println("Failed to connect to WiFi"); + startHotspot(); + return; + } + } + + + if (deviceSettings.dhcpEnable) { - while (WiFi.status() != WL_CONNECTED && endTime > millis()) - yield(); - if (millis() >= endTime) - startHotspot(); - deviceSettings.ip = WiFi.localIP(); deviceSettings.subnet = WiFi.subnetMask(); if (deviceSettings.gateway == INADDR_NONE) deviceSettings.gateway = WiFi.gatewayIP(); - + deviceSettings.broadcast = {~deviceSettings.subnet[0] | (deviceSettings.ip[0] & deviceSettings.subnet[0]), ~deviceSettings.subnet[1] | (deviceSettings.ip[1] & deviceSettings.subnet[1]), ~deviceSettings.subnet[2] | (deviceSettings.ip[2] & deviceSettings.subnet[2]), ~deviceSettings.subnet[3] | (deviceSettings.ip[3] & deviceSettings.subnet[3])}; } else WiFi.config(deviceSettings.ip, deviceSettings.gateway, deviceSettings.subnet); @@ -386,16 +408,16 @@ void wifiStart() { //sprintf(wifiStatus, "Wifi connected. Signal: %ld
SSID: %s", WiFi.RSSI(), deviceSettings.wifiSSID); sprintf(wifiStatus, "Wifi connected.
SSID: %s", deviceSettings.wifiSSID); WiFi.macAddress(MAC_array); - + } else startHotspot(); - + yield(); } void startHotspot() { yield(); - + WiFi.mode(WIFI_AP); WiFi.softAP(deviceSettings.hotspotSSID, deviceSettings.hotspotPass); WiFi.softAPConfig(deviceSettings.hotspotIp, deviceSettings.hotspotIp, deviceSettings.hotspotSubnet); @@ -404,20 +426,22 @@ void startHotspot() { WiFi.macAddress(MAC_array); isHotspot = true; - + if (deviceSettings.standAloneEnable) return; - + webStart(); unsigned long endTime = millis() + 30000; // Stay here if not in stand alone mode - no dmx or artnet - while (endTime > millis() || wifi_softap_get_station_num() > 0) { + //while (endTime > millis() || wifi_softap_get_station_num() > 0) { // if 30 seconds has passed or client connected + while (true){ webServer.handleClient(); - yield(); + //yield(); + delay(1); } - ESP.restart(); - isHotspot = false; + //ESP.restart(); + //isHotspot = false; } diff --git a/espArtLeDNode/store.h b/espArtLeDNode/store.h index 268c9fb..fd5297c 100644 --- a/espArtLeDNode/store.h +++ b/espArtLeDNode/store.h @@ -79,42 +79,54 @@ struct StoreStruct { void eepromSave() { for (uint16_t t = 0; t < sizeof(deviceSettings); t++) EEPROM.write(CONFIG_START + t, *((char*)&deviceSettings + t)); - - EEPROM.commit(); + Serial.println("save"); + Serial.println(deviceSettings.wifiSSID); + Serial.println(deviceSettings.wifiPass); + + EEPROM.commit(); } void eepromLoad() { + + // Store defaults for if we need them + StoreStruct tmpStore; + tmpStore = deviceSettings; + // To make sure there are settings, and they are YOURS! // If nothing is found it will use the default settings. if (EEPROM.read(CONFIG_START + 0) == CONFIG_VERSION[0] && EEPROM.read(CONFIG_START + 1) == CONFIG_VERSION[1] && EEPROM.read(CONFIG_START + 2) == CONFIG_VERSION[2]) { - // Store defaults for if we need them - StoreStruct tmpStore; - tmpStore = deviceSettings; - // Copy data to deviceSettings structure for (uint16_t t = 0; t < sizeof(deviceSettings); t++) *((char*)&deviceSettings + t) = EEPROM.read(CONFIG_START + t); - + + Serial.println("load+"); + Serial.println(deviceSettings.wifiSSID); + Serial.println(deviceSettings.wifiPass); + // If we want to restore all our settings - if (deviceSettings.resetCounter >= 5 || deviceSettings.wdtCounter >= 10) { + /* + if (deviceSettings.resetCounter >= 5 ){//|| deviceSettings.wdtCounter >= 10) { deviceSettings.wdtCounter = 0; deviceSettings.resetCounter = 0; // Store defaults back into main settings deviceSettings = tmpStore; } - + */ // If config files dont match, save defaults then erase the ESP config to clear away any residue } else { + deviceSettings = tmpStore; eepromSave(); delay(500); - + WiFi.persistent(false); ESP.eraseConfig(); - while(1); + WiFi.disconnect(); + ESP.restart(); + // while(1); + } } - diff --git a/espArtLeDNode/ws2812Driver.cpp b/espArtLeDNode/ws2812Driver.cpp index 689f1ff..e7feb59 100644 --- a/espArtLeDNode/ws2812Driver.cpp +++ b/espArtLeDNode/ws2812Driver.cpp @@ -169,7 +169,7 @@ void ICACHE_RAM_ATTR ws2812Driver::doPixel(byte* data, uint8_t pin, uint16_t num "MEMW;" "RSR %[r_cc1], CCOUNT;" // get clock cycles - "ADDI %[r_cc1], %[r_cc1], 95;" // add to cycles for delay - works at 100 + "ADDI %[r_cc1], %[r_cc1], 100;" // add to cycles for delay - works at 100 "SingleOneLoop:" "RSR %[r_cc2], CCOUNT;" // Get clock cycles @@ -179,7 +179,7 @@ void ICACHE_RAM_ATTR ws2812Driver::doPixel(byte* data, uint8_t pin, uint16_t num "MEMW;" "RSR %[r_cc1], CCOUNT;" // get clock cycles - "ADDI %[r_cc1], %[r_cc1], 61;" // add to cycles for delay - works at 67 + "ADDI %[r_cc1], %[r_cc1], 84;" // add to cycles for delay - works at 67 "BEQZ %[r_allow_int], SingleLoop;" // if allowInt equals false, jump without enabling interrupts "RSIL %[r_int], 0;" // enable interrupts again "NOP;" // 1 clock for any interrupts to run @@ -193,7 +193,7 @@ void ICACHE_RAM_ATTR ws2812Driver::doPixel(byte* data, uint8_t pin, uint16_t num "MEMW;" "RSR %[r_cc1], CCOUNT;" // get clock cycles - "ADDI %[r_cc1], %[r_cc1], 40;" // add to cycles for delay - works at 50 + "ADDI %[r_cc1], %[r_cc1], 44;" // add to cycles for delay - works at 50 "SingleZeroLoop:" "RSR %[r_cc2], CCOUNT;" // Get clock cycles @@ -203,7 +203,7 @@ void ICACHE_RAM_ATTR ws2812Driver::doPixel(byte* data, uint8_t pin, uint16_t num "MEMW;" "RSR %[r_cc1], CCOUNT;" // get clock cycles - "ADDI %[r_cc1], %[r_cc1], 85;" // add to cycles for delay - works at 105 + "ADDI %[r_cc1], %[r_cc1], 116;" // add to cycles for delay - works at 105 "BEQZ %[r_allow_int], SingleLoop;" // if allowInt equals false, jump without enabling interrupts "RSIL %[r_int], 0;" // enable interrupts again "NOP;" // 1 clock for any interrupts to run From c9fad3055025389c810114b89cd42401245186ae Mon Sep 17 00:00:00 2001 From: Nils Bernhardt Date: Sat, 3 Mar 2018 22:12:50 +0100 Subject: [PATCH 02/23] Typo fix --- espArtLeDNode/wsFX.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/espArtLeDNode/wsFX.cpp b/espArtLeDNode/wsFX.cpp index 5b036e7..5a3feb9 100644 --- a/espArtLeDNode/wsFX.cpp +++ b/espArtLeDNode/wsFX.cpp @@ -1,5 +1,5 @@ /* -ESP8266_LED-DMX-ArtNetNode +ESP8266_ArtNet-LED-DMX-Node https://github.com/bombcheck/ESP8266_LED-DMX-ArtNetNode This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public From 42e3a79e6ac8e4ea4f6f891fd630a1e85c473725 Mon Sep 17 00:00:00 2001 From: Nils Bernhardt Date: Sat, 3 Mar 2018 22:44:12 +0100 Subject: [PATCH 03/23] Updated Readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d1c636b..c3373b1 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ Check the 'release'-section for the latest ready-to-flash-binaries. Download and - You need the latest ESP8266 Arduino Core files and the latest Arduino IDE version. - Make sure you placed the libraries from this project into your Arduino libraries folder. - Select the proper board. For me it is a "NodeMCU 1.0 (ESP-12E Module)". - - Make sure to compile with a CPU Frequency of 160 MHz! + - Make sure to compile with a CPU Frequency of 160 MHz and IwIP v1.4! ### First Boot On your first boot, the device will start a hotspot called "espArtLeDNode" with a password of "espArtLeDNode" (case sensitive). Login to the hotspot and goto http://10.0.17.1 in a web browser. From 0f481240db3af7900beeb1e9d16997a51102ccfe Mon Sep 17 00:00:00 2001 From: Nils Bernhardt Date: Sun, 4 Mar 2018 09:28:58 +0100 Subject: [PATCH 04/23] Fixed unique setup-wifi ssid & changed DMX_DIR_A-Pin for ESP01 --- espArtLeDNode/espArtLeDNode.ino | 2 +- espArtLeDNode/startFunctions.ino | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/espArtLeDNode/espArtLeDNode.ino b/espArtLeDNode/espArtLeDNode.ino index 5cc9c84..1d77a5d 100644 --- a/espArtLeDNode/espArtLeDNode.ino +++ b/espArtLeDNode/espArtLeDNode.ino @@ -48,7 +48,7 @@ extern "C" { #ifdef ESP_01 - #define DMX_DIR_A 2 // Same pin as TX1 + #define DMX_DIR_A 3 #define DMX_TX_A 1 #define ONE_PORT #define NO_RESET diff --git a/espArtLeDNode/startFunctions.ino b/espArtLeDNode/startFunctions.ino index 6576d1b..65c128a 100644 --- a/espArtLeDNode/startFunctions.ino +++ b/espArtLeDNode/startFunctions.ino @@ -346,8 +346,8 @@ void webStart() { void wifiStart() { // If it's the default WiFi SSID, make it unique - if (strcmp(deviceSettings.hotspotSSID, "espArtNetNode") == 0 || deviceSettings.hotspotSSID[0] == '\0') - sprintf(deviceSettings.hotspotSSID, "espArtNetNode_%05u", (ESP.getChipId() & 0xFF)); + if (strcmp(deviceSettings.hotspotSSID, "espArtLeDNode") == 0 || deviceSettings.hotspotSSID[0] == '\0') + sprintf(deviceSettings.hotspotSSID, "espArtLeDNode_%05u", (ESP.getChipId() & 0xFF)); if (deviceSettings.standAloneEnable) { startHotspot(); From 1fee23a076134288da54616449805f86f5d81bb4 Mon Sep 17 00:00:00 2001 From: Nils Bernhardt Date: Sun, 4 Mar 2018 09:45:54 +0100 Subject: [PATCH 05/23] Changed DMX_DIR_A-Pin for ESP01 --- espArtLeDNode/espArtLeDNode.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/espArtLeDNode/espArtLeDNode.ino b/espArtLeDNode/espArtLeDNode.ino index 1d77a5d..28b7048 100644 --- a/espArtLeDNode/espArtLeDNode.ino +++ b/espArtLeDNode/espArtLeDNode.ino @@ -48,7 +48,7 @@ extern "C" { #ifdef ESP_01 - #define DMX_DIR_A 3 + #define DMX_DIR_A 5 #define DMX_TX_A 1 #define ONE_PORT #define NO_RESET From 27afc923285468195a0b256605147b9643545fbd Mon Sep 17 00:00:00 2001 From: Nils Bernhardt Date: Sun, 4 Mar 2018 09:48:35 +0100 Subject: [PATCH 06/23] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c3373b1..d1c636b 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ Check the 'release'-section for the latest ready-to-flash-binaries. Download and - You need the latest ESP8266 Arduino Core files and the latest Arduino IDE version. - Make sure you placed the libraries from this project into your Arduino libraries folder. - Select the proper board. For me it is a "NodeMCU 1.0 (ESP-12E Module)". - - Make sure to compile with a CPU Frequency of 160 MHz and IwIP v1.4! + - Make sure to compile with a CPU Frequency of 160 MHz! ### First Boot On your first boot, the device will start a hotspot called "espArtLeDNode" with a password of "espArtLeDNode" (case sensitive). Login to the hotspot and goto http://10.0.17.1 in a web browser. From 815e45f03b13ddb0ec559218280c16d901d4a5dd Mon Sep 17 00:00:00 2001 From: Nils Bernhardt Date: Sun, 4 Mar 2018 10:59:53 +0100 Subject: [PATCH 07/23] Reverted changes ESP01 pinout --- espArtLeDNode/espArtLeDNode.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/espArtLeDNode/espArtLeDNode.ino b/espArtLeDNode/espArtLeDNode.ino index 28b7048..cc2ba72 100644 --- a/espArtLeDNode/espArtLeDNode.ino +++ b/espArtLeDNode/espArtLeDNode.ino @@ -30,7 +30,7 @@ extern "C" { extern struct rst_info resetInfo; } -#define FIRMWARE_VERSION "v1.0.3-dev1" +#define FIRMWARE_VERSION "v1.0.3-dev2" #define ART_FIRM_VERSION 0x0200 // Firmware given over Artnet (2 bytes) @@ -48,7 +48,7 @@ extern "C" { #ifdef ESP_01 - #define DMX_DIR_A 5 + #define DMX_DIR_A 2 #define DMX_TX_A 1 #define ONE_PORT #define NO_RESET From 2fae7175447ab8c60136e965ff4b18aeeeabd66d Mon Sep 17 00:00:00 2001 From: Nils Bernhardt Date: Sun, 4 Mar 2018 22:15:25 +0100 Subject: [PATCH 08/23] Changed defaults --- espArtLeDNode/store.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/espArtLeDNode/store.h b/espArtLeDNode/store.h index fd5297c..f3b753d 100644 --- a/espArtLeDNode/store.h +++ b/espArtLeDNode/store.h @@ -67,7 +67,7 @@ struct StoreStruct { "espArtLeDNode", "espArtLeDNode by Bombcheck", "", "", "espArtLeDNode", "espArtLeDNode", 15, TYPE_WS2812, TYPE_DMX_OUT, PROT_ARTNET, PROT_ARTNET, MERGE_HTP, MERGE_HTP, - 1, 1, {0, 1, 2, 3}, 0, 0, {4, 5, 6, 7}, {1, 2, 3, 4}, {5, 6, 7, 8}, + 0, 0, {0, 1, 2, 3}, 0, 0, {4, 5, 6, 7}, {1, 2, 3, 4}, {5, 6, 7, 8}, 680, 680, 0, 0, false, FX_MODE_PIXEL_MAP, FX_MODE_PIXEL_MAP, From 5b1acffe60edce105ac352662ace2cae280ff4b4 Mon Sep 17 00:00:00 2001 From: Nils Bernhardt Date: Mon, 5 Mar 2018 14:53:05 +0100 Subject: [PATCH 09/23] Re-enabled WDT --- README.md | 6 +----- espArtLeDNode/espArtLeDNode.ino | 6 ++---- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index d1c636b..6c5d659 100644 --- a/README.md +++ b/README.md @@ -28,11 +28,7 @@ In the Wifi tab, enter your SSID and password. Click save (it should go green a If the device can't connect to the wifi or get a DHCP assigned address within (Start Delay) seconds, it will start the hotspot and wait for 30 seconds for you to connect. If a client doesn't connect to the hotspot in time, the device will restart and try again. ### Restore Factory Defaults -I have allowed for 2 methods to restore the factory default settings: using a dedicated factory reset button on GPIO14 or multiple power cycles. - -Method 1: Hold GPIO14 to GND while the device boots. - -Method 2: Allow the esp8266 about 1-4 seconds to start, then reset it (or power cycle). Do this at least 5 times to restore factory default settings. +Hold GPIO14 to GND while the device boots. ## Features - sACN and ArtNet V4 support diff --git a/espArtLeDNode/espArtLeDNode.ino b/espArtLeDNode/espArtLeDNode.ino index cc2ba72..58d3720 100644 --- a/espArtLeDNode/espArtLeDNode.ino +++ b/espArtLeDNode/espArtLeDNode.ino @@ -30,7 +30,7 @@ extern "C" { extern struct rst_info resetInfo; } -#define FIRMWARE_VERSION "v1.0.3-dev2" +#define FIRMWARE_VERSION "v1.0.3-dev3" #define ART_FIRM_VERSION 0x0200 // Firmware given over Artnet (2 bytes) @@ -39,7 +39,6 @@ extern "C" { // Wemos boards use 4M (3M SPIFFS) compiler option - #define ARTNET_OEM 0x0123 // Artnet OEM Code #define ESTA_MAN 0x08DD // ESTA Manufacturer Code #define ESTA_DEV 0xEE000000 // RDM Device ID (used with Man Code to make 48bit UID) @@ -77,7 +76,6 @@ extern "C" { #define SETTINGS_RESET 14 #endif - // Definitions for status leds xxBBRRGG #define BLACK 0x00000000 #define WHITE 0x00FFFFFF @@ -140,7 +138,7 @@ void setup(void) { //digitalWrite(4, LOW); Serial.begin(74880); // to match bootloader baudrate Serial.setDebugOutput(true); - //ESP.wdtEnable(3500);//enable SW WDT + ESP.wdtEnable(3500);//enable SW WDT // Make direction input to avoid boot garbage being sent out pinMode(DMX_DIR_A, OUTPUT); digitalWrite(DMX_DIR_A, LOW); From 4205ce4fd15b80fd75dc04c310b1a6106dcc4fed Mon Sep 17 00:00:00 2001 From: Nils Bernhardt Date: Mon, 5 Mar 2018 15:29:30 +0100 Subject: [PATCH 10/23] WDT is enabled by default --- espArtLeDNode/espArtLeDNode.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/espArtLeDNode/espArtLeDNode.ino b/espArtLeDNode/espArtLeDNode.ino index 58d3720..30e0f94 100644 --- a/espArtLeDNode/espArtLeDNode.ino +++ b/espArtLeDNode/espArtLeDNode.ino @@ -136,9 +136,9 @@ byte* dataIn; void setup(void) { //pinMode(4, OUTPUT); //digitalWrite(4, LOW); - Serial.begin(74880); // to match bootloader baudrate + Serial.begin(115200); // to match bootloader baudrate Serial.setDebugOutput(true); - ESP.wdtEnable(3500);//enable SW WDT + //ESP.wdtEnable(3500);//enable SW WDT // Make direction input to avoid boot garbage being sent out pinMode(DMX_DIR_A, OUTPUT); digitalWrite(DMX_DIR_A, LOW); From d88582123c76a49bd0acfac830b660676001215b Mon Sep 17 00:00:00 2001 From: Nils Bernhardt Date: Mon, 5 Mar 2018 15:59:34 +0100 Subject: [PATCH 11/23] Poking around --- espArtLeDNode/espArtLeDNode.ino | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/espArtLeDNode/espArtLeDNode.ino b/espArtLeDNode/espArtLeDNode.ino index 30e0f94..b9f4ea2 100644 --- a/espArtLeDNode/espArtLeDNode.ino +++ b/espArtLeDNode/espArtLeDNode.ino @@ -136,7 +136,7 @@ byte* dataIn; void setup(void) { //pinMode(4, OUTPUT); //digitalWrite(4, LOW); - Serial.begin(115200); // to match bootloader baudrate + Serial.begin(74880); // to match bootloader baudrate Serial.setDebugOutput(true); //ESP.wdtEnable(3500);//enable SW WDT // Make direction input to avoid boot garbage being sent out @@ -197,7 +197,6 @@ void setup(void) { */ deviceSettings.wdtCounter = 0; - deviceSettings.resetCounter =0; // Store values From 3d01c3a60cfac5b3f2b8c2036c214f75d567db9b Mon Sep 17 00:00:00 2001 From: Nils Bernhardt Date: Tue, 6 Mar 2018 13:16:04 +0100 Subject: [PATCH 12/23] Feeding watchdog & resetting ESP explicitly when crashed --- espArtLeDNode/espArtLeDNode.ino | 55 ++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 25 deletions(-) diff --git a/espArtLeDNode/espArtLeDNode.ino b/espArtLeDNode/espArtLeDNode.ino index b9f4ea2..7231cca 100644 --- a/espArtLeDNode/espArtLeDNode.ino +++ b/espArtLeDNode/espArtLeDNode.ino @@ -30,7 +30,7 @@ extern "C" { extern struct rst_info resetInfo; } -#define FIRMWARE_VERSION "v1.0.3-dev3" +#define FIRMWARE_VERSION "v1.0.3-dev10" #define ART_FIRM_VERSION 0x0200 // Firmware given over Artnet (2 bytes) @@ -138,7 +138,8 @@ void setup(void) { //digitalWrite(4, LOW); Serial.begin(74880); // to match bootloader baudrate Serial.setDebugOutput(true); - //ESP.wdtEnable(3500);//enable SW WDT + ESP.wdtEnable(WDTO_8S); //enable SW WDT with 8s timeout + // Make direction input to avoid boot garbage being sent out pinMode(DMX_DIR_A, OUTPUT); digitalWrite(DMX_DIR_A, LOW); @@ -211,36 +212,36 @@ void setup(void) { webStart(); switch (resetInfo.reason) { - case REASON_DEFAULT_RST: // normal start - case REASON_EXT_SYS_RST: - case REASON_SOFT_RESTART: + case REASON_DEFAULT_RST: // normal startup by power on + case REASON_EXT_SYS_RST: // external system reset + case REASON_SOFT_RESTART: // software restart ,system_restart , GPIO status won’t change - // Don't start our Artnet or DMX in firmware update mode or after multiple WDT resets - if (!deviceSettings.doFirmwareUpdate) {// && deviceSettings.wdtCounter <= 3) { + // Don't start our Artnet or DMX in firmware update mode or after multiple WDT resets + if (!deviceSettings.doFirmwareUpdate) {// && deviceSettings.wdtCounter <= 3) { - // We only allow 1 DMX input - and RDM can't run alongside DMX in - if (deviceSettings.portAmode == TYPE_DMX_IN && deviceSettings.portBmode == TYPE_RDM_OUT) - deviceSettings.portBmode = TYPE_DMX_OUT; + // We only allow 1 DMX input - and RDM can't run alongside DMX in + if (deviceSettings.portAmode == TYPE_DMX_IN && deviceSettings.portBmode == TYPE_RDM_OUT) + deviceSettings.portBmode = TYPE_DMX_OUT; - // Setup Artnet Ports & Callbacks - artStart(); + // Setup Artnet Ports & Callbacks + artStart(); - // Don't open any ports for a bit to let the ESP spill it's garbage to serial - while (millis() < 3500) - yield(); + // Don't open any ports for a bit to let the ESP spill it's garbage to serial + while (millis() < 3500) + yield(); - // Port Setup - portSetup(); + // Port Setup + portSetup(); - } else - deviceSettings.doFirmwareUpdate = false; - break; + } else { + deviceSettings.doFirmwareUpdate = false; + } + break; - case REASON_WDT_RST: - break; - case REASON_EXCEPTION_RST: - break; - case REASON_SOFT_WDT_RST: + case REASON_WDT_RST: // hardware watch dog reset + case REASON_EXCEPTION_RST: // exception reset, GPIO status won’t change + case REASON_SOFT_WDT_RST: // software watch dog reset, GPIO status won’t change + ESP.reset(); break; case REASON_DEEP_SLEEP_AWAKE: // not used @@ -251,6 +252,9 @@ void setup(void) { } void loop(void){ + // Feed the watchdog + ESP.wdtFeed(); + // If the device lasts for 6 seconds, clear our reset timers /* if (deviceSettings.resetCounter != 0 && millis() > 6000) { deviceSettings.resetCounter = 0; @@ -262,6 +266,7 @@ void loop(void){ if (WiFi.status() != WL_CONNECTED) { delay(1); wifiStart(); + ESP.wdtFeed(); return; } webServer.handleClient(); From 112e0a321326f51d3d5a17e5d5a33b721db8b9a6 Mon Sep 17 00:00:00 2001 From: Nils Bernhardt Date: Tue, 6 Mar 2018 15:11:50 +0100 Subject: [PATCH 13/23] Timing adjustments & check wifi connection every 5s --- espArtLeDNode/espArtLeDNode.ino | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/espArtLeDNode/espArtLeDNode.ino b/espArtLeDNode/espArtLeDNode.ino index 7231cca..c4720db 100644 --- a/espArtLeDNode/espArtLeDNode.ino +++ b/espArtLeDNode/espArtLeDNode.ino @@ -30,7 +30,7 @@ extern "C" { extern struct rst_info resetInfo; } -#define FIRMWARE_VERSION "v1.0.3-dev10" +#define FIRMWARE_VERSION "v1.0.3-dev13" #define ART_FIRM_VERSION 0x0200 // Firmware given over Artnet (2 bytes) @@ -94,6 +94,7 @@ uint8_t MAC_array[6]; uint8_t dmxInSeqID = 0; uint8_t statusLedData[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0}; uint32_t statusTimer = 0; +uint32_t wifiCheckTimer = 0; esp8266ArtNetRDM artRDM; ESP8266WebServer webServer(80); @@ -241,7 +242,7 @@ void setup(void) { case REASON_WDT_RST: // hardware watch dog reset case REASON_EXCEPTION_RST: // exception reset, GPIO status won’t change case REASON_SOFT_WDT_RST: // software watch dog reset, GPIO status won’t change - ESP.reset(); + ESP.restart(); break; case REASON_DEEP_SLEEP_AWAKE: // not used @@ -262,14 +263,19 @@ void loop(void){ eepromSave(); } */ - //connect wifi if not connected - if (WiFi.status() != WL_CONNECTED) { - delay(1); - wifiStart(); - ESP.wdtFeed(); - return; + //connect wifi if not connected (check every 5 seconds) + if (wifiCheckTimer < millis()) { + if (WiFi.status() != WL_CONNECTED) { + delay(1); + wifiStart(); + ESP.wdtFeed(); + return; + } + wifiCheckTimer = millis() + 5000; } webServer.handleClient(); + + delay(7); // Get the node details and handle Artnet doNodeReport(); From d4ea4429e2d16506e1d64f7b7d585a72aa6e6ab3 Mon Sep 17 00:00:00 2001 From: Nils Bernhardt Date: Tue, 6 Mar 2018 15:16:25 +0100 Subject: [PATCH 14/23] Removed serial printout --- espArtLeDNode/espArtLeDNode.ino | 6 +++--- espArtLeDNode/store.h | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/espArtLeDNode/espArtLeDNode.ino b/espArtLeDNode/espArtLeDNode.ino index c4720db..ba63af3 100644 --- a/espArtLeDNode/espArtLeDNode.ino +++ b/espArtLeDNode/espArtLeDNode.ino @@ -30,7 +30,7 @@ extern "C" { extern struct rst_info resetInfo; } -#define FIRMWARE_VERSION "v1.0.3-dev13" +#define FIRMWARE_VERSION "v1.0.3-dev14" #define ART_FIRM_VERSION 0x0200 // Firmware given over Artnet (2 bytes) @@ -137,8 +137,8 @@ byte* dataIn; void setup(void) { //pinMode(4, OUTPUT); //digitalWrite(4, LOW); - Serial.begin(74880); // to match bootloader baudrate - Serial.setDebugOutput(true); + //Serial.begin(74880); // to match bootloader baudrate + //Serial.setDebugOutput(true); ESP.wdtEnable(WDTO_8S); //enable SW WDT with 8s timeout // Make direction input to avoid boot garbage being sent out diff --git a/espArtLeDNode/store.h b/espArtLeDNode/store.h index f3b753d..78453d7 100644 --- a/espArtLeDNode/store.h +++ b/espArtLeDNode/store.h @@ -79,9 +79,9 @@ struct StoreStruct { void eepromSave() { for (uint16_t t = 0; t < sizeof(deviceSettings); t++) EEPROM.write(CONFIG_START + t, *((char*)&deviceSettings + t)); - Serial.println("save"); - Serial.println(deviceSettings.wifiSSID); - Serial.println(deviceSettings.wifiPass); + //Serial.println("save"); + //Serial.println(deviceSettings.wifiSSID); + //Serial.println(deviceSettings.wifiPass); EEPROM.commit(); } @@ -102,9 +102,9 @@ void eepromLoad() { for (uint16_t t = 0; t < sizeof(deviceSettings); t++) *((char*)&deviceSettings + t) = EEPROM.read(CONFIG_START + t); - Serial.println("load+"); - Serial.println(deviceSettings.wifiSSID); - Serial.println(deviceSettings.wifiPass); + //Serial.println("load+"); + //Serial.println(deviceSettings.wifiSSID); + //Serial.println(deviceSettings.wifiPass); // If we want to restore all our settings /* From 243624e4ce63ae64411c09b03af3bf47fdef83f9 Mon Sep 17 00:00:00 2001 From: Nils Bernhardt Date: Tue, 6 Mar 2018 15:50:09 +0100 Subject: [PATCH 15/23] Timing... --- espArtLeDNode/espArtLeDNode.ino | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/espArtLeDNode/espArtLeDNode.ino b/espArtLeDNode/espArtLeDNode.ino index ba63af3..bc2b15d 100644 --- a/espArtLeDNode/espArtLeDNode.ino +++ b/espArtLeDNode/espArtLeDNode.ino @@ -30,7 +30,7 @@ extern "C" { extern struct rst_info resetInfo; } -#define FIRMWARE_VERSION "v1.0.3-dev14" +#define FIRMWARE_VERSION "v1.0.3-dev15" #define ART_FIRM_VERSION 0x0200 // Firmware given over Artnet (2 bytes) @@ -275,7 +275,8 @@ void loop(void){ } webServer.handleClient(); - delay(7); + // Trying some sort of timing adjustments to fight crashes + delay(5); // Get the node details and handle Artnet doNodeReport(); From 5de2d109d36708e6b07d16bccec9dfa584a3c3ca Mon Sep 17 00:00:00 2001 From: Nils Bernhardt Date: Tue, 6 Mar 2018 16:31:19 +0100 Subject: [PATCH 16/23] Will not getting better... --- espArtLeDNode/espArtLeDNode.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/espArtLeDNode/espArtLeDNode.ino b/espArtLeDNode/espArtLeDNode.ino index bc2b15d..81fd65a 100644 --- a/espArtLeDNode/espArtLeDNode.ino +++ b/espArtLeDNode/espArtLeDNode.ino @@ -30,7 +30,7 @@ extern "C" { extern struct rst_info resetInfo; } -#define FIRMWARE_VERSION "v1.0.3-dev15" +#define FIRMWARE_VERSION "v1.0.3-dev16" #define ART_FIRM_VERSION 0x0200 // Firmware given over Artnet (2 bytes) @@ -276,7 +276,7 @@ void loop(void){ webServer.handleClient(); // Trying some sort of timing adjustments to fight crashes - delay(5); + //delay(5); // Get the node details and handle Artnet doNodeReport(); From 171933cf20700ad1e7db1bea4bdb7e3d39bb112a Mon Sep 17 00:00:00 2001 From: Nils Bernhardt Date: Tue, 6 Mar 2018 17:29:21 +0100 Subject: [PATCH 17/23] One more try... --- espArtLeDNode/espArtLeDNode.ino | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/espArtLeDNode/espArtLeDNode.ino b/espArtLeDNode/espArtLeDNode.ino index 81fd65a..1b43ffb 100644 --- a/espArtLeDNode/espArtLeDNode.ino +++ b/espArtLeDNode/espArtLeDNode.ino @@ -30,7 +30,7 @@ extern "C" { extern struct rst_info resetInfo; } -#define FIRMWARE_VERSION "v1.0.3-dev16" +#define FIRMWARE_VERSION "v1.0.3-dev18" #define ART_FIRM_VERSION 0x0200 // Firmware given over Artnet (2 bytes) @@ -135,6 +135,15 @@ bool doReboot = false; byte* dataIn; void setup(void) { + // Restart if crashed before + switch (resetInfo.reason) { + case REASON_WDT_RST: // hardware watch dog reset + case REASON_EXCEPTION_RST: // exception reset, GPIO status won’t change + case REASON_SOFT_WDT_RST: // software watch dog reset, GPIO status won’t change + ESP.restart(); + break; + } + //pinMode(4, OUTPUT); //digitalWrite(4, LOW); //Serial.begin(74880); // to match bootloader baudrate @@ -238,15 +247,6 @@ void setup(void) { deviceSettings.doFirmwareUpdate = false; } break; - - case REASON_WDT_RST: // hardware watch dog reset - case REASON_EXCEPTION_RST: // exception reset, GPIO status won’t change - case REASON_SOFT_WDT_RST: // software watch dog reset, GPIO status won’t change - ESP.restart(); - break; - case REASON_DEEP_SLEEP_AWAKE: - // not used - break; } delay(10); From c3302903cae6141b61c411d173facb8ce7679099 Mon Sep 17 00:00:00 2001 From: Nils Bernhardt Date: Wed, 7 Mar 2018 09:55:14 +0100 Subject: [PATCH 18/23] Removed unneccessary wifi check in main loop --- espArtLeDNode/espArtLeDNode.ino | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/espArtLeDNode/espArtLeDNode.ino b/espArtLeDNode/espArtLeDNode.ino index 1b43ffb..0bb6ba4 100644 --- a/espArtLeDNode/espArtLeDNode.ino +++ b/espArtLeDNode/espArtLeDNode.ino @@ -30,7 +30,7 @@ extern "C" { extern struct rst_info resetInfo; } -#define FIRMWARE_VERSION "v1.0.3-dev18" +#define FIRMWARE_VERSION "v1.0.3-dev19" #define ART_FIRM_VERSION 0x0200 // Firmware given over Artnet (2 bytes) @@ -94,7 +94,7 @@ uint8_t MAC_array[6]; uint8_t dmxInSeqID = 0; uint8_t statusLedData[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0}; uint32_t statusTimer = 0; -uint32_t wifiCheckTimer = 0; +//uint32_t wifiCheckTimer = 0; esp8266ArtNetRDM artRDM; ESP8266WebServer webServer(80); @@ -264,7 +264,8 @@ void loop(void){ } */ //connect wifi if not connected (check every 5 seconds) - if (wifiCheckTimer < millis()) { + //Not needed because: WiFi.setAutoReconnect(true) in wifiStart(); + /* if (wifiCheckTimer < millis()) { if (WiFi.status() != WL_CONNECTED) { delay(1); wifiStart(); @@ -272,7 +273,7 @@ void loop(void){ return; } wifiCheckTimer = millis() + 5000; - } + } */ webServer.handleClient(); // Trying some sort of timing adjustments to fight crashes From e043f7b9595a2093a819125462981c3c90701864 Mon Sep 17 00:00:00 2001 From: Nils Bernhardt Date: Wed, 7 Mar 2018 13:11:53 +0100 Subject: [PATCH 19/23] Added reference to original project --- espArtLeDNode/ajax.ino | 2 ++ espArtLeDNode/espArtLeDNode.ino | 2 ++ espArtLeDNode/firmUpdate.ino | 2 ++ espArtLeDNode/startFunctions.ino | 2 ++ espArtLeDNode/store.h | 2 ++ espArtLeDNode/ws2812Driver.cpp | 2 ++ espArtLeDNode/ws2812Driver.h | 2 ++ espArtLeDNode/wsFX.cpp | 2 ++ espArtLeDNode/wsFX.h | 2 ++ 9 files changed, 18 insertions(+) diff --git a/espArtLeDNode/ajax.ino b/espArtLeDNode/ajax.ino index d3fd75e..8ff4763 100644 --- a/espArtLeDNode/ajax.ino +++ b/espArtLeDNode/ajax.ino @@ -2,6 +2,8 @@ ESP8266_ArtNet-LED-DMX-Node https://github.com/bombcheck/ESP8266_LED-DMX-ArtNetNode +Forked from: https://github.com/mtongnz/ESP8266_ArtNetNode_v2 + This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. diff --git a/espArtLeDNode/espArtLeDNode.ino b/espArtLeDNode/espArtLeDNode.ino index 0bb6ba4..3022dd5 100644 --- a/espArtLeDNode/espArtLeDNode.ino +++ b/espArtLeDNode/espArtLeDNode.ino @@ -2,6 +2,8 @@ ESP8266_ArtNet-LED-DMX-Node https://github.com/bombcheck/ESP8266_LED-DMX-ArtNetNode +Forked from: https://github.com/mtongnz/ESP8266_ArtNetNode_v2 + This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. diff --git a/espArtLeDNode/firmUpdate.ino b/espArtLeDNode/firmUpdate.ino index a22b574..727c740 100644 --- a/espArtLeDNode/firmUpdate.ino +++ b/espArtLeDNode/firmUpdate.ino @@ -2,6 +2,8 @@ ESP8266_ArtNet-LED-DMX-Node https://github.com/bombcheck/ESP8266_LED-DMX-ArtNetNode +Forked from: https://github.com/mtongnz/ESP8266_ArtNetNode_v2 + This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. diff --git a/espArtLeDNode/startFunctions.ino b/espArtLeDNode/startFunctions.ino index 65c128a..54a0e97 100644 --- a/espArtLeDNode/startFunctions.ino +++ b/espArtLeDNode/startFunctions.ino @@ -2,6 +2,8 @@ ESP8266_ArtNet-LED-DMX-Node https://github.com/bombcheck/ESP8266_LED-DMX-ArtNetNode +Forked from: https://github.com/mtongnz/ESP8266_ArtNetNode_v2 + This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. diff --git a/espArtLeDNode/store.h b/espArtLeDNode/store.h index 78453d7..8f686f6 100644 --- a/espArtLeDNode/store.h +++ b/espArtLeDNode/store.h @@ -2,6 +2,8 @@ ESP8266_ArtNet-LED-DMX-Node https://github.com/bombcheck/ESP8266_LED-DMX-ArtNetNode +Forked from: https://github.com/mtongnz/ESP8266_ArtNetNode_v2 + This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. diff --git a/espArtLeDNode/ws2812Driver.cpp b/espArtLeDNode/ws2812Driver.cpp index e7feb59..45d9d42 100644 --- a/espArtLeDNode/ws2812Driver.cpp +++ b/espArtLeDNode/ws2812Driver.cpp @@ -2,6 +2,8 @@ ESP8266_ArtNet-LED-DMX-Node https://github.com/bombcheck/ESP8266_LED-DMX-ArtNetNode +Forked from: https://github.com/mtongnz/ESP8266_ArtNetNode_v2 + This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. diff --git a/espArtLeDNode/ws2812Driver.h b/espArtLeDNode/ws2812Driver.h index 9ed8533..178c38d 100644 --- a/espArtLeDNode/ws2812Driver.h +++ b/espArtLeDNode/ws2812Driver.h @@ -2,6 +2,8 @@ ESP8266_ArtNet-LED-DMX-Node https://github.com/bombcheck/ESP8266_LED-DMX-ArtNetNode +Forked from: https://github.com/mtongnz/ESP8266_ArtNetNode_v2 + This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. diff --git a/espArtLeDNode/wsFX.cpp b/espArtLeDNode/wsFX.cpp index 5a3feb9..f533bd3 100644 --- a/espArtLeDNode/wsFX.cpp +++ b/espArtLeDNode/wsFX.cpp @@ -2,6 +2,8 @@ ESP8266_ArtNet-LED-DMX-Node https://github.com/bombcheck/ESP8266_LED-DMX-ArtNetNode +Forked from: https://github.com/mtongnz/ESP8266_ArtNetNode_v2 + This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. diff --git a/espArtLeDNode/wsFX.h b/espArtLeDNode/wsFX.h index 72f8a5a..3197aa6 100644 --- a/espArtLeDNode/wsFX.h +++ b/espArtLeDNode/wsFX.h @@ -2,6 +2,8 @@ ESP8266_ArtNet-LED-DMX-Node https://github.com/bombcheck/ESP8266_LED-DMX-ArtNetNode +Forked from: https://github.com/mtongnz/ESP8266_ArtNetNode_v2 + This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. From 4603e49278e35ef5f9ff4a573370973903e0d4e9 Mon Sep 17 00:00:00 2001 From: Nils Bernhardt Date: Wed, 7 Mar 2018 21:39:11 +0100 Subject: [PATCH 20/23] Reverted timing changes in ws2812 driver --- espArtLeDNode/espArtLeDNode.ino | 2 +- espArtLeDNode/ws2812Driver.cpp | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/espArtLeDNode/espArtLeDNode.ino b/espArtLeDNode/espArtLeDNode.ino index 3022dd5..5b3da6f 100644 --- a/espArtLeDNode/espArtLeDNode.ino +++ b/espArtLeDNode/espArtLeDNode.ino @@ -32,7 +32,7 @@ extern "C" { extern struct rst_info resetInfo; } -#define FIRMWARE_VERSION "v1.0.3-dev19" +#define FIRMWARE_VERSION "v1.0.3-dev20" #define ART_FIRM_VERSION 0x0200 // Firmware given over Artnet (2 bytes) diff --git a/espArtLeDNode/ws2812Driver.cpp b/espArtLeDNode/ws2812Driver.cpp index 45d9d42..c095fee 100644 --- a/espArtLeDNode/ws2812Driver.cpp +++ b/espArtLeDNode/ws2812Driver.cpp @@ -171,7 +171,7 @@ void ICACHE_RAM_ATTR ws2812Driver::doPixel(byte* data, uint8_t pin, uint16_t num "MEMW;" "RSR %[r_cc1], CCOUNT;" // get clock cycles - "ADDI %[r_cc1], %[r_cc1], 100;" // add to cycles for delay - works at 100 + "ADDI %[r_cc1], %[r_cc1], 95;" // add to cycles for delay - works at 100 "SingleOneLoop:" "RSR %[r_cc2], CCOUNT;" // Get clock cycles @@ -181,7 +181,7 @@ void ICACHE_RAM_ATTR ws2812Driver::doPixel(byte* data, uint8_t pin, uint16_t num "MEMW;" "RSR %[r_cc1], CCOUNT;" // get clock cycles - "ADDI %[r_cc1], %[r_cc1], 84;" // add to cycles for delay - works at 67 + "ADDI %[r_cc1], %[r_cc1], 61;" // add to cycles for delay - works at 67 "BEQZ %[r_allow_int], SingleLoop;" // if allowInt equals false, jump without enabling interrupts "RSIL %[r_int], 0;" // enable interrupts again "NOP;" // 1 clock for any interrupts to run @@ -195,7 +195,7 @@ void ICACHE_RAM_ATTR ws2812Driver::doPixel(byte* data, uint8_t pin, uint16_t num "MEMW;" "RSR %[r_cc1], CCOUNT;" // get clock cycles - "ADDI %[r_cc1], %[r_cc1], 44;" // add to cycles for delay - works at 50 + "ADDI %[r_cc1], %[r_cc1], 40;" // add to cycles for delay - works at 50 "SingleZeroLoop:" "RSR %[r_cc2], CCOUNT;" // Get clock cycles @@ -205,7 +205,7 @@ void ICACHE_RAM_ATTR ws2812Driver::doPixel(byte* data, uint8_t pin, uint16_t num "MEMW;" "RSR %[r_cc1], CCOUNT;" // get clock cycles - "ADDI %[r_cc1], %[r_cc1], 116;" // add to cycles for delay - works at 105 + "ADDI %[r_cc1], %[r_cc1], 85;" // add to cycles for delay - works at 105 "BEQZ %[r_allow_int], SingleLoop;" // if allowInt equals false, jump without enabling interrupts "RSIL %[r_int], 0;" // enable interrupts again "NOP;" // 1 clock for any interrupts to run From 8a4e29aa7b4ced54ad8f3e0880075a878b4677d0 Mon Sep 17 00:00:00 2001 From: Nils Bernhardt Date: Thu, 8 Mar 2018 11:06:15 +0100 Subject: [PATCH 21/23] Updated version tag --- espArtLeDNode/espArtLeDNode.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/espArtLeDNode/espArtLeDNode.ino b/espArtLeDNode/espArtLeDNode.ino index 5b3da6f..a93b2eb 100644 --- a/espArtLeDNode/espArtLeDNode.ino +++ b/espArtLeDNode/espArtLeDNode.ino @@ -32,7 +32,7 @@ extern "C" { extern struct rst_info resetInfo; } -#define FIRMWARE_VERSION "v1.0.3-dev20" +#define FIRMWARE_VERSION "v1.0.3" #define ART_FIRM_VERSION 0x0200 // Firmware given over Artnet (2 bytes) From f2bababda839651ac98359273ecbf2dabc411384 Mon Sep 17 00:00:00 2001 From: Nils Bernhardt Date: Thu, 8 Mar 2018 15:40:32 +0100 Subject: [PATCH 22/23] Fixed Stand-Alone-Mode --- espArtLeDNode/espArtLeDNode.ino | 2 +- espArtLeDNode/startFunctions.ino | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/espArtLeDNode/espArtLeDNode.ino b/espArtLeDNode/espArtLeDNode.ino index a93b2eb..fbf48da 100644 --- a/espArtLeDNode/espArtLeDNode.ino +++ b/espArtLeDNode/espArtLeDNode.ino @@ -32,7 +32,7 @@ extern "C" { extern struct rst_info resetInfo; } -#define FIRMWARE_VERSION "v1.0.3" +#define FIRMWARE_VERSION "v1.0.4" #define ART_FIRM_VERSION 0x0200 // Firmware given over Artnet (2 bytes) diff --git a/espArtLeDNode/startFunctions.ino b/espArtLeDNode/startFunctions.ino index 54a0e97..ac9da09 100644 --- a/espArtLeDNode/startFunctions.ino +++ b/espArtLeDNode/startFunctions.ino @@ -437,13 +437,13 @@ void startHotspot() { unsigned long endTime = millis() + 30000; // Stay here if not in stand alone mode - no dmx or artnet - //while (endTime > millis() || wifi_softap_get_station_num() > 0) { // if 30 seconds has passed or client connected - while (true){ + while (endTime > millis() || wifi_softap_get_station_num() > 0) { // if 30 seconds has passed or client connected + //while (true){ webServer.handleClient(); - //yield(); - delay(1); + yield(); + //delay(1); } - //ESP.restart(); - //isHotspot = false; + isHotspot = false; + ESP.restart(); } From c552a311440713edfdd16235a2421ba7e228690a Mon Sep 17 00:00:00 2001 From: Nils Bernhardt Date: Thu, 8 Mar 2018 23:17:44 +0100 Subject: [PATCH 23/23] Fixed hotspot-bug --- espArtLeDNode/startFunctions.ino | 1 + 1 file changed, 1 insertion(+) diff --git a/espArtLeDNode/startFunctions.ino b/espArtLeDNode/startFunctions.ino index ac9da09..4910c56 100644 --- a/espArtLeDNode/startFunctions.ino +++ b/espArtLeDNode/startFunctions.ino @@ -380,6 +380,7 @@ void wifiStart() { // Serial.println("Failed to connect to WiFi. Please verify credentials: "); // delay(1000); startHotspot(); + return; } delay(100); // Serial.print(".");