Browse Source

Merge pull request #2028 from mcspr/ota/arduino-ota-adjustments

OTA and system callbacks adjustments
master
Max Prokhorov 5 years ago
committed by GitHub
parent
commit
8dab1239d8
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 66 additions and 21 deletions
  1. +2
    -0
      code/espurna/api.ino
  2. +1
    -0
      code/espurna/button.ino
  3. +0
    -4
      code/espurna/config/prototypes.h
  4. +7
    -4
      code/espurna/espurna.ino
  5. +1
    -0
      code/espurna/mqtt.ino
  6. +1
    -0
      code/espurna/nofuss.ino
  7. +14
    -7
      code/espurna/ota_arduinoota.ino
  8. +2
    -0
      code/espurna/ota_asynctcp.ino
  9. +1
    -0
      code/espurna/ota_httpupdate.ino
  10. +25
    -0
      code/espurna/system.h
  11. +8
    -6
      code/espurna/system.ino
  12. +1
    -0
      code/espurna/terminal.ino
  13. +1
    -0
      code/espurna/web.ino
  14. +2
    -0
      code/espurna/ws.ino

+ 2
- 0
code/espurna/api.ino View File

@ -13,6 +13,8 @@ Copyright (C) 2016-2019 by Xose Pérez <xose dot perez at gmail dot com>
#include <ArduinoJson.h> #include <ArduinoJson.h>
#include <vector> #include <vector>
#include "system.h"
typedef struct { typedef struct {
char * key; char * key;
api_get_callback_f getFn = NULL; api_get_callback_f getFn = NULL;


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

@ -15,6 +15,7 @@ Copyright (C) 2016-2019 by Xose Pérez <xose dot perez at gmail dot com>
#include <DebounceEvent.h> #include <DebounceEvent.h>
#include <vector> #include <vector>
#include "system.h"
#include "relay.h" #include "relay.h"
#include "light.h" #include "light.h"


+ 0
- 4
code/espurna/config/prototypes.h View File

@ -38,10 +38,6 @@ extern "C" {
#define TCP_MSS (1460) #define TCP_MSS (1460)
#endif #endif
uint32_t systemResetReason();
uint8_t systemStabilityCounter();
void systemStabilityCounter(uint8_t);
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// PROGMEM // PROGMEM
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------


+ 7
- 4
code/espurna/espurna.ino View File

@ -22,14 +22,17 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "config/all.h" #include "config/all.h"
#include <vector> #include <vector>
#include "system.h"
#include "utils.h" #include "utils.h"
#include "relay.h" #include "relay.h"
#include "broker.h" #include "broker.h"
#include "tuya.h" #include "tuya.h"
#include "libs/HeapStats.h" #include "libs/HeapStats.h"
std::vector<void (*)()> _loop_callbacks;
std::vector<void (*)()> _reload_callbacks;
using void_callback_f = void (*)();
std::vector<void_callback_f> _loop_callbacks;
std::vector<void_callback_f> _reload_callbacks;
bool _reload_config = false; bool _reload_config = false;
unsigned long _loop_delay = 0; unsigned long _loop_delay = 0;
@ -38,11 +41,11 @@ unsigned long _loop_delay = 0;
// GENERAL CALLBACKS // GENERAL CALLBACKS
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
void espurnaRegisterLoop(void (*callback)()) {
void espurnaRegisterLoop(void_callback_f callback) {
_loop_callbacks.push_back(callback); _loop_callbacks.push_back(callback);
} }
void espurnaRegisterReload(void (*callback)()) {
void espurnaRegisterReload(void_callback_f callback) {
_reload_callbacks.push_back(callback); _reload_callbacks.push_back(callback);
} }


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

@ -18,6 +18,7 @@ Updated secure client support by Niek van der Maas < mail at niekvandermaas dot
#include <Ticker.h> #include <Ticker.h>
#include <TimeLib.h> #include <TimeLib.h>
#include "system.h"
#include "libs/SecureClientHelpers.h" #include "libs/SecureClientHelpers.h"
#if MQTT_LIBRARY == MQTT_LIBRARY_ASYNCMQTTCLIENT #if MQTT_LIBRARY == MQTT_LIBRARY_ASYNCMQTTCLIENT


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

@ -153,6 +153,7 @@ void nofussSetup() {
#endif #endif
// TODO: NoFUSS will reset the board after this callback returns. // TODO: NoFUSS will reset the board after this callback returns.
// Maybe this should be optional // Maybe this should be optional
customResetReason(CUSTOM_RESET_NOFUSS);
nice_delay(100); nice_delay(100);
} }


+ 14
- 7
code/espurna/ota_arduinoota.ino View File

@ -8,6 +8,8 @@ Copyright (C) 2016-2019 by Xose Pérez <xose dot perez at gmail dot com>
#if OTA_ARDUINOOTA_SUPPORT #if OTA_ARDUINOOTA_SUPPORT
#include "system.h"
// TODO: allocate ArduinoOTAClass on-demand, stop using global instance // TODO: allocate ArduinoOTAClass on-demand, stop using global instance
void _arduinoOtaConfigure() { void _arduinoOtaConfigure() {
@ -48,7 +50,10 @@ void _arduinoOtaOnEnd() {
#if WEB_SUPPORT #if WEB_SUPPORT
wsSend_P(PSTR("{\"action\": \"reload\"}")); wsSend_P(PSTR("{\"action\": \"reload\"}"));
#endif #endif
deferredReset(100, CUSTOM_RESET_OTA);
// Note: ArduinoOTA will reset the board after this callback returns.
customResetReason(CUSTOM_RESET_OTA);
nice_delay(100);
} }
@ -60,13 +65,15 @@ void _arduinoOtaOnProgress(unsigned int progress, unsigned int total) {
if (wsConnected()) return; if (wsConnected()) return;
#endif #endif
static unsigned int _progOld;
#if DEBUG_SUPPORT
static unsigned int _progOld;
unsigned int _prog = (progress / (total / 100));
if (_prog != _progOld) {
DEBUG_MSG_P(PSTR("[OTA] Progress: %u%%\r"), _prog);
_progOld = _prog;
}
unsigned int _prog = (progress / (total / 100));
if (_prog != _progOld) {
DEBUG_MSG_P(PSTR("[OTA] Progress: %u%%\r"), _prog);
_progOld = _prog;
}
#endif
} }


+ 2
- 0
code/espurna/ota_asynctcp.ino View File

@ -15,6 +15,8 @@ Copyright (C) 2016-2019 by Xose Pérez <xose dot perez at gmail dot com>
#if TERMINAL_SUPPORT || OTA_MQTT_SUPPORT #if TERMINAL_SUPPORT || OTA_MQTT_SUPPORT
#include <ESPAsyncTCP.h> #include <ESPAsyncTCP.h>
#include "system.h"
#include "libs/URL.h" #include "libs/URL.h"
std::unique_ptr<AsyncClient> _ota_client = nullptr; std::unique_ptr<AsyncClient> _ota_client = nullptr;


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

@ -18,6 +18,7 @@ Copyright (C) 2019 by Maxim Prokhorov <prokhorov dot max at outlook dot com>
#include <ESP8266httpUpdate.h> #include <ESP8266httpUpdate.h>
#include <Schedule.h> #include <Schedule.h>
#include "system.h"
#include "libs/URL.h" #include "libs/URL.h"
#include "libs/TypeChecks.h" #include "libs/TypeChecks.h"
#include "libs/SecureClientHelpers.h" #include "libs/SecureClientHelpers.h"


+ 25
- 0
code/espurna/system.h View File

@ -0,0 +1,25 @@
/*
SYSTEM MODULE
Copyright (C) 2019 by Xose Pérez <xose dot perez at gmail dot com>
*/
#pragma once
#include <cstdint>
uint32_t systemResetReason();
uint8_t systemStabilityCounter();
void systemStabilityCounter(uint8_t count);
void systemCheck(bool stable);
bool systemCheck();
uint32_t systemResetReason();
unsigned char customResetReason();
void customResetReason(unsigned char reason);
void deferredReset(unsigned long delay, unsigned char reason);
bool checkNeedsReset();

+ 8
- 6
code/espurna/system.ino View File

@ -9,6 +9,8 @@ Copyright (C) 2019 by Xose Pérez <xose dot perez at gmail dot com>
#include <Ticker.h> #include <Ticker.h>
#include <EEPROM_Rotate.h> #include <EEPROM_Rotate.h>
#include "system.h"
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
bool _system_send_heartbeat = false; bool _system_send_heartbeat = false;
@ -25,33 +27,33 @@ union system_rtcmem_t {
uint8_t stability_counter; uint8_t stability_counter;
uint8_t reset_reason; uint8_t reset_reason;
uint16_t _reserved_; uint16_t _reserved_;
} parts;
} packed;
uint32_t value; uint32_t value;
}; };
uint8_t systemStabilityCounter() { uint8_t systemStabilityCounter() {
system_rtcmem_t data; system_rtcmem_t data;
data.value = Rtcmem->sys; data.value = Rtcmem->sys;
return data.parts.stability_counter;
return data.packed.stability_counter;
} }
void systemStabilityCounter(uint8_t counter) {
void systemStabilityCounter(uint8_t count) {
system_rtcmem_t data; system_rtcmem_t data;
data.value = Rtcmem->sys; data.value = Rtcmem->sys;
data.parts.stability_counter = counter;
data.packed.stability_counter = count;
Rtcmem->sys = data.value; Rtcmem->sys = data.value;
} }
uint8_t _systemResetReason() { uint8_t _systemResetReason() {
system_rtcmem_t data; system_rtcmem_t data;
data.value = Rtcmem->sys; data.value = Rtcmem->sys;
return data.parts.reset_reason;
return data.packed.reset_reason;
} }
void _systemResetReason(uint8_t reason) { void _systemResetReason(uint8_t reason) {
system_rtcmem_t data; system_rtcmem_t data;
data.value = Rtcmem->sys; data.value = Rtcmem->sys;
data.parts.reset_reason = reason;
data.packed.reset_reason = reason;
Rtcmem->sys = data.value; Rtcmem->sys = data.value;
} }


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

