Skip to content

Commit

Permalink
Update the dependencies to the actual version.
Browse files Browse the repository at this point in the history
Replace Dynamic and Static Json to Jsondocument
  • Loading branch information
14yannick committed Jan 12, 2024
1 parent c32cbb1 commit eac6632
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 29 deletions.
11 changes: 4 additions & 7 deletions HCPBridgeESP32/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
[platformio]
;set your env you want to build default esp32 without any sensor. Comment line to build all environments.
;list separeted by , to build selected evns.
;default_envs = esp32
default_envs = esp32

[common]
dht22libs =
Expand All @@ -20,9 +20,6 @@ bmelibs =
adafruit/Adafruit BME280 Library
ds18x20libs =
milesburton/DallasTemperature
hcsr501libs =
https://github.com/dok-net/ghostl ; << Fix missing circular_queue.h


[env]
platform = espressif32
Expand All @@ -36,13 +33,14 @@ monitor_filters = esp32_exception_decoder
lib_ldf_mode = deep+
lib_deps =
esphome/ESPAsyncWebServer-esphome
esphome/AsyncTCP[email protected].0
https://github.com/HeMan/AsyncTCP#CI-and-fix ;async tcp issue fix 2.1.0
bblanchon/ArduinoJson
plerup/EspSoftwareSerial
ayushsharma82/AsyncElegantOTA
ottowinter/AsyncMqttClient-esphome
paulstoffregen/OneWire
https://github.com/emelianov/modbus-esp8266
emelianov/modbus-esp8266
https://github.com/dok-net/ghostl ; << Fix missing circular_queue.h
extra_scripts = pre:../WebUI/webpage/compress.py
;build_flags =
; -D CORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_VERBOSE
Expand Down Expand Up @@ -94,7 +92,6 @@ lib_deps = ${env:esp32.lib_deps} ${common.bmelibs}
build_flags = ${env:esp32.build_flags} -D SENSORS -D USE_BME -D USE_HCSR04

[env:HCSR501]
lib_deps = ${env:esp32.lib_deps} ${common.hcsr501libs}
build_flags = ${env:esp32.build_flags} -D SENSORS -D USE_HCSR501

[env:m5stack-stamps3]
Expand Down
2 changes: 1 addition & 1 deletion HCPBridgeESP32/src/hoermann.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@
}

