Merge pull request #692 from cyberman54/development

Development
This commit is contained in:
Verkehrsrot 2020-12-26 18:29:55 +01:00 committed by GitHub
commit ec538495d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 46 additions and 30 deletions

View File

@ -113,16 +113,17 @@ String BintrayClient::getLatestVersion() const
ESP_LOGE(TAG, "Error: Firmware version data invalid.");
return version;
}
StaticJsonBuffer<bufferSize> jsonBuffer;
StaticJsonDocument<bufferSize> doc;
DeserializationError err = deserializeJson(doc, jsonResult.c_str());
JsonObject &root = jsonBuffer.parseObject(jsonResult.c_str());
// Check for errors in parsing
if (!root.success())
if (err)
{
ESP_LOGE(TAG, "Error: Firmware version data not found.");
return version;
}
return root.get<String>("name");
return doc["name"].as<String>();
}
String BintrayClient::getBinaryPath(const String &version) const
@ -137,14 +138,15 @@ String BintrayClient::getBinaryPath(const String &version) const
ESP_LOGE(TAG, "Error: Firmware download path data invalid.");
return path;
}
StaticJsonBuffer<bufferSize> jsonBuffer;
StaticJsonDocument<bufferSize> doc;
JsonArray &root = jsonBuffer.parseArray(jsonResult.c_str());
JsonObject &firstItem = root[0];
if (!root.success())
DeserializationError err = deserializeJson(doc, jsonResult.c_str());
JsonObject firstItem = doc[0];
if (err)
{ //Check for errors in parsing
ESP_LOGE(TAG, "Error: Firmware download path not found.");
return path;
}
return "/" + getUser() + "/" + getRepository() + "/" + firstItem.get<String>("path");
return "/" + getUser() + "/" + getRepository() + "/" + firstItem["path"].as<String>();
}

View File

@ -79,7 +79,7 @@ lib_deps_sensors =
boschsensortec/BSEC Software Library @ 1.6.1480
https://github.com/ricki-z/SDS011.git
lib_deps_basic =
bblanchon/ArduinoJson @ <6
bblanchon/ArduinoJson @ ^6
jchristensen/Timezone @ ^1.2.4
makuna/RTC @ ^2.3.5
spacehuhn/SimpleButton

View File

@ -251,10 +251,11 @@ uint8_t read_battlevel(mapFn_t mapFunction) {
bool batt_sufficient() {
#if (defined HAS_PMU || defined BAT_MEASURE_ADC || defined HAS_IP5306)
return (batt_level > OTA_MIN_BATT);
#else
return true; // we don't know batt level
if (batt_level) // we have a battery voltage
return (batt_level > OTA_MIN_BATT);
else
#endif
return true; // we don't know batt level
}
#ifdef HAS_IP5306

View File

@ -9,7 +9,7 @@ static const char TAG[] = __FILE__;
#define uS_TO_S_FACTOR 1000000ULL
// variables keep its values after a wakeup from sleep
RTC_DATA_ATTR runmode_t RTC_runmode = RUNMODE_POWERCYCLE;
RTC_NOINIT_ATTR runmode_t RTC_runmode = RUNMODE_POWERCYCLE;
RTC_DATA_ATTR struct timeval RTC_sleep_start_time;
RTC_DATA_ATTR unsigned long long RTC_millis = 0;
timeval sleep_stop_time;
@ -36,14 +36,20 @@ void do_after_reset(void) {
struct timeval sleep_stop_time;
uint64_t sleep_time_ms;
switch (esp_sleep_get_wakeup_cause()) {
case ESP_SLEEP_WAKEUP_EXT0: // Wakeup caused by external signal using RTC_IO
case ESP_SLEEP_WAKEUP_EXT1: // Wakeup caused by external signal using
// RTC_CNTL
case ESP_SLEEP_WAKEUP_TIMER: // Wakeup caused by timer
case ESP_SLEEP_WAKEUP_TOUCHPAD: // Wakeup caused by touchpad
case ESP_SLEEP_WAKEUP_ULP: // Wakeup caused by ULP program
switch (rtc_get_reset_reason(0)) {
case POWERON_RESET: // 0x01 Vbat power on reset
case RTCWDT_BROWN_OUT_RESET: // 0x0f Reset when the vdd voltage is not
// stable
RTC_runmode = RUNMODE_POWERCYCLE;
break;
case SW_CPU_RESET: // 0x0c Software reset CPU
// keep previous runmode (could be RUNMODE_UPDATE)
break;
case DEEPSLEEP_RESET: // 0x05 Deep Sleep reset digital core
RTC_runmode = RUNMODE_WAKEUP;
// calculate time spent in deep sleep
gettimeofday(&sleep_stop_time, NULL);
sleep_time_ms =
@ -51,19 +57,23 @@ void do_after_reset(void) {
(sleep_stop_time.tv_usec - RTC_sleep_start_time.tv_usec) / 1000;
ESP_LOGI(TAG, "Time spent in deep sleep: %d ms", sleep_time_ms);
RTC_millis += sleep_time_ms; // increment system monotonic time
RTC_runmode = RUNMODE_WAKEUP;
break;
case ESP_SLEEP_WAKEUP_ALL:
case ESP_SLEEP_WAKEUP_GPIO:
case ESP_SLEEP_WAKEUP_UART:
case ESP_SLEEP_WAKEUP_UNDEFINED:
case SW_RESET: // 0x03 Software reset digital core
case OWDT_RESET: // 0x04 Legacy watch dog reset digital core
case SDIO_RESET: // 0x06 Reset by SLC module, reset digital core
case TG0WDT_SYS_RESET: // 0x07 Timer Group0 Watch dog reset digital core
case TG1WDT_SYS_RESET: // 0x08 Timer Group1 Watch dog reset digital core
case RTCWDT_SYS_RESET: // 0x09 RTC Watch dog Reset digital core
case INTRUSION_RESET: // 0x0a Instrusion tested to reset CPU
case TGWDT_CPU_RESET: // 0x0b Time Group reset CPU
case RTCWDT_CPU_RESET: // 0x0d RTC Watch dog Reset CPU
case EXT_CPU_RESET: // 0x0e for APP CPU, reseted by PRO CPU
case RTCWDT_RTC_RESET: // 0x10 RTC Watch dog reset digital core and rtc mode
default:
// not a deep sleep reset
RTC_runmode = RUNMODE_POWERCYCLE;
break;
} // switch
}
ESP_LOGI(TAG, "Starting Software v%s, runmode %s", PROGVERSION,
runmode[RTC_runmode]);
@ -72,6 +82,7 @@ void do_after_reset(void) {
void enter_deepsleep(const uint64_t wakeup_sec = 60,
gpio_num_t wakeup_gpio = GPIO_NUM_MAX) {
// don't go to sleep while unjoined
#if (HAS_LORA)
if (!LMIC.devaddr) {
ESP_LOGI(TAG, "Can't go to sleep while joining");
@ -162,9 +173,11 @@ void enter_deepsleep(const uint64_t wakeup_sec = 60,
dp_shutdown();
#endif
// reduce power if has PMU
// reduce power if has PMU or VEXT
#ifdef HAS_PMU
AXP192_power(pmu_power_sleep);
#elif EXT_POWER_SW
digitalWrite(EXT_POWER_SW, EXT_POWER_OFF);
#endif
// shutdown i2c bus