@ -8,6 +8,7 @@ Copyright (C) 2016-2019 by Xose Pérez <xose dot perez at gmail dot com>
#if TERMINAL_SUPPORT #if TERMINAL_SUPPORT
#include "system.h"
#include "utils.h" #include "utils.h"
#include "libs/EmbedisWrap.h" #include "libs/EmbedisWrap.h"
#include "libs/StreamInjector.h" #include "libs/StreamInjector.h"


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

@ -8,6 +8,7 @@ Copyright (C) 2016-2019 by Xose Pérez <xose dot perez at gmail dot com>
#if WEB_SUPPORT #if WEB_SUPPORT
#include "system.h"
#include "utils.h" #include "utils.h"
#include <ESPAsyncTCP.h> #include <ESPAsyncTCP.h>


+ 2
- 0
code/espurna/ws.ino View File

@ -13,6 +13,8 @@ Copyright (C) 2016-2019 by Xose Pérez <xose dot perez at gmail dot com>
#include <ArduinoJson.h> #include <ArduinoJson.h>
#include <Ticker.h> #include <Ticker.h>
#include <vector> #include <vector>
#include "system.h"
#include "libs/WebSocketIncommingBuffer.h" #include "libs/WebSocketIncommingBuffer.h"
AsyncWebSocket _ws("/ws"); AsyncWebSocket _ws("/ws");


Loading…
Cancel
Save