1 Star 0 Fork 0

Chentuo/ESP8266_NONOS_SDK

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README

Simple MQTT Client Demo

This example implement:

  • MQTT Publish the Message
  • MQTT Subscribe the Topic
  • MQTT works with SSL/TLS
  • MQTT works with one-way anthentication
  • MQTT works with two-way anthentication

How to make the Demo work

Step 1: Start the MQTT broker

you could choose mosquitto or EMQTT as your MQTT broker

Step 2: Configurate your demo

All you need to configurate are in mqtt_config.h, please according to the comment to modify:

  • CFG_HOLDER
  • MQTT_HOST
  • MQTT_PORT
  • MQTT_CLIENT_ID
  • MQTT_USER
  • MQTT_PASS
  • STA_SSID
  • STA_PASS
  • DEFAULT_SECURITY
  • CA_CERT_FLASH_ADDRESS
  • CLIENT_CERT_FLASH_ADDRESS

Step 3(optional): Generate your certificate for SSL/TLS

if you configurate DEFAULT_SECURITY to ONE_WAY_ANTHENTICATION or TWO_WAY_ANTHENTICATION, please according to tools/README.txt to generate your certificate

Step 4: Build your demo

$./gen_misc.sh

compile options: 1 1 2 0 5, or others if you are familar to it.

Step 5: Flash your demo

Any way is OK,such as:

$~/esp/esp-idf/components/esptool_py/esptool/esptool.py --port /dev/ttyUSB0 --baud 921600 write_flash 0x00000 ~/ESP8266_NONOS_SDK/bin/boot_v1.6.bin 0x1000 ../bin/upgrade/user1.2048.new.5.bin 0x1fe000 ~/ESP8266_NONOS_SDK/bin/blank.bin 0x1fc000 ~/ESP8266_NONOS_SDK/bin/esp_init_data_default.bin

Step 6(optional): Flash your certificate

Any way is OK, but your flashing address is same as the Step 2,such as:

$~/esp/esp-idf/components/esptool_py/esptool/esptool.py --port /dev/ttyUSB0 --baud 921600 write_flash  0x77000 ~/ESP8266_NONOS_SDK/tools/bin/esp_ca_cert.bin
$~/esp/esp-idf/components/esptool_py/esptool/esptool.py --port /dev/ttyUSB0 --baud 921600 write_flash  0x78000 ~/MQTTESP8266/tools/bin/esp_cert_private_key.bin

Run the demo and Result Shows

when the demo starts up:

  • it would subscribe the topic /mqtt/topic/0 , /mqtt/topic/1 , /mqtt/topic/2
  • it would publish the topic /mqtt/topic/0 , /mqtt/topic/1 , /mqtt/topic/2
  • MQTT broker would receive subscribe and publish

Troubleshooting

why the demo connect the WiFi failed?

  • try to modify CFG_HOLDER

why the handshake failed?

  • try to uncomment espconn_secure_set_size and modify memory allocate
  • make sure your MQTT broker SSL/TLS certificate configurate valid
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/chentuo2000/ESP8266_NONOS_SDK.git
git@gitee.com:chentuo2000/ESP8266_NONOS_SDK.git
chentuo2000
ESP8266_NONOS_SDK
ESP8266_NONOS_SDK
master

搜索帮助