Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
0d38a31
feat: implement module commands.
kakopappa Jul 5, 2024
dd9b676
feat: OTA and workflows
kakopappa Jul 6, 2024
297cef3
fix: OTA update for Picow
kakopappa Jul 6, 2024
f81ba13
chore: version update
kakopappa Jul 6, 2024
eb42b83
chore: remove get settings
kakopappa Jul 7, 2024
020bb09
chore: refactor settings example
kakopappa Jul 7, 2024
143b152
chore: comments updated
kakopappa Jul 7, 2024
2a7e714
chore: code refactor
kakopappa Jul 7, 2024
a168bac
fix: version
kakopappa Jul 7, 2024
4f08ab4
fix: add examples/OTAUpdate, examples/Settings
kakopappa Jul 7, 2024
6a7a708
fix: example
kakopappa Jul 7, 2024
edd3bd2
fix: OTA on esp32/esp8266/picow
kakopappa Jul 8, 2024
c1dcff2
fix: WiFi.config
kakopappa Jul 8, 2024
011d4be
fix: logging
kakopappa Jul 8, 2024
37784a5
fix: add esp32 dns lookup fix
kakopappa Jul 8, 2024
baa8582
feat: force update added.
kakopappa Jul 15, 2024
ace2b71
chore: refactor ota, setting examples
kakopappa Jul 15, 2024
be1cdf3
fix: esp8266 build errors
kakopappa Jul 15, 2024
78a252e
fix: exclude ota
kakopappa Jul 15, 2024
432fbfc
fix: build errors
kakopappa Jul 15, 2024
77700a3
fix: build errors
kakopappa Jul 15, 2024
6d1a699
fix: excluding settings due to PIO missing APlistClean in WiFi.h
kakopappa Jul 15, 2024
c469c89
fix: version
kakopappa Jul 17, 2024
c9b728e
feat: health
kakopappa Jul 17, 2024
5127881
fix: ids
kakopappa Jul 17, 2024
6c58983
fix: add health
kakopappa Jul 17, 2024
e0aee69
fix: support picow
kakopappa Jul 17, 2024
14ffbbe
fix: adding examples/Health
kakopappa Jul 17, 2024
bad84a2
chore: update debug message.
kakopappa Jul 17, 2024
7ee9960
fix: typo
kakopappa Jul 17, 2024
99dfcee
fix: remove MALLOC_CAP_SPIRAM
kakopappa Jul 20, 2024
31db09e
fix: split Cert to .cpp and .h
kakopappa Jul 20, 2024
e7fd5d4
fix: Update version comparison and OTA update response
kakopappa Jul 20, 2024
ffdbe01
fix: remove OTAResult
kakopappa Jul 20, 2024
027b897
fix: remove OTAResult
kakopappa Jul 20, 2024
040e8af
fix: ota update example
kakopappa Jul 20, 2024
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 .github/workflows/build-esp8266-esp32.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
example: [examples/ACUnit, examples/AirQualitySensor/AirQualitySensor, examples/Blinds, examples/ContactSensor, examples/DimSwitch, examples/doorbell, examples/Fan, examples/GarageDoor, examples/Light/Light, examples/Lock/Lock, examples/Lock/Lock_with_feedback, examples/MotionSensor, examples/PowerSensor, examples/Relay/MultiRelays_advance, examples/Relay/Relay, examples/Speaker, examples/Switch/MultiSwitch_advance, examples/Switch/MultiSwitch_beginner, examples/Switch/MultiSwitch_intermediate, examples/Switch/Switch, examples/Thermostat, examples/TV]
example: [examples/ACUnit, examples/AirQualitySensor/AirQualitySensor, examples/Blinds, examples/ContactSensor, examples/DimSwitch, examples/doorbell, examples/Fan, examples/GarageDoor, examples/Light/Light, examples/Lock/Lock, examples/Lock/Lock_with_feedback, examples/MotionSensor, examples/PowerSensor, examples/Relay/MultiRelays_advance, examples/Relay/Relay, examples/Speaker, examples/Switch/MultiSwitch_advance, examples/Switch/MultiSwitch_beginner, examples/Switch/MultiSwitch_intermediate, examples/Switch/Switch, examples/Thermostat, examples/TV, examples/OTAUpdate, examples/Health]

