Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/wdt': v1.0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
bombcheck committed Mar 9, 2018
2 parents e271ea3 + c552a31 commit 0fefdf5
Show file tree
Hide file tree
Showing 10 changed files with 297 additions and 201 deletions.
6 changes: 1 addition & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion espArtLeDNode/ajax.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -741,4 +743,3 @@ void ajaxLoad(uint8_t page, JsonObject& jsonReply) {
jsonReply["message"] = "Invalid or incomplete data received.";
}
}

110 changes: 79 additions & 31 deletions espArtLeDNode/espArtLeDNode.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)


Expand All @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -77,7 +78,6 @@ extern "C" {
#define SETTINGS_RESET 14
#endif


// Definitions for status leds xxBBRRGG
#define BLACK 0x00000000
#define WHITE 0x00FFFFFF
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -177,66 +190,96 @@ 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
if (!resetDefaults)
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();
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -587,4 +636,3 @@ void doStatusLedOutput() {
void setStatusLed(uint8_t num, uint32_t col) {
memcpy(&statusLedData[num*3], &col, 3);
}

2 changes: 2 additions & 0 deletions espArtLeDNode/firmUpdate.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading

0 comments on commit 0fefdf5

Please sign in to comment.