LoginSignup
0
0

More than 1 year has passed since last update.

WioLTE で MQTT Publish できる最大サイズを調べる

Last updated at Posted at 2021-08-21

こちらのプログラムを改造して、WioLTE で MQTT Publish できる最大サイズを調べてみました。
WioLTE で 大きいデータを MQTT Publish する

mqtt_publish/mqtt_publish.ino
// ---------------------------------------------------------------
/*
    mqtt_publish.ino

                    Aug/21/2021
*/
// ---------------------------------------------------------------
#include <WioLTEforArduino.h>
#include <WioLTEClient.h>
#include <PubSubClient.h>
#include <ArduinoJson.h>
#include <stdio.h>

#define MQTT_SERVER_HOST  "example.com"
#define MQTT_SERVER_PORT  (1883)

#define ID      "WioLTE"
#define OUT_TOPIC   "sample/imageTopic"
#define IN_TOPIC    "sample/imageTopic"

#define INTERVAL    (5000)

WioLTE Wio;
WioLTEClient WioClient(&Wio);
PubSubClient MqttClient;

int count = 0;
// ---------------------------------------------------------------
void callback(char* topic, byte* payload, unsigned int length)
{
    SerialUSB.println("");
    payload[length] = '\0';
    String msg = String((char*) payload);
    SerialUSB.println(msg);
}

// ---------------------------------------------------------------
void setup()
{
    setupLTE();

    setup_mqtt_proc();

    SerialUSB.println("*** Setup completed *** Aug/21/2021 PM 17:00 ***");
}

// ---------------------------------------------------------------
void loop()
{
    Wio.LedSetRGB(1, 1, 0); 
    MqttClient.loop();
    SerialUSB.println("*** check *** " + String(count));

    mqtt_send_proc(count);

    Wio.LedSetRGB(0, 0, 1); 
    delay(INTERVAL / 4);
    Wio.LedSetRGB(0, 1, 0); 
    delay(INTERVAL / 4);
    Wio.LedSetRGB(1, 1, 1); 
    delay(INTERVAL / 4);
    Wio.LedSetRGB(0, 0, 0); 
    delay(INTERVAL / 4);

    count++;
}

// ---------------------------------------------------------------
void mqtt_send_proc(int count)
{
    DynamicJsonDocument doc(4096);
    char data_json[2048];
    data_json[0] = '\0';

    char *chx = (char *)malloc(2048);
    chx[0] = '\0';

    char qq[51] = "012345678901234567890123456789012345678901234567qq";

    for (int it=0; it<28; it++)
        {
        strcat(chx,qq);
        }

    doc["count"] = count;

    doc["llx"] = String(strlen(chx));
    doc["chx"] = chx;

    serializeJson(doc, data_json);

    SerialUSB.println(data_json);
    SerialUSB.println(strlen(data_json));
    SerialUSB.println(MQTT_MAX_PACKET_SIZE);

    boolean flag = MqttClient.publish(OUT_TOPIC, data_json);
    SerialUSB.println(flag);

    free(chx);
}

// ---------------------------------------------------------------

実行結果
mqtt_publish_aug21.png

1433 Byte は Publish できました。
1483 Byte は Publish できませんでした。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0