Ed Wios
Published © MIT

Node-Red, MQTT and the new Weather Station (Part 1)

This is a 3 parts project aimed to give an overview of how one could use MQTT, Node-Red and an ESP8266 to build a weather station.

BeginnerFull instructions provided16,298
Node-Red, MQTT and the new Weather Station (Part 1)

Things used in this project

Hardware components

NodeMCU ESP8266 Breakout Board
NodeMCU ESP8266 Breakout Board
×1
Temp and Humidity Sensor (SI7021)
×1

Story

Read more

Code

Code snippet #1

Plain text
si7021 = require("si7021")

Code snippet #2

Plain text
SDA_PIN = 6 -- sda pin, GPIO12
SCL_PIN = 5 -- scl pin, GPIO14
si7021 = require("si7021")
si7021.init(SDA_PIN, SCL_PIN)
si7021.read(OSS)
h = si7021.getHumidity()
t = si7021.getTemperature()

Code snippet #3

Plain text
mqtt.Client(clientname, timeout, username, password)
e.g.
m = mqtt.Client("Client_Name", 120, null, null)

Code snippet #4

Plain text
mqtt:connect( host, port, secure, auto_reconnect, function(client))
e.g. 
m:connect(MQTTBrokerIP, MQTTBrokerPort, 0, 1)

Code snippet #5

Plain text
mqtt:publish(topic,message,qos,retain)
e.g. 
m:publish("home/outdoor/temperature",t,0,0)

Code snippet #6

Plain text
mosquitto_pub -h broker_ip -t topic -m message
e.g.
mosquitto_pub -h 127.0.0.1 -t "home/livingroom/light02/dim" -m "58"

Code snippet #7

Plain text
mosquitto_sub -h broker_ip -t topic
e.g.
mosquitto_sub -h 127.0.0.1 -t "home/livingroom/temperature"
24.8
24.6
24.7

Credits

Ed Wios

Ed Wios

10 projects • 25 followers
Hi! This is Ed, I love tinkering with digital electronics, as well as writing programs.

Comments