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: mqtt/wss の使い方

Last updated at Posted at 2025-02-13

こちらと同様のことを、
esp-idf: mqtt/ws の使い方
esp-idf/examples/protocols/mqtt/wss で行いました。
MQTT over WebSocket Secure になります。

ブローカー wss://mqtt.eclipseprojects.io:443/mqtt
トピック /topic/qos0

プログラム

プロジェクトのコピー

cp -r ~/esp/esp-idf/examples/protocols/mqtt/wss .

wss/sdkconfig を作成

idf.py build

Wifi の接続情報を変更

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

main/mqtt_eclipseprojects_io.pem の作成

ダウンロード (README.md に記述されています)

echo "" | openssl s_client -showcerts -connect mqtt.eclipseprojects.io:443 | sed -n "1,/Root/d; /BEGIN/,/END/p" | openssl x509 -outform PEM >mqtt_eclipse_org.pem

mqtt_eclipse_org.pem を wss/main/mqtt_eclipseprojects_io.pem
にコピーする

コンパイル、実行

idf.py -p /dev/ttyUSB0 flash

テスト

esp-idf: mqtt/ws の使い方
の publish.js subscribe.js の const brokerUrl を次に変更

const brokerUrl = 'wss://mqtt.eclipseprojects.io:443/mqtt'

実行結果

$ cu -l /dev/ttyUSB0 -s 115200
Connected.
(省略)
I (768825) mqttwss_example: MQTT_EVENT_DATA
TOPIC=/topic/qos0
DATA=Good Afternoon Feb/13/2025 PM 15:31
I (772715) mqttwss_example: MQTT_EVENT_DATA
TOPIC=/topic/qos0
DATA=Good Afternoon Feb/13/2025 PM 15:31
I (775485) mqttwss_example: MQTT_EVENT_DATA
TOPIC=/topic/qos0
DATA=Good Afternoon Feb/13/2025 PM 15:31
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?