steps:

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build-rpipicow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
example: [examples/ACUnit, examples/AirQualitySensor/AirQualitySensor, examples/Blinds, examples/ContactSensor, examples/DimSwitch, examples/doorbell, examples/Fan, examples/GarageDoor, examples/Light/Light, examples/Lock/Lock, examples/Lock/Lock_with_feedback, examples/MotionSensor, examples/PowerSensor, examples/Relay/MultiRelays_advance, examples/Relay/Relay, examples/Speaker, examples/Switch/MultiSwitch_advance, examples/Switch/MultiSwitch_beginner, examples/Switch/MultiSwitch_intermediate, examples/Switch/Switch, examples/Thermostat, examples/TV]
example: [examples/ACUnit, examples/AirQualitySensor/AirQualitySensor, examples/Blinds, examples/ContactSensor, examples/DimSwitch, examples/doorbell, examples/Fan, examples/GarageDoor, examples/Light/Light, examples/Lock/Lock, examples/Lock/Lock_with_feedback, examples/MotionSensor, examples/PowerSensor, examples/Relay/MultiRelays_advance, examples/Relay/Relay, examples/Speaker, examples/Switch/MultiSwitch_advance, examples/Switch/MultiSwitch_beginner, examples/Switch/MultiSwitch_intermediate, examples/Switch/Switch, examples/Thermostat, examples/TV, examples/Health]

steps:
- name: Step 1 - Checkout Repo
Expand Down
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# Changelog
## Version 3.2.0
### New
- Support OTA Updates
- Module level command support for WiFi settings, ESP Health

## Version 3.1.0
Upgrade:
- Upgrade to ArduinoJson 7
Expand Down
98 changes: 98 additions & 0 deletions examples/Health/Health.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*
* Example for how to monitor ESP health.
*
* If you encounter any issues:
* - check the readme.md at https://github.com/sinricpro/esp8266-esp32-sdk/blob/master/README.md
* - ensure all dependent libraries are installed
* - see https://github.com/sinricpro/esp8266-esp32-sdk/blob/master/README.md#arduinoide
* - see https://github.com/sinricpro/esp8266-esp32-sdk/blob/master/README.md#dependencies
* - open serial monitor and check whats happening
* - check full user documentation at https://sinricpro.github.io/esp8266-esp32-sdk
* - visit https://github.com/sinricpro/esp8266-esp32-sdk/issues and check for existing issues or open a new one
*/

// Uncomment the following line to enable serial debug output
#define ENABLE_DEBUG

#ifdef ENABLE_DEBUG
#define DEBUG_ESP_PORT Serial
#define NODEBUG_WEBSOCKETS
#define NDEBUG
#endif

#include <Arduino.h>
#include <ArduinoJson.h>

#if defined(ESP8266)
#include <ESP8266WiFi.h>
#elif defined(ESP32)
#include <WiFi.h>
#endif

#include "SinricPro.h"
#include "SinricProSwitch.h"
#include "HealthDiagnostics.h"

#define WIFI_SSID "YOUR-WIFI-SSID"
#define WIFI_PASS "YOUR-WIFI-PASSWORD"
#define APP_KEY "YOUR-APP-KEY" // Should look like "de0bxxxx-1x3x-4x3x-ax2x-5dabxxxxxxxx"
#define APP_SECRET "YOUR-APP-SECRET" // Should look like "5f36xxxx-x3x7-4x3x-xexe-e86724a9xxxx-4c4axxxx-3x3x-x5xe-x9x3-333d65xxxxxx"
#define SWITCH_ID "YOUR-DEVICE-ID" // Should look like "5dc1564130xxxxxxxxxxxxxx"

#define BAUD_RATE 115200 // Change baudrate to your need

HealthDiagnostics healthDiagnostics;

// setup function for WiFi connection
void setupWiFi() {
Serial.printf("\r\n[Wifi]: Connecting");

#if defined(ESP8266)
WiFi.setSleepMode(WIFI_NONE_SLEEP);
WiFi.setAutoReconnect(true);
#elif defined(ESP32)
WiFi.setSleep(false);
WiFi.setAutoReconnect(true);
#endif

WiFi.begin(WIFI_SSID, WIFI_PASS);

while (WiFi.status() != WL_CONNECTED) {
Serial.printf(".");
delay(250);
}

Serial.printf("connected!\r\n[WiFi]: IP-Address is %s\r\n", WiFi.localIP().toString().c_str());
}

