Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OTA Error #41

Merged
merged 3 commits into from
Feb 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion firmware/version.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"version": "2.2.1"}
{"version": "2.2.2"}
36 changes: 22 additions & 14 deletions json_models/Config JSON.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
},
"dospiffs1": false,
"dospiffs2": false,
"didupdate": false
"didupdate": false,
"nodrd": false
}
```

Expand All @@ -51,18 +52,24 @@ const size_t capacity = 3*JSON_OBJECT_SIZE(2) + JSON_OBJECT_SIZE(3) + 3*JSON_OBJ
512+728 = 1240
```

## Parsing:
## Deserializing:

```
const size_t capacity = 3*JSON_OBJECT_SIZE(2) + JSON_OBJECT_SIZE(3) + 3*JSON_OBJECT_SIZE(4) + JSON_OBJECT_SIZE(11) + 810;
DynamicJsonDocument doc(capacity);
// char* input;
// size_t inputLength; (optional)

StaticJsonDocument<768> doc;

const char* json = "{\"apconfig\":{\"ssid\":\"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\",\"passphrase\":\"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\"},\"hostname\":\"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\",\"bubble\":{\"name\":\"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\",\"tempinf\":false},\"calibrate\":{\"room\":-999.9999,\"vessel\":-999.9999},\"urltarget\":{\"url\":\"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\",\"freq\":999,\"update\":false},\"brewersfriend\":{\"key\":\"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\",\"channel\":0,\"freq\":9999,\"update\":false},\"brewfather\":{\"key\":\"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\",\"channel\":0,\"freq\":9999,\"update\":false},\"thingspeak\":{\"key\":\"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\",\"channel\":999999999,\"freq\":9999,\"update\":false},\"dospiffs1\":false,\"dospiffs2\":false,\"didupdate\":false}";
DeserializationError error = deserializeJson(doc, input, inputLength);

deserializeJson(doc, json);
if (error) {
Serial.print(F("deserializeJson() failed: "));
Serial.println(error.f_str());
return;
}

const char* apconfig_ssid = doc["apconfig"]["ssid"]; // "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
const char* apconfig_passphrase = doc["apconfig"]["passphrase"]; // "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
const char* apconfig_passphrase = doc["apconfig"]["passphrase"];

const char* hostname = doc["hostname"]; // "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

Expand All @@ -73,38 +80,38 @@ float calibrate_room = doc["calibrate"]["room"]; // -999.9999
float calibrate_vessel = doc["calibrate"]["vessel"]; // -999.9999

JsonObject urltarget = doc["urltarget"];
const char* urltarget_url = urltarget["url"]; // "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
const char* urltarget_url = urltarget["url"];
int urltarget_freq = urltarget["freq"]; // 999
bool urltarget_update = urltarget["update"]; // false

JsonObject brewersfriend = doc["brewersfriend"];
const char* brewersfriend_key = brewersfriend["key"]; // "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
const char* brewersfriend_key = brewersfriend["key"];
int brewersfriend_channel = brewersfriend["channel"]; // 0
int brewersfriend_freq = brewersfriend["freq"]; // 9999
bool brewersfriend_update = brewersfriend["update"]; // false

JsonObject brewfather = doc["brewfather"];
const char* brewfather_key = brewfather["key"]; // "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
const char* brewfather_key = brewfather["key"];
int brewfather_channel = brewfather["channel"]; // 0
int brewfather_freq = brewfather["freq"]; // 9999
bool brewfather_update = brewfather["update"]; // false

JsonObject thingspeak = doc["thingspeak"];
const char* thingspeak_key = thingspeak["key"]; // "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
const char* thingspeak_key = thingspeak["key"];
long thingspeak_channel = thingspeak["channel"]; // 999999999
int thingspeak_freq = thingspeak["freq"]; // 9999
bool thingspeak_update = thingspeak["update"]; // false

bool dospiffs1 = doc["dospiffs1"]; // false
bool dospiffs2 = doc["dospiffs2"]; // false
bool didupdate = doc["didupdate"]; // false
bool nodrd = doc["nodrd"]; // false
```

## Serializing:

```
const size_t capacity = 3*JSON_OBJECT_SIZE(2) + JSON_OBJECT_SIZE(3) + 3*JSON_OBJECT_SIZE(4) + JSON_OBJECT_SIZE(11);
DynamicJsonDocument doc(capacity);
DynamicJsonDocument doc(1536);

JsonObject apconfig = doc.createNestedObject("apconfig");
apconfig["ssid"] = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
Expand Down Expand Up @@ -144,6 +151,7 @@ thingspeak["update"] = false;
doc["dospiffs1"] = false;
doc["dospiffs2"] = false;
doc["didupdate"] = false;
doc["nodrd"] = false;

serializeJson(doc, Serial);
serializeJson(doc, output);
```
35 changes: 20 additions & 15 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,39 @@ platform = espressif8266
build_unflags =
build_flags =
!python tools\git_rev.py
-D PIO_SRC_TAG=2.2.1
-D PIO_SRC_TAG=2.2.2
-D BAUD=${common_env_data.monitor_speed}
; -DDEBUG_ESP_PORT=Serial
; -DDEBUG_ESP_WIFI
; -DDEBUG_ESP_HTTP_UPDATE
; -DDEBUG_ESP_CORE
; -DPIO_FRAMEWORK_ARDUINO_LWIP2_LOW_MEMORY ; v2 Lower Memory (default)
; -DPIO_FRAMEWORK_ARDUINO_LWIP2_HIGHER_BANDWIDTH ; v2 Higher Bandwidth
; -DPIO_FRAMEWORK_ARDUINO_LWIP2_LOW_MEMORY_LOW_FLASH ; v2 Lower Memory (no features)
; -DPIO_FRAMEWORK_ARDUINO_LWIP2_HIGHER_BANDWIDTH_LOW_FLASH ; v2 Higher Bandwidth (no features)
; -DPIO_FRAMEWORK_ARDUINO_LWIP2_IPV6_LOW_MEMORY ; v2 IPv6 Lower Memory
; -DPIO_FRAMEWORK_ARDUINO_LWIP2_IPV6_HIGHER_BANDWIDTH ; v2 IPv6 Higher Bandwidth
; -DPIO_FRAMEWORK_ARDUINO_LWIP_HIGHER_BANDWIDTH ; v1.4 Higher Bandwidth
-DDEBUG_ESP_PORT=Serial
; -D DEBUG_ESP_WIFI
; -D DEBUG_ESP_HTTP_UPDATE
; -D DEBUG_ESP_HTTP_CLIENT
; -D DEBUG_ESP_UPDATE
; -D DEBUG_ESP_OTA
; -D DEBUG_ESP_OOM
; -include "umm_malloc/umm_malloc_cfg.h"
; -D DEBUG_ESP_CORE
; -D PIO_FRAMEWORK_ARDUINO_LWIP2_LOW_MEMORY ; v2 Lower Memory (default)
; -D PIO_FRAMEWORK_ARDUINO_LWIP2_HIGHER_BANDWIDTH ; v2 Higher Bandwidth
; -D PIO_FRAMEWORK_ARDUINO_LWIP2_LOW_MEMORY_LOW_FLASH ; v2 Lower Memory (no features)
; -D PIO_FRAMEWORK_ARDUINO_LWIP2_HIGHER_BANDWIDTH_LOW_FLASH ; v2 Higher Bandwidth (no features)
; -D PIO_FRAMEWORK_ARDUINO_LWIP2_IPV6_LOW_MEMORY ; v2 IPv6 Lower Memory
; -D PIO_FRAMEWORK_ARDUINO_LWIP2_IPV6_HIGHER_BANDWIDTH ; v2 IPv6 Higher Bandwidth
-D PIO_FRAMEWORK_ARDUINO_LWIP_HIGHER_BANDWIDTH ; v1.4 Higher Bandwidth
extra_scripts = ; pre:python tools\name_firmware.py
lib_deps =
ArduinoJson
https://github.com/lbussy/OneWire.git
https://github.com/lbussy/DS18B20.git
https://github.com/lbussy/Arduino-Log.git
https://github.com/lbussy/ESPAsyncWebServer.git#littlefs
https://github.com/lbussy/ESPAsyncWebServer.git
https://github.com/lbussy/AsyncWiFiManager.git
https://github.com/lbussy/ESPAsyncTCP
https://github.com/lbussy/asyncHTTPrequest.git
https://github.com/lbussy/CircularBuffer.git
https://github.com/lbussy/LCBUrl.git
https://github.com/lbussy/esptelnet.git
ESP_DoubleResetDetector
ThingSpeak
https://github.com/lbussy/ESP_DoubleResetDetector
https://github.com/lbussy/ThingSpeak
monitor_filters =
esp8266_exception_decoder
; log2file
Expand Down
25 changes: 16 additions & 9 deletions src/execota.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ void execfw()
ESPhttpUpdate.setLedPin(LED, LOW);
// "http://www.brewbubbles.com/firmware/firmware.bin"
WiFiClient _client;
Log.verbose(F("Pulling Firmware from: %s" CR), F(FIRMWAREURL));
config.nodrd = true;
saveConfig();
t_httpUpdate_return ret = ESPhttpUpdate.update(_client, F(FIRMWAREURL), "0");

switch (ret)
Expand All @@ -48,7 +51,9 @@ void execfw()
config.dospiffs1 = false;
config.dospiffs2 = false;
config.didupdate = false;
config.nodrd = true;
saveConfig();
_delay(100);
ESP.restart();
break;

Expand All @@ -58,16 +63,20 @@ void execfw()
config.dospiffs1 = false;
config.dospiffs2 = false;
config.didupdate = false;
config.nodrd = true;
saveConfig();
_delay(100);
ESP.restart();
break;

