Skip to content

Commit

Permalink
increase MQTT_MAX_PACKET_SIZE to 1024
Browse files Browse the repository at this point in the history
  • Loading branch information
Greg Toth committed Apr 30, 2020
1 parent 4ec0002 commit 52c4b38
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Author: Greg Toth
* In Arduino IDE, from Tools > Manage Libraries... install these libraries:
* PubSubClient by Nick O'Leary, version 2.7.0 or higher
* ArduinoJson by Benoit Blanchon, version 6.15.0 or higher
* For the PubSubClient library, edit Arduino/libraries/PubSubClient/src/PubSubClient.h and change MQTT_MAX_PACKET_SIZE to be 1024 instead of 128.
* Open the application source code file esp32_mediumone_bridge.ino from repository directory.

### Configuring the ESP32 Serial Port
Expand Down
15 changes: 6 additions & 9 deletions esp32_mediumone_bridge.ino
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#define VERSION "0.8.0"

#include <WiFiClientSecure.h> // https://github.com/espressif/arduino-esp32/tree/master/libraries/WiFiClientSecure
#define MQTT_MAX_PACKET_SIZE 512
#define MQTT_MAX_PACKET_SIZE 1024
#include <PubSubClient.h>
#include <ArduinoJson.h>

Expand Down Expand Up @@ -350,7 +350,7 @@ void cmdStatusMqtt(char *payload)
void cmdPublishMqtt(char *payload)
{
// {"topic":"thepublishtopic","msg":"msg to publish"}
StaticJsonDocument<512> json_payload;
StaticJsonDocument<1024> json_payload;
DeserializationError err = deserializeJson(json_payload, payload);
if (err) {
CONSOLE_SERIAL.println("ERROR: Could not parse JSON payload");
Expand Down Expand Up @@ -392,14 +392,11 @@ void cmdPublishMqtt(char *payload)
BLINK_LED_ERROR();
CLIENT_SERIAL.println(RESULT_ERROR_MQTT_PUBLISH_FAILED_NOT_CONNECTED); // second error msg
} else {
CONSOLE_SERIAL.println(topic);
CONSOLE_SERIAL.println(msg);
CONSOLE_SERIAL.print("Topic: "); CONSOLE_SERIAL.println(topic);
CONSOLE_SERIAL.print("Message: "); CONSOLE_SERIAL.println(msg);
CONSOLE_SERIAL.print("Message Len: "); CONSOLE_SERIAL.println(strlen(msg));
if (mqttClient.publish(topic, msg)) {
CONSOLE_SERIAL.print("Published to topic '");
CONSOLE_SERIAL.print(topic);
CONSOLE_SERIAL.print("' msg '");
CONSOLE_SERIAL.print(msg);
CONSOLE_SERIAL.println("'");
CONSOLE_SERIAL.println("Publish successful");
BLINK_LED_OK();
CLIENT_SERIAL.println(RESULT_OK);
} else {
Expand Down

0 comments on commit 52c4b38

Please sign in to comment.