Giter VIP home page Giter VIP logo

tcp-mqtt's Introduction

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

tcp-mqtt's People

Contributors

linngo avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.