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/ajax.ino b/espArtLeDNode/ajax.ino index d3c5ef5..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. @@ -741,4 +743,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..fbf48da 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. @@ -30,7 +32,7 @@ extern "C" { extern struct rst_info resetInfo; } -#define FIRMWARE_VERSION "v1.0.2" +#define FIRMWARE_VERSION "v1.0.4" #define ART_FIRM_VERSION 0x0200 // Firmware given over Artnet (2 bytes) @@ -39,7 +41,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) @@ -48,7 +49,7 @@ extern "C" { #ifdef ESP_01 - #define DMX_DIR_A 2 // Same pin as TX1 + #define DMX_DIR_A 2 #define DMX_TX_A 1 #define ONE_PORT #define NO_RESET @@ -77,7 +78,6 @@ extern "C" { #define SETTINGS_RESET 14 #endif - // Definitions for status leds xxBBRRGG #define BLACK 0x00000000 #define WHITE 0x00FFFFFF @@ -96,6 +96,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); @@ -136,9 +137,21 @@ 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 + //Serial.setDebugOutput(true); + 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); @@ -177,12 +190,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,53 +203,83 @@ 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(); - - // Don't start our Artnet or DMX in firmware update mode or after multiple WDT resets - if (!deviceSettings.doFirmwareUpdate && deviceSettings.wdtCounter <= 3) { + switch (resetInfo.reason) { + 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) { - // 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; + } else { + deviceSettings.doFirmwareUpdate = false; + } + break; + } delay(10); } 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) { + /* if (deviceSettings.resetCounter != 0 && millis() > 6000) { deviceSettings.resetCounter = 0; deviceSettings.wdtCounter = 0; eepromSave(); } - + */ + //connect wifi if not connected (check every 5 seconds) + //Not needed because: WiFi.setAutoReconnect(true) in wifiStart(); + /* if (wifiCheckTimer < millis()) { + if (WiFi.status() != WL_CONNECTED) { + delay(1); + wifiStart(); + ESP.wdtFeed(); + return; + } + wifiCheckTimer = millis() + 5000; + } */ webServer.handleClient(); + + // Trying some sort of timing adjustments to fight crashes + //delay(5); // Get the node details and handle Artnet doNodeReport(); @@ -296,7 +339,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 +636,3 @@ void doStatusLedOutput() { void setStatusLed(uint8_t num, uint32_t col) { memcpy(&statusLedData[num*3], &col, 3); } - 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 3e0b937..4910c56 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. @@ -16,74 +18,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 +94,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 +106,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 +149,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 +160,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]); + } + 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 + } +#endif // Add required callback functions artRDM.setArtDMXCallback(dmxHandle); @@ -236,7 +238,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 +261,7 @@ void artStart() { // not used break; } - + // Start artnet artRDM.begin(); @@ -267,15 +269,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,100 +287,123 @@ 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(); } 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(); 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(); + return; + } + 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 +411,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 +429,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(); + //delay(1); } - ESP.restart(); isHotspot = false; + ESP.restart(); } diff --git a/espArtLeDNode/store.h b/espArtLeDNode/store.h index 268c9fb..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. @@ -67,7 +69,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, @@ -79,42 +81,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..c095fee 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 5b036e7..f533bd3 100644 --- a/espArtLeDNode/wsFX.cpp +++ b/espArtLeDNode/wsFX.cpp @@ -1,7 +1,9 @@ /* -ESP8266_LED-DMX-ArtNetNode +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.