MQTT NodeMCU

From ElectroDragon
Jump to navigation Jump to search

MQTT Debugging Method For ESP8266

Websocket debugging:

CloudMQTT Websocket Console.png
  • Websocket debugging, login to cloudmqtt, please use your own server config (lua file mqtt-config.lua), see the screenshot on right
  • Commands can also send directly via websocket interface

Serial USB interface debugging:

Esp relay board demo.JPG
  • Debugging info can be read when you use it.
NodeMCU custom build by frightanic.com
	branch: master
	commit: c8037568571edb5c568c2f8231e4f8ce0683b883
	SSL: false
	modules: dht,enduser_setup,file,gpio,mqtt,net,node,tmr,uart,wifi
 build 	built on: 2016-03-29 10:06
 powered by Lua 5.1.4 on SDK 1.4.0
set up wifi mode
> Waiting for smartconfig, IP unavailable..
Waiting for smartconfig, IP unavailable..
Waiting for smartconfig, IP unavailable..
Waiting for smartconfig, IP unavailable..
Success. SSID: hcwork ; PASSWORD: electrodragon
Waiting for smartconfig, IP unavailable..
Waiting for smartconfig, IP unavailable..
Config done, IP is 192.168.43.134
Running file mqtt
connected
Light2:
receive OFF liked data on light2
Light1:
receive OFF liked data on light1
Light1:
received message: ON@light1
Light1:
receive OFF liked data on light1
Light2:
received message: ON@light2
Light2:
offline

MQTT Server Setup

Run simple test

  • run this command in one connection -> mosquitto_sub -h localhost -t test
  • run this in other connection -> mosquitto_pub -h localhost -t test -m "hello world"

Set password

  • sudo mosquitto_passwd -c /etc/mosquitto/passwd ed
  • sudo nano /etc/mosquitto/conf.d/default.conf
  • allow_anonymous false
  • password_file /etc/mosquitto/passwd
  • restart -> sudo systemctl restart mosquitto

Test again

  • mosquitto_sub -h localhost -t test -u "ed" -P "dragon"

ufw port setup

  • ufw allow 22