MQTT NodeMCU
MQTT Debugging Method For ESP8266
Websocket debugging:
- 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:
- 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
- Only need to run the last command sudo apt-get install mosquitto mosquitto-clients
- wget http://repo.mosquitto.org/debian/mosquitto-repo.gpg.key
- sudo apt-key add mosquitto-repo.gpg.key
- sudo nano /etc/apt/sources.list.d/mosquitto.list -> add -> deb http://repo.mosquitto.org/debian jessie main
- sudo apt-get update
- sudo apt-get install mosquitto mosquitto-clients
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