// setup function for SinricPro
void setupSinricPro() {
SinricProSwitch& mySwitch = SinricPro[SWITCH_ID];

// setup SinricPro
SinricPro.onConnected([]() {
Serial.printf("Connected to SinricPro\r\n");
});

SinricPro.onDisconnected([]() {
Serial.printf("Disconnected from SinricPro\r\n");
});

SinricPro.onReportHealth([&](String &healthReport) {
return healthDiagnostics.reportHealth(healthReport);
});

SinricPro.begin(APP_KEY, APP_SECRET);
}

// main setup function
void setup() {
Serial.begin(BAUD_RATE);
Serial.printf("\r\n\r\n");
setupWiFi();
setupSinricPro();
}

void loop() {
SinricPro.handle();
}
137 changes: 137 additions & 0 deletions examples/Health/HealthDiagnostics.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
#include "HealthDiagnostics.h"

String HealthDiagnostics::getChipId() {
#if defined(ESP32)
return String((uint32_t)ESP.getEfuseMac(), HEX);
#elif defined(ESP8266)
return String(ESP.getChipId(), HEX);
#elif defined(ARDUINO_ARCH_RP2040)
return String(rp2040.getChipID(), HEX);
#endif
}

void HealthDiagnostics::addHeapInfo(JsonObject& doc) {
#if defined(ESP32)
doc["freeHeap"] = ESP.getFreeHeap();
doc["totalHeap"] = ESP.getHeapSize();
doc["minFreeHeap"] = ESP.getMinFreeHeap();
doc["maxAllocHeap"] = ESP.getMaxAllocHeap();

multi_heap_info_t heap_info;
heap_caps_get_info(&heap_info, MALLOC_CAP_INTERNAL);

JsonObject internalHeap = doc["internalHeap"].to<JsonObject>();
internalHeap["totalFreeBytes"] = heap_info.total_free_bytes;
internalHeap["totalAllocatedBytes"] = heap_info.total_allocated_bytes;
internalHeap["largestFreeBlock"] = heap_info.largest_free_block;
internalHeap["minimumFreeBytes"] = heap_info.minimum_free_bytes;
internalHeap["allocatedBlocks"] = heap_info.allocated_blocks;
internalHeap["freeBlocks"] = heap_info.free_blocks;
internalHeap["totalBlocks"] = heap_info.total_blocks;

heap_caps_get_info(&heap_info, MALLOC_CAP_SPIRAM);

JsonObject psram = doc["psram"].to<JsonObject>();
psram["totalFreeBytes"] = heap_info.total_free_bytes;
psram["totalAllocatedBytes"] = heap_info.total_allocated_bytes;
psram["largestFreeBlock"] = heap_info.largest_free_block;
psram["minimumFreeBytes"] = heap_info.minimum_free_bytes;
psram["allocatedBlocks"] = heap_info.allocated_blocks;
psram["freeBlocks"] = heap_info.free_blocks;
psram["totalBlocks"] = heap_info.total_blocks;

#elif defined(ESP8266)
doc["freeHeap"] = ESP.getFreeHeap();
doc["heapFragmentation"] = ESP.getHeapFragmentation();
doc["maxFreeBlockSize"] = ESP.getMaxFreeBlockSize();

// Get detailed heap information.
JsonObject heapInfo = doc["heapInfo"].to<JsonObject>();
UMM_HEAP_INFO ummHeapInfo;
umm_info(&ummHeapInfo, 0);
heapInfo["freeBlocks"] = ummHeapInfo.freeBlocks;
heapInfo["usedBlocks"] = ummHeapInfo.usedBlocks;
heapInfo["totalBlocks"] = ummHeapInfo.totalBlocks;
heapInfo["totalEntries"] = ummHeapInfo.totalEntries;
heapInfo["usedEntries"] = ummHeapInfo.usedEntries;
heapInfo["freeEntries"] = ummHeapInfo.freeEntries;
heapInfo["maxFreeContiguousBytes"] = umm_max_block_size();

#elif defined(ARDUINO_ARCH_RP2040)
doc["freeHeap"] = rp2040.getFreeHeap();
doc["totalHeap"] = rp2040.getTotalHeap();
#endif
}

