Skip to content

Commit

Permalink
mise en pause téléinfo pendant update
Browse files Browse the repository at this point in the history
  • Loading branch information
rene-d committed Mar 7, 2020
1 parent c5fe66e commit a4cd3b6
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
6 changes: 6 additions & 0 deletions src/tic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ static esp8266::polledTimeout::periodicMs timer_sse(esp8266::polledTimeout::peri

Teleinfo tinfo;
static TeleinfoDecoder tinfo_decoder;
bool tinfo_pause = false;

static void tic_get_json_dict_notif(String &data, const char *notif);
static void http_notif(const char *notif);
Expand All @@ -51,6 +52,11 @@ static void emoncms_notif();

void tic_decode(int c)
{
if (tinfo_pause)
{
return;
}

tinfo_decoder.put(c);

if (tinfo_decoder.ready())
Expand Down
2 changes: 2 additions & 0 deletions src/tic.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ void tic_get_json_dict(String &html, bool restricted);
void tic_emoncms_data(String &url, bool restricted);

void tic_dump();

extern bool tinfo_pause;
25 changes: 16 additions & 9 deletions src/update.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,17 @@
#include "wifinfo.h"
#include "led.h"
#include "sys.h"
#include "tic.h"
#include "webserver.h"
#include <ESP8266WebServer.h>
#include <Ticker.h>


// these variables are set by the linker
extern "C" uint32_t _FS_start;
extern "C" uint32_t _FS_end;

//
static bool sys_update_is_ok = false; // indicates a successful update
static Ticker blink;

Expand All @@ -22,19 +29,15 @@ static const char update_html[] PROGMEM = R"html(<!DOCTYPE html>
<form method="POST" enctype="multipart/form-data">
<input type="file" name="data">
<input class="button" type="submit" value="Upload">
</form>
</body>
</html>)html";

extern "C" uint32_t _FS_start;
extern "C" uint32_t _FS_end;
</form></body></html>)html";

//
static void sys_update_finish(ESP8266WebServer &server, bool finish = false)
{
Serial.println(F("sys_update_finish"));
led_off();
blink.detach();
tinfo_pause = false;

if (Update.hasError())
{
Expand All @@ -56,7 +59,7 @@ static void sys_update_finish(ESP8266WebServer &server, bool finish = false)
//
void sys_update_register(ESP8266WebServer &server)
{
// page statique si on a perdu le filesystem...
// static page in case of filesystem loss
server.on(
"/update",
HTTP_GET,
Expand Down Expand Up @@ -106,13 +109,13 @@ void sys_update_register(ESP8266WebServer &server)
});

sys_update_is_ok = false;
int command = (upload.filename.indexOf("spiffs.bin") != -1) ? U_FS : U_FLASH;
int command = (upload.filename.indexOf("fs.bin") != -1) ? U_FS : U_FLASH;

// upload.contentLength is NOT the real upload size
uint32_t max_size;
if (command == U_FS)
{
// contentLength is a little above the authorized length
// contentLength is a little above the authorized length that should be exactly the FS size
max_size = (uint32_t)&_FS_end - (uint32_t)&_FS_start;
}
else
Expand Down Expand Up @@ -142,6 +145,10 @@ void sys_update_register(ESP8266WebServer &server)
Serial.printf("begin error %d %d\n", max_size, command);
sys_update_finish(server);
}
else
{
tinfo_pause = true;
}
}
else if (upload.status == UPLOAD_FILE_WRITE)
{
Expand Down

0 comments on commit a4cd3b6

Please sign in to comment.