case HTTP_UPDATE_OK:
// We should never actually reach this as the controller
// resets after OTA
Log.notice(F("HTTP Firmware OTA Update complete, restarting." CR));
config.nodrd = true;
saveConfig();
_delay(100);
ESP.restart();
_delay(1000);
break;
}
}
Expand All @@ -80,13 +89,10 @@ void execspiffs()
config.dospiffs1 = false;
config.dospiffs2 = true;
config.didupdate = false;
config.nodrd = true;
saveConfig();
_delay(3000);
if (LittleFS.begin())
if (LittleFS.remove("/drd.dat"))
Log.notice(F("Deleted DRD semaphore." CR));
_delay(100);
ESP.restart();
_delay(1000);
}
else if (config.dospiffs2)
{
Expand All @@ -98,6 +104,7 @@ void execspiffs()
ESPhttpUpdate.setLedPin(LED, LOW);
// "http://www.brewbubbles.com/firmware/spiffs.bin"
WiFiClient client;
Log.verbose(F("Pulling Filesystem from: %s" CR), F(LITTLEFSURL));
t_httpUpdate_return ret = ESPhttpUpdate.updateFS(client, F(LITTLEFSURL), "");

switch (ret)
Expand All @@ -115,11 +122,11 @@ void execspiffs()
config.dospiffs1 = false;
config.dospiffs2 = false;
config.didupdate = true;
saveConfig(); // This not only saves the flags, it (re)saves the whole config after File System wipes it
_delay(1000);
config.nodrd = true;
Log.notice(F("HTTP File System OTA Update complete, restarting." CR));
saveConfig(); // This not only saves the flags, it (re)saves the whole config after File System wipes it
_delay(100);
ESP.restart();
_delay(1000);
break;
}
}
Expand Down
15 changes: 13 additions & 2 deletions src/jsonconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ SOFTWARE. */
const char *filename = "/config.json";
Config config;

extern const size_t capacitySerial = 3 * JSON_OBJECT_SIZE(2) + JSON_OBJECT_SIZE(3) + 3 * JSON_OBJECT_SIZE(4) + JSON_OBJECT_SIZE(11);
extern const size_t capacityDeserial = capacitySerial + 810;
extern const size_t capacitySerial = 1536;
extern const size_t capacityDeserial = 768;

bool deleteConfigFile()
{
Expand Down Expand Up @@ -478,6 +478,15 @@ void Config::load(JsonObjectConst obj)
{
didupdate = obj["didupdate"];
}

if (obj["nodrd"].isNull())
{
nodrd = false;
}
else
{
nodrd = obj["nodrd"];
}
}

void Config::save(JsonObject obj) const
Expand All @@ -504,4 +513,6 @@ void Config::save(JsonObject obj) const
obj["dospiffs2"] = dospiffs2;
// Add dospiffs1 object
obj["didupdate"] = didupdate;
// Add nodrd object
obj["nodrd"] = nodrd;
}
1 change: 1 addition & 0 deletions src/jsonconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ struct Config
bool dospiffs1;
bool dospiffs2;
bool didupdate;
bool nodrd;

void load(JsonObjectConst);
void save(JsonObject) const;
Expand Down
3 changes: 2 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,15 @@ void setup()
Log.notice(F("%s low, presenting portal." CR), stringify(RESETWIFI));
doWiFi(true);
}
else if (drd->detectDoubleReset())
else if (!config.nodrd && drd->detectDoubleReset())
{
Log.notice(F("DRD: Triggered, presenting portal." CR));
doWiFi(true);
}
else
{
Log.verbose(F("DRD: Normal boot." CR));
config.nodrd = false;
doWiFi();
}

Expand Down
2 changes: 1 addition & 1 deletion src/thingSpeakWork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ int createChannel(
channelJSON = http.getString();

#ifdef PRINT_DEBUG_MESSAGES
Serial.println(F("DEBUG: Create ThingSpeak Channel results:"));
Serial.println(F("Create ThingSpeak Channel results:"));
Serial.println(httpCode); //Print HTTP return code
Serial.println(channelJSON); //Print request response payload
#endif
Expand Down
6 changes: 6 additions & 0 deletions src/tools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ void resetController()
Log.notice(F("Reboot request - rebooting system." CR));
_delay(5000);
saveBpm();
config.nodrd = true;
saveConfig();
_delay(100);
ESP.restart();
}

Expand Down Expand Up @@ -137,6 +140,9 @@ void maintenanceLoop()
// The ms clock will rollover after ~49 days. To be on the safe side,
// restart the ESP after about 42 days to reset the ms clock.
Log.warning(F("Maintenance: Six week routine restart."));
config.nodrd = true;
saveConfig();
_delay(100);
ESP.restart();
}
if (lastNTPUpdate > NTPRESET)
Expand Down
7 changes: 6 additions & 1 deletion src/wifihandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,10 @@ void doWiFi(bool dontUseStoredCreds)
_delay(3000);
digitalWrite(LED, HIGH);
Log.warning(F("Restarting." CR));
config.nodrd = true;
saveConfig();
_delay(100);
ESP.restart();
_delay(1000); // Just a hack to give it time to reset
}
else
{
Expand Down Expand Up @@ -178,6 +180,9 @@ void resetWifi()
blinker.detach(); // Turn off blinker
digitalWrite(LED, LOW); // Turn on LED
Log.notice(F("Restarting after clearing WiFi settings." CR));
config.nodrd = true;
saveConfig();
_delay(100);
ESP.restart();
}

Expand Down