String toStatusJson() {
DynamicJsonDocument root(1024);
JsonDocument root;
root["valid"] = this->isValid();
root["targetPosition"] = (int)(this->targetPosition*100);
root["currentPosition"] = (int)(this->currentPosition*100);
Expand Down
47 changes: 26 additions & 21 deletions HCPBridgeESP32/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ void updateDoorStatus(bool forceUpate = false)
// onyl send updates when state changed
if (hoermannEngine->state->changed || forceUpate){
hoermannEngine->state->clearChanged();
DynamicJsonDocument doc(1024);
JsonDocument doc;
char payload[1024];
const char *venting = HA_CLOSE;

Expand Down Expand Up @@ -310,7 +310,7 @@ void updateSensors(bool forceUpate = false){

if (new_sensor_data || forceUpate) {
new_sensor_data = false;
DynamicJsonDocument doc(1024); //2048 needed because of BME280 float values!
JsonDocument doc; //2048 needed because of BME280 float values!
char payload[1024];
char buf[20];
#ifdef USE_DS18X20
Expand Down Expand Up @@ -401,7 +401,7 @@ void setWill()

void sendDebug(char *key, String value)
{
DynamicJsonDocument doc(1024);
JsonDocument doc;
char payload[1024];
doc["reset-reason"] = esp_reset_reason();
doc["debug"] = hoermannEngine->state->debugMessage;
Expand All @@ -421,7 +421,7 @@ void sendDiscoveryMessageForBinarySensor(const char name[], const char topic[],
char vtemp[64];
sprintf(vtemp, "{{ value_json.%s }}", key);

DynamicJsonDocument doc(1024);
JsonDocument doc;

doc["name"] = name;
doc["state_topic"] = topic;
Expand All @@ -447,7 +447,7 @@ void sendDiscoveryMessageForAVSensor(const JsonDocument& device)

char uid[64];
sprintf(uid, "%s_sensor_availability", localPrefs->getString(preference_gd_id));
DynamicJsonDocument doc(1024);
JsonDocument doc;

doc["name"] = localPrefs->getString(preference_gd_avail);
doc["state_topic"] = mqttStrings.availability_topic;
Expand All @@ -470,9 +470,17 @@ void sendDiscoveryMessageForSensor(const char name[], const char topic[], const
sprintf(uid, "%s_sensor_%s", localPrefs->getString(preference_gd_id), key);

char vtemp[64];
sprintf(vtemp, "{{ value_json.%s | float }}", key);
//small workaround to get the value as float
if (key == "hum" || key == "temp" || key == "pres"){
sprintf(vtemp, "{{ value_json.%s | float }}", key);
} else {
sprintf(vtemp, "{{ value_json.%s }}", key);
}




DynamicJsonDocument doc(1024);
JsonDocument doc;

doc["name"] = name;
doc["state_topic"] = topic;
Expand Down Expand Up @@ -504,7 +512,7 @@ void sendDiscoveryMessageForDebug(const char name[], const char key[], const Jso
char vtemp[64];
sprintf(vtemp, "{{ value_json.%s }}", key);

DynamicJsonDocument doc(1024);
JsonDocument doc;

doc["name"] = name;
doc["state_topic"] = mqttStrings.debug_topic;
Expand Down Expand Up @@ -541,7 +549,7 @@ void sendDiscoveryMessageForSwitch(const char name[], const char discovery[], co
sprintf(uid, "%s_switch_%s",localPrefs->getString(preference_gd_id), topic);
}

DynamicJsonDocument doc(1024);
JsonDocument doc;

doc["name"] = name;
doc["state_topic"] = mqttStrings.state_topic;
Expand Down Expand Up @@ -575,7 +583,7 @@ void sendDiscoveryMessageForCover(const char name[], const char topic[], const J
char uid[64];
sprintf(uid, "%s_cover_%s", localPrefs->getString(preference_gd_id), topic);

DynamicJsonDocument doc(1024);
JsonDocument doc;
//if it didn't work try without state topic.
doc["name"] = name;
doc["state_topic"] = mqttStrings.state_topic;
Expand Down Expand Up @@ -614,8 +622,7 @@ void sendDiscoveryMessageForCover(const char name[], const char topic[], const J
void sendDiscoveryMessage()
{
//declare json object here for device instead of creating in each methode. 150 bytes should be enough
const int capacity = JSON_OBJECT_SIZE(6);
StaticJsonDocument<capacity> device;
JsonDocument device;
device["identifiers"] = localPrefs->getString(preference_gd_name);
device["name"] = localPrefs->getString(preference_gd_name);
device["sw_version"] = HA_VERSION;
Expand Down Expand Up @@ -707,7 +714,7 @@ void SensorCheck(void *parameter){
hcsr501stat = digitalRead(SR501PIN);
if (hcsr501stat != hcsr501_laststat) {
hcsr501_laststat = hcsr501stat;
DynamicJsonDocument doc(1024);
JsonDocument doc;
char payload[1024];
if (hcsr501stat) {
doc["motion"] = HA_ON;
Expand Down Expand Up @@ -735,7 +742,7 @@ void SensorCheck(void *parameter){
//bme_status = bme.begin(); // check sensor. adreess can be 0x76 or 0x77
}
if (!bme_status) {
DynamicJsonDocument doc(1024); //2048 needed because of BME280 float values!
JsonDocument doc; //2048 needed because of BME280 float values!
// char payload[1024];
// doc["bme_status"] = "Could not find a valid BME280 sensor!"; // see: https://github.com/adafruit/Adafruit_BME280_Library/blob/master/examples/bme280test/bme280test.ino#L49
// serializeJson(doc, payload);
Expand Down Expand Up @@ -1033,7 +1040,7 @@ void setup()
server.on("/status", HTTP_GET, [](AsyncWebServerRequest *request){
//const SHCIState &doorstate = emulator.getState();
AsyncResponseStream *response = request->beginResponseStream("application/json");
DynamicJsonDocument root(1024);
JsonDocument root;
//response->print(hoermannEngine->state->toStatusJson());
root["doorstate"] = hoermannEngine->state->translatedState;
root["valid"] = hoermannEngine->state->valid;
Expand Down Expand Up @@ -1110,7 +1117,7 @@ void setup()
{
Serial.println("GET SYSINFO");
AsyncResponseStream *response = request->beginResponseStream("application/json");
DynamicJsonDocument root(1024);
JsonDocument root;
root["freemem"] = ESP.getFreeHeap();
root["hostname"] = WiFi.getHostname();
root["ip"] = WiFi.localIP().toString();
Expand All @@ -1125,8 +1132,7 @@ void setup()
{
Serial.println("GET CONFIG");
AsyncResponseStream *response = request->beginResponseStream("application/json");
const int capacity = JSON_OBJECT_SIZE(65); //Strings counts twice
StaticJsonDocument<capacity> conf;
JsonDocument conf;
prefHandler.getConf(conf);
serializeJson(conf, *response);
request->send(response); });
Expand All @@ -1137,8 +1143,7 @@ void setup()
// Handle setting config request
if (request->url() == "/config")
{
const int capacity = JSON_OBJECT_SIZE(70); //Strings counts twice
StaticJsonDocument<capacity> doc;
JsonDocument doc;
deserializeJson(doc, data);
prefHandler.saveConf(doc);

Expand All @@ -1148,7 +1153,7 @@ void setup()
{
Serial.println("GET reset");
AsyncResponseStream *response = request->beginResponseStream("application/json");
DynamicJsonDocument root(1024);
JsonDocument root;
root["reset"] = "OK";
serializeJson(root, *response);
request->send(response);
Expand Down

0 comments on commit eac6632

Please sign in to comment.