Browse Source

Added custom reset messages

fastled
Xose Pérez 7 years ago
parent
commit
e349c6991b
7 changed files with 74 additions and 4 deletions
  1. +5
    -1
      code/espurna/button.ino
  2. +35
    -1
      code/espurna/config/general.h
  3. +25
    -1
      code/espurna/espurna.ino
  4. +1
    -0
      code/espurna/mqtt.ino
  5. +1
    -0
      code/espurna/ota.ino
  6. +1
    -0
      code/espurna/settings.ino
  7. +6
    -1
      code/espurna/web.ino

+ 5
- 1
code/espurna/button.ino View File

@ -93,11 +93,15 @@ void buttonEvent(unsigned int id, unsigned char event) {
} }
} }
if (action == BUTTON_MODE_AP) createAP(); if (action == BUTTON_MODE_AP) createAP();
if (action == BUTTON_MODE_RESET) ESP.restart();
if (action == BUTTON_MODE_RESET) {
customReset(CUSTOM_RESET_HARDWARE);
ESP.restart();
}
if (action == BUTTON_MODE_PULSE) relayPulseToggle(); if (action == BUTTON_MODE_PULSE) relayPulseToggle();
if (action == BUTTON_MODE_FACTORY) { if (action == BUTTON_MODE_FACTORY) {
DEBUG_MSG_P(PSTR("\n\nFACTORY RESET\n\n")); DEBUG_MSG_P(PSTR("\n\nFACTORY RESET\n\n"));
settingsFactoryReset(); settingsFactoryReset();
customReset(CUSTOM_RESET_FACTORY);
ESP.restart(); ESP.restart();
} }


+ 35
- 1
code/espurna/config/general.h View File

@ -29,7 +29,41 @@
#define EEPROM_RELAY_STATUS 0 #define EEPROM_RELAY_STATUS 0
#define EEPROM_ENERGY_COUNT 1 #define EEPROM_ENERGY_COUNT 1
#define EEPROM_DATA_END 5
#define EEPROM_CUSTOM_RESET 5
#define EEPROM_DATA_END 6
//--------------------------------------------------------------------------------
// RESET
//--------------------------------------------------------------------------------
#define CUSTOM_RESET_HARDWARE 1
#define CUSTOM_RESET_WEB 2
#define CUSTOM_RESET_TERMINAL 3
#define CUSTOM_RESET_MQTT 4
#define CUSTOM_RESET_RPC 5
#define CUSTOM_RESET_OTA 6
#define CUSTOM_RESET_NOFUSS 8
#define CUSTOM_RESET_UPGRADE 9
#define CUSTOM_RESET_FACTORY 10
#define CUSTOM_RESET_MAX 10
#include <pgmspace.h>
PROGMEM const char custom_reset_hardware[] = "Hardware button";
PROGMEM const char custom_reset_web[] = "Reset from web interface";
PROGMEM const char custom_reset_terminal[] = "Reset from terminal";
PROGMEM const char custom_reset_mqtt[] = "Reset from MQTT";
PROGMEM const char custom_reset_rpc[] = "Reset from RPC";
PROGMEM const char custom_reset_ota[] = "Reset after successful OTA update";
PROGMEM const char custom_reset_nofuss[] = "Reset after successful NoFUSS update";
PROGMEM const char custom_reset_upgrade[] = "Reset after successful web update";
PROGMEM const char custom_reset_factory[] = "Factory reset";
PROGMEM const char* const custom_reset_string[] = {
custom_reset_hardware, custom_reset_web, custom_reset_terminal,
custom_reset_mqtt, custom_reset_rpc, custom_reset_ota,
custom_reset_nofuss, custom_reset_upgrade, custom_reset_factory
};
//-------------------------------------------------------------------------------- //--------------------------------------------------------------------------------
// BUTTON // BUTTON


+ 25
- 1
code/espurna/espurna.ino View File