void HealthDiagnostics::addWiFiInfo(JsonObject& doc) {
doc["ssid"] = WiFi.SSID();

#if defined(ESP32) || defined(ESP8266)
doc["bssid"] = WiFi.BSSIDstr();
#endif

doc["rssi"] = WiFi.RSSI();
doc["ipAddress"] = WiFi.localIP().toString();
doc["subnetMask"] = WiFi.subnetMask().toString();
doc["gateway"] = WiFi.gatewayIP().toString();
doc["dns"] = WiFi.dnsIP().toString();
doc["macAddress"] = WiFi.macAddress();
doc["channel"] = WiFi.channel();
}

void HealthDiagnostics::addSketchInfo(JsonObject& doc) {
#if defined(ESP32) || defined(ESP8266)
doc["cpuFreq"] = ESP.getCpuFreqMHz();
doc["sketchSize"] = ESP.getSketchSize();
doc["freeSketchSpace"] = ESP.getFreeSketchSpace();
doc["flashChipSize"] = ESP.getFlashChipSize();
doc["flashChipSpeed"] = ESP.getFlashChipSpeed();
#endif
}

void HealthDiagnostics::addResetCause(JsonObject& doc) {
#if defined(ESP32)
switch (esp_reset_reason()) {
case ESP_RST_POWERON: doc["reason"] = "Power-on event"; break;
case ESP_RST_EXT: doc["reason"] = "External pin reset"; break;
case ESP_RST_SW: doc["reason"] = "Software reset via esp_restart"; break;
case ESP_RST_PANIC: doc["reason"] = "Software reset due to exception/panic"; break;
case ESP_RST_INT_WDT: doc["reason"] = "Reset (software or hardware) due to interrupt watchdog"; break;
case ESP_RST_TASK_WDT: doc["reason"] = "Reset due to task watchdog"; break;
case ESP_RST_WDT: doc["reason"] = "Reset due to other watchdogs"; break;
case ESP_RST_DEEPSLEEP: doc["reason"] = "Deep sleep reset"; break;
case ESP_RST_BROWNOUT: doc["reason"] = "Brownout reset"; break;
case ESP_RST_SDIO: doc["reason"] = "Reset over SDIO"; break;
default: doc["reason"] = "Unknown reset reason"; break;
}
#elif defined(ESP8266)
doc["reason"] = ESP.getResetReason();
#endif

//doc["crashDetails"] = "" // Use something like https://github.com/krzychb/EspSaveCrash
}

bool HealthDiagnostics::reportHealth(String& healthReport) {
JsonDocument doc;
doc["chipId"] = getChipId();
doc["uptime"] = millis() / 1000; // seconds

// Add detailed heap information.
JsonObject heap = doc["heap"].to<JsonObject>();
addHeapInfo(heap);

// Detailed Sketch information.
JsonObject sketch = doc["sketch"].to<JsonObject>();
addSketchInfo(sketch);

// Detailed WiFi information.
JsonObject wifi = doc["wifi"].to<JsonObject>();
addWiFiInfo(wifi);

// Add last reset reson
JsonObject resetInfo = doc["reset"].to<JsonObject>();
addResetCause(resetInfo);

serializeJson(doc, healthReport);
return true;
}
44 changes: 44 additions & 0 deletions examples/Health/HealthDiagnostics.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#ifndef HEALTH_DIAGNOSTICS_H
#define HEALTH_DIAGNOSTICS_H

#include <Arduino.h>
#include <ArduinoJson.h>

#if defined(ESP32)
#include <WiFi.h>
#include "esp_system.h"
#include <esp_wifi.h>
#include <esp_heap_caps.h>
#elif defined(ESP8266)
#include <ESP8266WiFi.h>
#include <user_interface.h>
extern "C" {
#include "umm_malloc/umm_heap_select.h"
#include "umm_malloc/umm_malloc.h"
}
#elif defined(ARDUINO_ARCH_RP2040)
#include <WiFi.h>
#endif

/**
* @brief Class to handle health diagnostics
*/
class HealthDiagnostics {
public:
/**
* @brief Report the health diagnostic information.
*
* @param healthReport A reference to a String to store the health report in JSON format.
* @return True on success, otherwise false.
*/
bool reportHealth(String& healthReport);

private:
String getChipId();
void addHeapInfo(JsonObject& doc);
void addWiFiInfo(JsonObject& doc);
void addSketchInfo(JsonObject& doc);
void addResetCause(JsonObject& doc);
};

