Skip to content

Commit

Permalink
mathieucarbou/MycilaSystem @ 3.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieucarbou committed Sep 27, 2024
1 parent 1381dd0 commit 4f8604a
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 116 deletions.
3 changes: 0 additions & 3 deletions include/YaSolRWebsite.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,6 @@ namespace YaSolR {
Statistic _relay1SwitchCount = Statistic(&dashboard, YASOLR_LBL_032);
Statistic _relay2SwitchCount = Statistic(&dashboard, YASOLR_LBL_033);

Statistic _zcdPulseLength = Statistic(&dashboard, YASOLR_LBL_187);
Statistic _zcdPulsePeriod = Statistic(&dashboard, YASOLR_LBL_185);

Statistic _time = Statistic(&dashboard, YASOLR_LBL_034);
Statistic _uptime = Statistic(&dashboard, YASOLR_LBL_035);
#ifdef APP_MODEL_TRIAL
Expand Down
4 changes: 2 additions & 2 deletions include/i18n/en.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,9 @@
#define YASOLR_LBL_182 YASOLR_LBL_070 " " YASOLR_LBL_048 " MQTT Topic"
#define YASOLR_LBL_183 YASOLR_LBL_046 " Dimmer Min/Max Remapping"
#define YASOLR_LBL_184 YASOLR_LBL_070 " Dimmer Min/Max Remapping"
#define YASOLR_LBL_185 "ZCD: Measured Pulse Period"
#define YASOLR_LBL_185
#define YASOLR_LBL_186 "Resistance Value Detection"
#define YASOLR_LBL_187 "ZCD: Measured Pulse Length"
#define YASOLR_LBL_187
#define YASOLR_LBL_030 "Relay: " YASOLR_LBL_046 " Bypass Relay Switch Count"
#define YASOLR_LBL_031 "Relay: " YASOLR_LBL_070 " Bypass Relay Switch Count"
#define YASOLR_LBL_032 "Relay: " YASOLR_LBL_074 " Switch Count"
Expand Down
4 changes: 2 additions & 2 deletions include/i18n/fr.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,9 @@
#define YASOLR_LBL_182 "Topic MQTT pour la température sortie 2"
#define YASOLR_LBL_183 "Redéfinition Min/Max Variateur Sortie 1"
#define YASOLR_LBL_184 "Redéfinition Min/Max Variateur Sortie 2"
#define YASOLR_LBL_185 "ZCD: Période mesurée des pulses"
#define YASOLR_LBL_185
#define YASOLR_LBL_186 "Détection valeur résistances"
#define YASOLR_LBL_187 "ZCD: Longueur mesurée des pulses"
#define YASOLR_LBL_187
#define YASOLR_LBL_188 "Adresse IP statique"
#define YASOLR_LBL_189 "Masque de sous-réseau"
#define YASOLR_LBL_190 "Passerelle"
Expand Down
2 changes: 1 addition & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ lib_deps =
mathieucarbou/MycilaPulseAnalyzer @ 2.3.4
mathieucarbou/MycilaPZEM004Tv3 @ 4.0.7
mathieucarbou/MycilaRelay @ 4.0.1
mathieucarbou/MycilaSystem @ 3.0.3
mathieucarbou/MycilaSystem @ 3.1.0
mathieucarbou/MycilaTaskManager @ 3.1.2
mathieucarbou/MycilaTaskMonitor @ 3.0.1
mathieucarbou/MycilaTrafficLight @ 1.0.0
Expand Down
6 changes: 2 additions & 4 deletions src/Website.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,6 @@ void YaSolR::WebsiteClass::initCards() {
_deviceCores.set(String(ESP.getChipCores()).c_str());
_deviceModel.set(ESP.getChipModel());
_deviceRev.set(String(ESP.getChipRevision()).c_str());
_deviceHeapTotal.set((String(ESP.getHeapSize()) + " bytes").c_str());
_deviceID.set(Mycila::AppInfo.id.c_str());
_firmwareBuildHash.set(Mycila::AppInfo.buildHash.c_str());
_firmwareBuildTimestamp.set(Mycila::AppInfo.buildDate.c_str());
Expand Down Expand Up @@ -779,8 +778,9 @@ void YaSolR::WebsiteClass::updateCards() {
Mycila::ESPConnect::Mode mode = espConnect.getMode();
_output1RelaySwitchCount.set(String(bypassRelayO1.getSwitchCount()).c_str());
_output2RelaySwitchCount.set(String(bypassRelayO2.getSwitchCount()).c_str());
_deviceHeapUsage.set((String(memory.usage) + " %").c_str());
_deviceHeapTotal.set((String(memory.total) + " bytes").c_str());
_deviceHeapUsed.set((String(memory.used) + " bytes").c_str());
_deviceHeapUsage.set((String(memory.usage) + " %").c_str());
_gridEnergy.set((String(gridMetrics.energy, 3) + " kWh").c_str());
_gridEnergyReturned.set((String(gridMetrics.energyReturned, 3) + " kWh").c_str());
_gridFrequency.set((String(detectGridFrequency(), 0) + " Hz").c_str());
Expand All @@ -794,8 +794,6 @@ void YaSolR::WebsiteClass::updateCards() {
_relay1SwitchCount.set(String(relay1.getSwitchCount()).c_str());
_relay2SwitchCount.set(String(relay2.getSwitchCount()).c_str());
_udpMessageRateBuffer.set((String(udpMessageRateBuffer.rate()) + " msg/s").c_str());
_zcdPulsePeriod.set((String(pulseAnalyzer.getPeriod()) + " us").c_str());
_zcdPulseLength.set((String(pulseAnalyzer.getWidth()) + " us").c_str());
_time.set(Mycila::Time::getLocalStr().c_str());
_uptime.set(Mycila::Time::toDHHMMSS(Mycila::System::getUptime()).c_str());
#ifdef APP_MODEL_TRIAL
Expand Down
209 changes: 108 additions & 101 deletions src/init/REST.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,63 +10,6 @@

#include <map>

static void systemInfoToJson(JsonObject& root) {
Mycila::System::Memory memory;
Mycila::System::getMemory(memory);

root["app"]["manufacturer"] = Mycila::AppInfo.manufacturer;
root["app"]["model"] = Mycila::AppInfo.model;
root["app"]["name"] = Mycila::AppInfo.name;
root["app"]["version"] = Mycila::AppInfo.version;

root["device"]["boots"] = Mycila::System::getBootCount();
root["device"]["cores"] = ESP.getChipCores();
root["device"]["cpu_freq"] = ESP.getCpuFreqMHz();
root["device"]["heap"]["total"] = memory.total;
root["device"]["heap"]["usage"] = memory.usage;
root["device"]["heap"]["used"] = memory.used;
root["device"]["id"] = Mycila::AppInfo.id;
root["device"]["model"] = ESP.getChipModel();
root["device"]["revision"] = ESP.getChipRevision();
root["device"]["uptime"] = Mycila::System::getUptime();

root["firmware"]["build"]["branch"] = Mycila::AppInfo.buildBranch;
root["firmware"]["build"]["hash"] = Mycila::AppInfo.buildHash;
root["firmware"]["build"]["timestamp"] = Mycila::AppInfo.buildDate;
root["firmware"]["debug"] = Mycila::AppInfo.debug;
root["firmware"]["filename"] = Mycila::AppInfo.firmware;

root["network"]["eth"]["ip_address"] = espConnect.getIPAddress(Mycila::ESPConnect::Mode::ETH).toString();
root["network"]["eth"]["mac_address"] = espConnect.getMACAddress(Mycila::ESPConnect::Mode::ETH);

root["network"]["hostname"] = espConnect.getHostname();
root["network"]["ip_address"] = espConnect.getIPAddress().toString();
root["network"]["mac_address"] = espConnect.getMACAddress();
switch (espConnect.getMode()) {
case Mycila::ESPConnect::Mode::ETH:
root["network"]["mode"] = "eth";
break;
case Mycila::ESPConnect::Mode::STA:
root["network"]["mode"] = "wifi";
break;
case Mycila::ESPConnect::Mode::AP:
root["network"]["mode"] = "ap";
break;
default:
root["network"]["mode"] = "";
break;
}

root["network"]["ntp"] = YASOLR_STATE(Mycila::NTP.isSynced());

root["network"]["wifi"]["bssid"] = espConnect.getWiFiBSSID();
root["network"]["wifi"]["ip_address"] = espConnect.getIPAddress(Mycila::ESPConnect::Mode::STA).toString();
root["network"]["wifi"]["mac_address"] = espConnect.getMACAddress(Mycila::ESPConnect::Mode::STA);
root["network"]["wifi"]["quality"] = espConnect.getWiFiSignalQuality();
root["network"]["wifi"]["rssi"] = espConnect.getWiFiRSSI();
root["network"]["wifi"]["ssid"] = espConnect.getWiFiSSID();
}

Mycila::Task initRestApiTask("Init REST API", [](void* params) {
logger.info(TAG, "Initializing REST API");

Expand All @@ -80,70 +23,79 @@ Mycila::Task initRestApiTask("Init REST API", [](void* params) {

AsyncJsonResponse* response = new AsyncJsonResponse();
JsonObject root = response->getRoot();
float voltage = grid.getVoltage().value_or(0);

Mycila::AppInfo.toJson(root["app"].to<JsonObject>());
config.toJson(root["config"].to<JsonObject>());
grid.toJson(root["grid"].to<JsonObject>());
jsy.toJson(root["jsy"].to<JsonObject>());
pulseAnalyzer.toJson(root["pulse_analyzer"].to<JsonObject>());
pidController.toJson(root["pid"].to<JsonObject>());
espConnect.toJson(root["network"].to<JsonObject>());

// router
float voltage = grid.getVoltage().value_or(0);
router.toJson(root["router"].to<JsonObject>(), voltage);
// output 1
output1.toJson(root["output1"].to<JsonObject>(), voltage);
output2.toJson(root["output2"].to<JsonObject>(), voltage);
dimmerO1.dimmerToJson(root["output1"]["dimmer"].to<JsonObject>());
dimmerO2.dimmerToJson(root["output2"]["dimmer"].to<JsonObject>());
ds18O1.toJson(root["output1"]["ds18"].to<JsonObject>());
ds18O2.toJson(root["output2"]["ds18"].to<JsonObject>());
pzemO1.toJson(root["output1"]["pzem"].to<JsonObject>());
pzemO2.toJson(root["output2"]["pzem"].to<JsonObject>());
bypassRelayO1.toJson(root["output1"]["relay"].to<JsonObject>());

// output 2
output2.toJson(root["output2"].to<JsonObject>(), voltage);
dimmerO2.dimmerToJson(root["output2"]["dimmer"].to<JsonObject>());
ds18O2.toJson(root["output2"]["ds18"].to<JsonObject>());
pzemO2.toJson(root["output2"]["pzem"].to<JsonObject>());
bypassRelayO2.toJson(root["output2"]["relay"].to<JsonObject>());

pidController.toJson(root["pid"].to<JsonObject>());
pulseAnalyzer.toJson(root["pulse_analyzer"].to<JsonObject>());

// relays
relay1.toJson(root["relay1"].to<JsonObject>());
relay2.toJson(root["relay2"].to<JsonObject>());

systemInfoToJson(root);
ds18Sys.toJson(root["ds18_sys"].to<JsonObject>());
lights.toJson(root["leds"].to<JsonObject>());
// router
router.toJson(root["router"].to<JsonObject>(), voltage);

// system
JsonObject system = root["system"].to<JsonObject>();
Mycila::System::toJson(system);
ds18Sys.toJson(system["ds18"].to<JsonObject>());
lights.toJson(system["leds"].to<JsonObject>());

// stack
Mycila::TaskMonitor.toJson(root["stack"].to<JsonObject>());
Mycila::TaskMonitor.toJson(system["stack"].to<JsonObject>());

// tasks
pioTaskManager.toJson(root["tasks"][pioTaskManager.getName()].to<JsonObject>());
coreTaskManager.toJson(root["tasks"][coreTaskManager.getName()].to<JsonObject>());
routingTaskManager.toJson(root["tasks"][routingTaskManager.getName()].to<JsonObject>());
jsyTaskManager.toJson(root["tasks"][jsyTaskManager.getName()].to<JsonObject>());
pzemTaskManager.toJson(root["tasks"][pzemTaskManager.getName()].to<JsonObject>());
mqttTaskManager.toJson(root["tasks"][mqttTaskManager.getName()].to<JsonObject>());

// config
config.toJson(root["config"].to<JsonObject>());
JsonObject tasks = system["task"].to<JsonObject>();
pioTaskManager.toJson(tasks[pioTaskManager.getName()].to<JsonObject>());
coreTaskManager.toJson(tasks[coreTaskManager.getName()].to<JsonObject>());
routingTaskManager.toJson(tasks[routingTaskManager.getName()].to<JsonObject>());
jsyTaskManager.toJson(tasks[jsyTaskManager.getName()].to<JsonObject>());
pzemTaskManager.toJson(tasks[pzemTaskManager.getName()].to<JsonObject>());
mqttTaskManager.toJson(tasks[mqttTaskManager.getName()].to<JsonObject>());

// libs versions
root["library"]["ArduinoJson"] = ARDUINOJSON_VERSION;
root["library"]["AsyncTCP"] = ASYNCTCP_VERSION;
root["library"]["CRC"] = CRC_LIB_VERSION;
root["library"]["ESPAsyncWebServer"] = ASYNCWEBSERVER_VERSION;
root["library"]["MycilaConfig"] = MYCILA_CONFIG_VERSION;
root["library"]["MycilaDS18"] = MYCILA_DS18_VERSION;
root["library"]["MycilaEasyDisplay"] = MYCILA_EASY_DISPLAY_VERSION;
root["library"]["MycilaESPConnect"] = ESPCONNECT_VERSION;
root["library"]["MycilaHADiscovery"] = MYCILA_HA_VERSION;
root["library"]["MycilaJSY"] = MYCILA_JSY_VERSION;
root["library"]["MycilaLogger"] = MYCILA_LOGGER_VERSION;
root["library"]["MycilaMQTT"] = MYCILA_MQTT_VERSION;
root["library"]["MycilaNTP"] = MYCILA_NTP_VERSION;
root["library"]["MycilaPulseAnalyzer"] = MYCILA_PULSE_VERSION;
root["library"]["MycilaPZEM004Tv3"] = MYCILA_PZEM_VERSION;
root["library"]["MycilaRelay"] = MYCILA_RELAY_VERSION;
root["library"]["MycilaSystem"] = MYCILA_SYSTEM_VERSION;
root["library"]["MycilaTaskManager"] = MYCILA_TASK_MANAGER_VERSION;
root["library"]["MycilaTaskMonitor"] = MYCILA_TASK_MONITOR_VERSION;
root["library"]["MycilaTrafficLight"] = MYCILA_TRAFFIC_LIGHT_VERSION;
root["library"]["MycilaUtilities"] = MYCILA_UTILITIES_VERSION;
JsonObject library = system["lib"].to<JsonObject>();
library["ArduinoJson"] = ARDUINOJSON_VERSION;
library["AsyncTCP"] = ASYNCTCP_VERSION;
library["CRC"] = CRC_LIB_VERSION;
library["ESPAsyncWebServer"] = ASYNCWEBSERVER_VERSION;
library["MycilaConfig"] = MYCILA_CONFIG_VERSION;
library["MycilaDS18"] = MYCILA_DS18_VERSION;
library["MycilaEasyDisplay"] = MYCILA_EASY_DISPLAY_VERSION;
library["MycilaESPConnect"] = ESPCONNECT_VERSION;
library["MycilaHADiscovery"] = MYCILA_HA_VERSION;
library["MycilaJSY"] = MYCILA_JSY_VERSION;
library["MycilaLogger"] = MYCILA_LOGGER_VERSION;
library["MycilaMQTT"] = MYCILA_MQTT_VERSION;
library["MycilaNTP"] = MYCILA_NTP_VERSION;
library["MycilaPulseAnalyzer"] = MYCILA_PULSE_VERSION;
library["MycilaPZEM004Tv3"] = MYCILA_PZEM_VERSION;
library["MycilaRelay"] = MYCILA_RELAY_VERSION;
library["MycilaSystem"] = MYCILA_SYSTEM_VERSION;
library["MycilaTaskManager"] = MYCILA_TASK_MANAGER_VERSION;
library["MycilaTaskMonitor"] = MYCILA_TASK_MONITOR_VERSION;
library["MycilaTrafficLight"] = MYCILA_TRAFFIC_LIGHT_VERSION;
library["MycilaUtilities"] = MYCILA_UTILITIES_VERSION;

response->setLength();
request->send(response);
Expand Down Expand Up @@ -260,7 +212,62 @@ Mycila::Task initRestApiTask("Init REST API", [](void* params) {
.on("/api/system", HTTP_GET, [](AsyncWebServerRequest* request) {
AsyncJsonResponse* response = new AsyncJsonResponse();
JsonObject root = response->getRoot();
systemInfoToJson(root);

Mycila::System::Memory memory;
Mycila::System::getMemory(memory);

root["app"]["manufacturer"] = Mycila::AppInfo.manufacturer;
root["app"]["model"] = Mycila::AppInfo.model;
root["app"]["name"] = Mycila::AppInfo.name;
root["app"]["version"] = Mycila::AppInfo.version;

root["device"]["boots"] = Mycila::System::getBootCount();
root["device"]["cores"] = ESP.getChipCores();
root["device"]["cpu_freq"] = ESP.getCpuFreqMHz();
root["device"]["heap"]["total"] = memory.total;
root["device"]["heap"]["usage"] = memory.usage;
root["device"]["heap"]["used"] = memory.used;
root["device"]["id"] = Mycila::AppInfo.id;
root["device"]["model"] = ESP.getChipModel();
root["device"]["revision"] = ESP.getChipRevision();
root["device"]["uptime"] = Mycila::System::getUptime();

root["firmware"]["build"]["branch"] = Mycila::AppInfo.buildBranch;
root["firmware"]["build"]["hash"] = Mycila::AppInfo.buildHash;
root["firmware"]["build"]["timestamp"] = Mycila::AppInfo.buildDate;
root["firmware"]["debug"] = Mycila::AppInfo.debug;
root["firmware"]["filename"] = Mycila::AppInfo.firmware;

root["network"]["eth"]["ip_address"] = espConnect.getIPAddress(Mycila::ESPConnect::Mode::ETH).toString();
root["network"]["eth"]["mac_address"] = espConnect.getMACAddress(Mycila::ESPConnect::Mode::ETH);

root["network"]["hostname"] = espConnect.getHostname();
root["network"]["ip_address"] = espConnect.getIPAddress().toString();
root["network"]["mac_address"] = espConnect.getMACAddress();
switch (espConnect.getMode()) {
case Mycila::ESPConnect::Mode::ETH:
root["network"]["mode"] = "eth";
break;
case Mycila::ESPConnect::Mode::STA:
root["network"]["mode"] = "wifi";
break;
case Mycila::ESPConnect::Mode::AP:
root["network"]["mode"] = "ap";
break;
default:
root["network"]["mode"] = "";
break;
}

root["network"]["ntp"] = YASOLR_STATE(Mycila::NTP.isSynced());

root["network"]["wifi"]["bssid"] = espConnect.getWiFiBSSID();
root["network"]["wifi"]["ip_address"] = espConnect.getIPAddress(Mycila::ESPConnect::Mode::STA).toString();
root["network"]["wifi"]["mac_address"] = espConnect.getMACAddress(Mycila::ESPConnect::Mode::STA);
root["network"]["wifi"]["quality"] = espConnect.getWiFiSignalQuality();
root["network"]["wifi"]["rssi"] = espConnect.getWiFiRSSI();
root["network"]["wifi"]["ssid"] = espConnect.getWiFiSSID();

response->setLength();
request->send(response);
});
Expand Down
4 changes: 2 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ void setup() {
assert( jsyTaskManager.asyncStart(512 * 4, 5, 0, 100, true)); // NOLINT
assert( pioTaskManager.asyncStart(512 * 7, 1, 1, 100, true)); // NOLINT
assert( coreTaskManager.asyncStart(512 * 7, 1, 1, 100, true)); // NOLINT
assert( mqttTaskManager.asyncStart(512 * 8, 1, 1, 100, false)); // NOLINT
assert( mqttTaskManager.asyncStart(512 * 7, 1, 1, 100, false)); // NOLINT
assert( pzemTaskManager.asyncStart(512 * 4, 5, 0, 100, true)); // NOLINT
assert(routingTaskManager.asyncStart(512 * 4, 5, 0, 100, true)); // NOLINT
assert(routingTaskManager.asyncStart(512 * 3, 5, 0, 100, true)); // NOLINT

// STARTUP READY!
logger.info(TAG, "Started %s", Mycila::AppInfo.nameModelVersion.c_str());
Expand Down
2 changes: 1 addition & 1 deletion src/tasks/MQTT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ Mycila::Task mqttPublishStaticTask("MQTT Static", Mycila::TaskType::ONCE, [](voi
mqtt.publish(baseTopic + "/system/device/boots", String(Mycila::System::getBootCount()), true);
mqtt.publish(baseTopic + "/system/device/cores", String(ESP.getChipCores()), true);
mqtt.publish(baseTopic + "/system/device/cpu_freq", String(ESP.getCpuFreqMHz()), true);
mqtt.publish(baseTopic + "/system/device/heap/total", String(ESP.getHeapSize()), true);
mqtt.publish(baseTopic + "/system/device/id", Mycila::AppInfo.id, true);
mqtt.publish(baseTopic + "/system/device/model", ESP.getChipModel(), true);
yield();
Expand Down Expand Up @@ -94,6 +93,7 @@ Mycila::Task mqttPublishTask("MQTT", [](void* params) {
Mycila::System::Memory memory;
Mycila::System::getMemory(memory);

mqtt.publish(baseTopic + "/system/device/heap/total", String(memory.total));
mqtt.publish(baseTopic + "/system/device/heap/usage", String(memory.usage));
mqtt.publish(baseTopic + "/system/device/heap/used", String(memory.used));
mqtt.publish(baseTopic + "/system/device/uptime", String(Mycila::System::getUptime()));
Expand Down

0 comments on commit 4f8604a

Please sign in to comment.