0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

esp-idf: mqtt5 の使い方

Last updated at Posted at 2023-01-31

esp/esp-idf/examples/protocols/mqtt5 のプログラムを改造します。
M5Stack Core2 で動作確認をしました。
次にパブリッシュするのを確認しました。

ブローカー mqtt.eclipseprojects.io
トピック /topic/qos1

プログラム

プロジェクトのコピー

cd ~/esp
cp -r ~/esp/esp-idf/examples/protocols/mqtt5 .

tcp/sdkconfig を作成

idf.py build

変更する場所

mqtt5/sdkconfig
(省略)
CONFIG_EXAMPLE_WIFI_SSID="****"
CONFIG_EXAMPLE_WIFI_PASSWORD="****"
(省略)

"こんにちは Hello data_3" を publish するようにします。

mqtt5/main/app_main.c
(省略)
        esp_mqtt5_client_set_publish_property(client, &publish_property);
        msg_id = esp_mqtt_client_publish(client, "/topic/qos1", "こんにちは Hello data_3", 0, 1, 1);
        esp_mqtt5_client_delete_user_property(publish_property.user_property);
        publish_property.user_property = NULL;
(省略)

コンパイル、実行

idf.py -p /dev/ttyUSB0 flash

テスト結果

サブスクライブするスクリプト

go_sub_mqtt.sh
mosquitto_sub -d -t orz -V mqttv5 -h mqtt.eclipseprojects.io \
    --topic /topic/qos1

スクリプトのけっか

$ ./go_sub_mqtt.sh 
Client (null) sending CONNECT
Client auto-2DA00A77-2CB7-79CF-4E0D-3B787C09A084 received CONNACK (0)
Client auto-2DA00A77-2CB7-79CF-4E0D-3B787C09A084 sending SUBSCRIBE (Mid: 1, Topic: orz, QoS: 0, Options: 0x00)
Client auto-2DA00A77-2CB7-79CF-4E0D-3B787C09A084 sending SUBSCRIBE (Mid: 1, Topic: /topic/qos1, QoS: 0, Options: 0x00)
Client auto-2DA00A77-2CB7-79CF-4E0D-3B787C09A084 received SUBACK
Subscribed (mid: 1): 0, 0
Client auto-2DA00A77-2CB7-79CF-4E0D-3B787C09A084 sending PINGREQ
Client auto-2DA00A77-2CB7-79CF-4E0D-3B787C09A084 received PINGRESP
Client auto-2DA00A77-2CB7-79CF-4E0D-3B787C09A084 received PUBLISH (d0, q0, r0, m0, '/topic/qos1', ... (28 bytes))
こんにちは Hello data_3
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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?