File tree Expand file tree Collapse file tree 1 file changed +7
-16
lines changed Expand file tree Collapse file tree 1 file changed +7
-16
lines changed Original file line number Diff line number Diff line change @@ -38,22 +38,13 @@ void WeatherFlowUdp::update() {
38
38
// Process all waiting packets
39
39
int packetSize = 0 ;
40
40
while (packetSize = weatherUDP.parsePacket ()) {
41
- char * buffer = (char *)malloc (packetSize+1 );
42
- int bufferLen = weatherUDP.read (buffer, packetSize);
43
-
44
- // Null terminate the buffer, just in case.
45
- buffer[bufferLen] = 0 ;
46
- bufferLen++;
47
- #ifdef DEBUG
48
- Serial.println (F (" Received WeatherFlow packet" ));
49
- Serial.println (buffer);
50
- #endif
51
- // Free the buffer if it wasn't handled.
52
- if (processPacket (buffer) != 0 ) {
53
- Serial.println (F (" Packet not handled" ));
54
- Serial.println (buffer);
55
- free (buffer);
56
- }
41
+ DynamicJsonDocument tempDoc (600 );
42
+ DeserializationError err = deserializeJson (tempDoc, weatherUDP);
43
+ if (err) {
44
+ Serial.print (F (" deserializeJson() failed of UDP packet: " ));
45
+ Serial.println (err.c_str ());
46
+ }
47
+ processJsonDocument (tempDoc);
57
48
}
58
49
}
59
50
You can’t perform that action at this time.
0 commit comments