From 630c10d8c858394e5595c5070151c5d3a99de011 Mon Sep 17 00:00:00 2001 From: proddy Date: Tue, 12 Mar 2019 23:03:26 +0100 Subject: [PATCH] optional compile with CRASH support --- lib/MyESP/MyESP.cpp | 51 ++++++++++++++++++++++++++++++++---------- lib/MyESP/MyESP.h | 2 ++ platformio.ini-example | 2 +- 3 files changed, 42 insertions(+), 13 deletions(-) diff --git a/lib/MyESP/MyESP.cpp b/lib/MyESP/MyESP.cpp index d4378fe88..79c116331 100644 --- a/lib/MyESP/MyESP.cpp +++ b/lib/MyESP/MyESP.cpp @@ -165,7 +165,7 @@ void MyESP::_wifiCallback(justwifi_messages_t code, char * parameter) { _wifi_callback(); } - jw.enableAPFallback(false); // Disable AP mode after initial connect was succesfull. Thanks @JewelZB + jw.enableAPFallback(false); // Disable AP mode after initial connect was succesfull. Thanks @JewelZB } if (code == MESSAGE_ACCESSPOINT_CREATED) { @@ -291,7 +291,10 @@ void MyESP::_mqtt_setup() { //mqttClient.onPublish([this](uint16_t packetId) { myDebug_P(PSTR("[MQTT] Publish ACK for PID %d"), packetId); }); - mqttClient.onMessage([this](char * topic, char * payload, AsyncMqttClientMessageProperties properties, size_t len, size_t index, size_t total) { _mqttOnMessage(topic, payload, len); }); + mqttClient.onMessage( + [this](char * topic, char * payload, AsyncMqttClientMessageProperties properties, size_t len, size_t index, size_t total) { + _mqttOnMessage(topic, payload, len); + }); } // WiFI setup @@ -407,12 +410,12 @@ void MyESP::_printBuildTime(unsigned long unix) { uint8_t Day, Month; - uint8_t Seconds = unix % 60; /* Get seconds from unix */ - unix /= 60; /* Go to minutes */ - uint8_t Minutes = unix % 60; /* Get minutes */ - unix /= 60; /* Go to hours */ - uint8_t Hours = unix % 24; /* Get hours */ - unix /= 24; /* Go to days */ + uint8_t Seconds = unix % 60; /* Get seconds from unix */ + unix /= 60; /* Go to minutes */ + uint8_t Minutes = unix % 60; /* Get minutes */ + unix /= 60; /* Go to hours */ + uint8_t Hours = unix % 24; /* Get hours */ + unix /= 24; /* Go to days */ uint16_t year = 1970; /* Process year */ while (1) { @@ -468,7 +471,10 @@ void MyESP::_consoleShowHelp() { #else String hostname = WiFi.hostname(); #endif - SerialAndTelnet.printf("* Hostname: %s IP: %s MAC: %s", hostname.c_str(), WiFi.localIP().toString().c_str(), WiFi.macAddress().c_str()); + SerialAndTelnet.printf("* Hostname: %s IP: %s MAC: %s", + hostname.c_str(), + WiFi.localIP().toString().c_str(), + WiFi.macAddress().c_str()); #ifdef ARDUINO_BOARD SerialAndTelnet.printf(" Board: %s", ARDUINO_BOARD); #endif @@ -727,7 +733,7 @@ void MyESP::_telnetCommand(char * commandLine) { crashDump(); } else if (strcmp(cmd, "clear") == 0) { crashClear(); - } else if ((strcmp(cmd, "test") == 0) && (wc == 3) ) { + } else if ((strcmp(cmd, "test") == 0) && (wc == 3)) { char * value = _telnet_readWord(); crashTest(atoi(value)); } @@ -864,7 +870,17 @@ void MyESP::setWIFI(const char * wifi_ssid, const char * wifi_password, wifi_cal } // init MQTT settings -void MyESP::setMQTT(const char * mqtt_host, const char * mqtt_username, const char * mqtt_password, const char * mqtt_base, unsigned long mqtt_keepalive, unsigned char mqtt_qos, bool mqtt_retain, const char * mqtt_will_topic, const char * mqtt_will_online_payload, const char * mqtt_will_offline_payload, mqtt_callback_f callback) { +void MyESP::setMQTT(const char * mqtt_host, + const char * mqtt_username, + const char * mqtt_password, + const char * mqtt_base, + unsigned long mqtt_keepalive, + unsigned char mqtt_qos, + bool mqtt_retain, + const char * mqtt_will_topic, + const char * mqtt_will_online_payload, + const char * mqtt_will_offline_payload, + mqtt_callback_f callback) { // can be empty if (!mqtt_host || *mqtt_host == 0x00) { _mqtt_host = NULL; @@ -1148,13 +1164,13 @@ int MyESP::getWifiQuality() { return 2 * (dBm + 100); } +#ifdef CRASH /** * Save crash information in EEPROM * This function is called automatically if ESP8266 suffers an exception * It should be kept quick / consise to be able to execute before hardware wdt may kick in */ extern "C" void custom_crash_callback(struct rst_info * rst_info, uint32_t stack_start, uint32_t stack_end) { - // Note that 'EEPROM.begin' method is reserving a RAM buffer // The buffer size is SAVE_CRASH_EEPROM_OFFSET + SAVE_CRASH_SPACE_SIZE EEPROM.begin(SAVE_CRASH_EEPROM_OFFSET + SAVE_CRASH_EEPROM_SIZE); @@ -1295,6 +1311,17 @@ void MyESP::crashDump() { } myDebug("<< // https://github.com/xoseperez/justwifi #include // modified from https://github.com/yasheena/telnetspy +#ifdef CRASH #include "EEPROM.h" extern "C" { void custom_crash_callback(struct rst_info*, uint32_t, uint32_t); } +#endif #if defined(ARDUINO_ARCH_ESP32) //#include diff --git a/platformio.ini-example b/platformio.ini-example index b381c389d..3687c74f0 100644 --- a/platformio.ini-example +++ b/platformio.ini-example @@ -5,7 +5,7 @@ env_default = d1_mini platform = espressif8266 flash_mode = dout -build_flags_debug = -ggdb3 -Wall -Wextra -Werror -Wno-missing-field-initializers -Wno-unused-parameter -Wno-unused-variable +build_flags_debug = -ggdb3 -Wall -Wextra -Werror -Wno-missing-field-initializers -Wno-unused-parameter -Wno-unused-variable -DCRASH ;build_flags_prod = -Os -DBUILD_TIME=$UNIX_TIME build_flags = ${common.build_flags_debug}