@ -104,6 +104,21 @@ void heartbeat() {
} }
void customReset(unsigned char status) {
EEPROM.write(EEPROM_CUSTOM_RESET, status);
EEPROM.commit();
}
unsigned char customReset() {
static unsigned char status = 255;
if (status == 255) {
status = EEPROM.read(EEPROM_CUSTOM_RESET);
if (status > 0) customReset(0);
if (status > CUSTOM_RESET_MAX) status = 0;
}
return status;
}
void hardwareSetup() { void hardwareSetup() {
EEPROM.begin(4096); EEPROM.begin(4096);
#ifdef DEBUG_PORT #ifdef DEBUG_PORT
@ -138,7 +153,16 @@ void welcome() {
DEBUG_MSG_P(PSTR("%s\n%s\n\n"), (char *) APP_AUTHOR, (char *) APP_WEBSITE); DEBUG_MSG_P(PSTR("%s\n%s\n\n"), (char *) APP_AUTHOR, (char *) APP_WEBSITE);
DEBUG_MSG_P(PSTR("ChipID: %06X\n"), ESP.getChipId()); DEBUG_MSG_P(PSTR("ChipID: %06X\n"), ESP.getChipId());
DEBUG_MSG_P(PSTR("CPU frequency: %d MHz\n"), ESP.getCpuFreqMHz()); DEBUG_MSG_P(PSTR("CPU frequency: %d MHz\n"), ESP.getCpuFreqMHz());
DEBUG_MSG_P(PSTR("Last reset reason: %s\n"), (char *) ESP.getResetReason().c_str());
unsigned char custom_reset = customReset();
if (custom_reset > 0) {
char buffer[32];
strcpy_P(buffer, custom_reset_string[custom_reset-1]);
DEBUG_MSG_P(PSTR("Last reset reason: %s\n"), buffer);
} else {
DEBUG_MSG_P(PSTR("Last reset reason: %s\n"), (char *) ESP.getResetReason().c_str());
}
DEBUG_MSG_P(PSTR("Memory size (SDK): %d bytes\n"), ESP.getFlashChipSize()); DEBUG_MSG_P(PSTR("Memory size (SDK): %d bytes\n"), ESP.getFlashChipSize());
DEBUG_MSG_P(PSTR("Memory size (CHIP): %d bytes\n"), ESP.getFlashChipRealSize()); DEBUG_MSG_P(PSTR("Memory size (CHIP): %d bytes\n"), ESP.getFlashChipRealSize());
DEBUG_MSG_P(PSTR("Free heap: %d bytes\n"), ESP.getFreeHeap()); DEBUG_MSG_P(PSTR("Free heap: %d bytes\n"), ESP.getFreeHeap());


+ 1
- 0
code/espurna/mqtt.ino View File

@ -166,6 +166,7 @@ void _mqttOnMessage(char* topic, char* payload, unsigned int len) {
String t = mqttSubtopic((char *) topic); String t = mqttSubtopic((char *) topic);
if (t.equals(MQTT_TOPIC_ACTION)) { if (t.equals(MQTT_TOPIC_ACTION)) {
if (strcmp(message, MQTT_ACTION_RESET) == 0) { if (strcmp(message, MQTT_ACTION_RESET) == 0) {
customReset(CUSTOM_RESET_MQTT);
ESP.restart(); ESP.restart();
} }
} }


+ 1
- 0
code/espurna/ota.ino View File

@ -28,6 +28,7 @@ void otaSetup() {
}); });
ArduinoOTA.onEnd([]() { ArduinoOTA.onEnd([]() {
customReset(CUSTOM_RESET_OTA);
DEBUG_MSG_P(PSTR("\n[OTA] End\n")); DEBUG_MSG_P(PSTR("\n[OTA] End\n"));
wsSend("{\"action\": \"reload\"}"); wsSend("{\"action\": \"reload\"}");
delay(100); delay(100);


+ 1
- 0
code/espurna/settings.ino View File

@ -96,6 +96,7 @@ void settingsSetup() {
Embedis::command( F("RESET"), [](Embedis* e) { Embedis::command( F("RESET"), [](Embedis* e) {
e->response(Embedis::OK); e->response(Embedis::OK);
customReset(CUSTOM_RESET_TERMINAL);
ESP.restart(); ESP.restart();
}); });


+ 6
- 1
code/espurna/web.ino View File

@ -86,6 +86,7 @@ void _wsParse(uint32_t client_id, uint8_t * payload, size_t length) {
DEBUG_MSG_P(PSTR("[WEBSOCKET] Requested action: %s\n"), action.c_str()); DEBUG_MSG_P(PSTR("[WEBSOCKET] Requested action: %s\n"), action.c_str());
if (action.equals("reset")) { if (action.equals("reset")) {
customReset(CUSTOM_RESET_WEB);
ESP.restart(); ESP.restart();
} }
@ -779,7 +780,10 @@ void _onRPC(AsyncWebServerRequest *request) {
if (action.equals("reset")) { if (action.equals("reset")) {
response = 200; response = 200;
deferred.once_ms(100, []() { ESP.restart(); });
deferred.once_ms(100, []() {
customReset(CUSTOM_RESET_RPC);
ESP.restart();
});
} }
} }
@ -863,6 +867,7 @@ void _onUpgrade(AsyncWebServerRequest *request) {
response->addHeader("Connection", "close"); response->addHeader("Connection", "close");
if (!Update.hasError()) { if (!Update.hasError()) {
deferred.once_ms(100, []() { deferred.once_ms(100, []() {
customReset(CUSTOM_RESET_UPGRADE);
ESP.restart(); ESP.restart();
}); });
} }


Loading…
Cancel
Save