#endif // HEALTH_DIAGNOSTICS_H
33 changes: 33 additions & 0 deletions examples/OTAUpdate/Cert.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include "Cert.h"

// Ref: https://projects.petrucci.ch/esp32/?page=ssl.php&url=otaupdates.sinric.pro


const char* rootCACertificate = R"EOF(
-----BEGIN CERTIFICATE-----
MIIEVzCCAj+gAwIBAgIRAIOPbGPOsTmMYgZigxXJ/d4wDQYJKoZIhvcNAQELBQAw
TzELMAkGA1UEBhMCVVMxKTAnBgNVBAoTIEludGVybmV0IFNlY3VyaXR5IFJlc2Vh
cmNoIEdyb3VwMRUwEwYDVQQDEwxJU1JHIFJvb3QgWDEwHhcNMjQwMzEzMDAwMDAw
WhcNMjcwMzEyMjM1OTU5WjAyMQswCQYDVQQGEwJVUzEWMBQGA1UEChMNTGV0J3Mg
RW5jcnlwdDELMAkGA1UEAxMCRTUwdjAQBgcqhkjOPQIBBgUrgQQAIgNiAAQNCzqK
a2GOtu/cX1jnxkJFVKtj9mZhSAouWXW0gQI3ULc/FnncmOyhKJdyIBwsz9V8UiBO
VHhbhBRrwJCuhezAUUE8Wod/Bk3U/mDR+mwt4X2VEIiiCFQPmRpM5uoKrNijgfgw
gfUwDgYDVR0PAQH/BAQDAgGGMB0GA1UdJQQWMBQGCCsGAQUFBwMCBggrBgEFBQcD
ATASBgNVHRMBAf8ECDAGAQH/AgEAMB0GA1UdDgQWBBSfK1/PPCFPnQS37SssxMZw
i9LXDTAfBgNVHSMEGDAWgBR5tFnme7bl5AFzgAiIyBpY9umbbjAyBggrBgEFBQcB
AQQmMCQwIgYIKwYBBQUHMAKGFmh0dHA6Ly94MS5pLmxlbmNyLm9yZy8wEwYDVR0g
BAwwCjAIBgZngQwBAgEwJwYDVR0fBCAwHjAcoBqgGIYWaHR0cDovL3gxLmMubGVu
Y3Iub3JnLzANBgkqhkiG9w0BAQsFAAOCAgEAH3KdNEVCQdqk0LKyuNImTKdRJY1C
2uw2SJajuhqkyGPY8C+zzsufZ+mgnhnq1A2KVQOSykOEnUbx1cy637rBAihx97r+
bcwbZM6sTDIaEriR/PLk6LKs9Be0uoVxgOKDcpG9svD33J+G9Lcfv1K9luDmSTgG
6XNFIN5vfI5gs/lMPyojEMdIzK9blcl2/1vKxO8WGCcjvsQ1nJ/Pwt8LQZBfOFyV
XP8ubAp/au3dc4EKWG9MO5zcx1qT9+NXRGdVWxGvmBFRAajciMfXME1ZuGmk3/GO
koAM7ZkjZmleyokP1LGzmfJcUd9s7eeu1/9/eg5XlXd/55GtYjAM+C4DG5i7eaNq
cm2F+yxYIPt6cbbtYVNJCGfHWqHEQ4FYStUyFnv8sjyqU8ypgZaNJ9aVcWSICLOI
E1/Qv/7oKsnZCWJ926wU6RqG1OYPGOi1zuABhLw61cuPVDT28nQS/e6z95cJXq0e
K1BcaJ6fJZsmbjRgD5p3mvEf5vdQM7MCEvU0tHbsx2I5mHHJoABHb8KVBgWp/lcX
GWiWaeOyB7RP+OfDtvi2OsapxXiV7vNVs7fMlrRjY1joKaqmmycnBvAq14AEbtyL
sVfOS66B8apkeFX2NY4XPEYV4ZSCe8VHPrdrERk2wILG3T/EGmSIkCYVUMSnjmJd
VQD9F6Na/+zmXCc=
-----END CERTIFICATE-----
)EOF";
3 changes: 3 additions & 0 deletions examples/OTAUpdate/Cert.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#pragma once

extern const char* rootCACertificate;
Loading