Skip to content

Commit effef88

Browse files
committed
fix broken json mqtt message
1 parent 2807004 commit effef88

2 files changed

Lines changed: 32 additions & 16 deletions

File tree

platformio.ini

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,19 @@ platform = espressif8266@4.2.1
1313
framework = arduino
1414
monitor_speed = 115200
1515
monitor_filters = esp8266_exception_decoder, default, time, printable, colorize
16-
1716
custom_prog_version = 2.3.0A1
18-
1917
build_flags =
20-
-DVERSION=${this.custom_prog_version}
21-
-DPIO_SRC_NAM="EPEver2MQTT"
22-
-DESP8266 -DATOMIC_FS_UPDATE
18+
-DVERSION=${this.custom_prog_version}
19+
-DPIO_SRC_NAM="EPEver2MQTT"
20+
-DESP8266 -DATOMIC_FS_UPDATE
2321
extra_scripts = pre:tools/mini_html.py
24-
pre:tools/pre_compile.py
25-
post:tools/post_compile.py
26-
22+
pre:tools/pre_compile.py
23+
post:tools/post_compile.py
2724
lib_extra_dirs =
2825
/lib
2926
lib_deps =
30-
knolleary/PubSubClient @ ^2.8
31-
bblanchon/ArduinoJson @ ^6.21.3
27+
knolleary/PubSubClient@^2.8
28+
bblanchon/ArduinoJson@^6.21.3
3229
ottowinter/ESPAsyncTCP-esphome@^1.2.3
3330
ottowinter/ESPAsyncWebServer-esphome@^3.0.0
3431
alanswx/ESPAsyncWiFiManager@^0.31
@@ -37,14 +34,16 @@ lib_deps =
3734
paulstoffregen/OneWire@^2.3.7
3835
milesburton/DallasTemperature@^3.11.0
3936

37+
bblanchon/StreamUtils@^1.8.0
38+
4039
[env:d1_mini]
4140
board = d1_mini
4241
build_flags = ${env.build_flags}
43-
board_build.ldscript = eagle.flash.4m.ld ; 4MB (FS:4MB OTA:~3600KB)
44-
upload_speed = 921600 ; faster upload to wemos d1 mini
42+
board_build.ldscript = eagle.flash.4m.ld
43+
upload_speed = 921600
4544

4645
[env:esp01_1m]
4746
board = esp01_1m
4847
build_flags = ${env.build_flags}
49-
board_build.ldscript = eagle.flash.1m.ld
50-
upload_speed = 115200
48+
board_build.ldscript = eagle.flash.1m.ld
49+
upload_speed = 115200

src/main.cpp

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
#include <WebSerialLite.h>
1717
#include <OneWire.h>
1818
#include <DallasTemperature.h>
19+
20+
#include <StreamUtils.h>
21+
1922
#include "Settings.h" //settings functions
2023
#include "html.h" //the HTML content
2124
#include "htmlProzessor.h" // The html Prozessor
@@ -53,6 +56,8 @@ UnixTime uTime(3);
5356
DynamicJsonDocument liveJson(JSON_BUFFER);
5457
OneWire oneWire(TEMPSENS_PIN);
5558
DallasTemperature tempSens(&oneWire);
59+
60+
5661
#include "status-LED.h"
5762
ADC_MODE(ADC_VCC);
5863
//----------------------------------------------------------------------
@@ -767,6 +772,7 @@ bool getJsonData(int invNum)
767772
liveJson["DEVICE_FREE_HEAP"] = ESP.getFreeHeap();
768773
liveJson["DEVICE_FREE_JSON"] = (JSON_BUFFER - liveJson.memoryUsage());
769774
liveJson["ESP_VCC"] = (ESP.getVcc() / 1000.0) + 0.3;
775+
liveJson["Runtime"] = millis() / 1000;
770776
liveJson["Wifi_RSSI"] = WiFi.RSSI();
771777
liveJson["sw_version"] = SOFTWARE_VERSION;
772778

@@ -857,9 +863,20 @@ bool sendtoMQTT()
857863
}
858864
else
859865
{
860-
mqttclient.beginPublish((topic + String("/DATA")).c_str(), measureJson(liveJson), false);
866+
/* mqttclient.beginPublish((topic + String("/DATA")).c_str(), measureJson(liveJson), false);
861867
serializeJson(liveJson, mqttclient);
862-
mqttclient.endPublish();
868+
mqttclient.endPublish(); */
869+
870+
871+
872+
873+
874+
mqttclient.beginPublish((topic + String("/DATA")).c_str(), measureJson(liveJson), false);
875+
BufferingPrint bufferedClient(mqttclient, 32);
876+
serializeJson(liveJson, bufferedClient);
877+
bufferedClient.flush();
878+
mqttclient.endPublish();
879+
863880
}
864881
return true;
865882
}

0 commit comments

Comments
 (0)