Difference between revisions of "Lit"
(Created page with "== Hardware == *NodeMCU *Board with 8 relays with galvanic isolation. *~3m RGB LED Strip *Two Temperature Sensors *Two Power Supply *Router Case *Wiring == Software == * Tasm...") |
|||
(3 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
+ | A MQTT controlled device that reads outdoors and indoors temperature sensors and give the user control over 8 relays, including three that have an RGB LED Stripe under the front window. | ||
+ | |||
== Hardware == | == Hardware == | ||
− | *NodeMCU | + | * NodeMCU |
− | *Board with | + | * 5V 8 Channel Relay Board with Optocouplers |
− | *~3m RGB LED Strip | + | * ~3m RGB LED Strip |
− | *Two Temperature Sensors | + | * Two DS18B20 Temperature Sensors. Soldered the cables together plus 4.7kΩ resistor between data and VCC on the cable. |
− | *Two Power | + | * Two Power Supplies -- 12V 2A, 5V 1A. Separate for Isolation. |
− | *Router Case | + | * Router Case -- From the Junk Bench |
− | *Wiring | + | * Wiring -- 10 Pin "Dupont" Male to Male Flat Cable from Relay Board to NodeMCU. |
== Software == | == Software == | ||
− | * Tasmota | + | === Packages === |
− | * MQTT server | + | * Sonoff-Tasmota |
− | + | * Mosquito MQTT server -- Default Settings (Allow Anonymous) | |
− | * | + | |
+ | === Tools === | ||
+ | Atom with PlatformIO. | ||
+ | |||
+ | === Config === | ||
+ | Disabled everything that is not used by this installation, preconfigured WiFi and MQTT broker address. | ||
+ | [[leet-tasmota-user_config.h]] | ||
+ | |||
+ | === Setup === | ||
+ | NodeMCU in Tasmota is the "WeMos D1 mini" module | ||
+ | <pre>mosquitto_pub -h mqtt.example.com -m '18' -t cmnd/example/module</pre> | ||
+ | |||
+ | '''mqtt.example.com''' and '''/example/''' are fake placeholders replace with real values to actually use any of this. | ||
+ | |||
+ | The relay board expects the optocouplers to be driven low, so we use the inverted relay module. Also the NodeMCU "D" Pins and the ESP GPIO are not matching. I ordered relay modules so that they are aligned with the flat cable. | ||
+ | |||
+ | <pre> | ||
+ | mosquitto_pub -h mqtt.example.com -m '25' -t cmnd/example/gpio16 | ||
+ | mosquitto_pub -h mqtt.example.com -m '26' -t cmnd/example/gpio5 | ||
+ | mosquitto_pub -h mqtt.example.com -m '27' -t cmnd/example/gpio4 | ||
+ | mosquitto_pub -h mqtt.example.com -m '28' -t cmnd/example/gpio0 | ||
+ | mosquitto_pub -h mqtt.example.com -m '29' -t cmnd/example/gpio2 | ||
+ | mosquitto_pub -h mqtt.example.com -m '30' -t cmnd/example/gpio14 | ||
+ | mosquitto_pub -h mqtt.example.com -m '31' -t cmnd/example/gpio12 | ||
+ | mosquitto_pub -h mqtt.example.com -m '32' -t cmnd/example/gpio13 | ||
+ | </pre> | ||
+ | |||
+ | For the DS18B20 "bus" I tried gpio15 but NodeMCU wouldn't boot with DS18B20 attached, so I moved it to gpio1 which is normally Serial TX, but seems to work fine, even when upgrading firmware over usb with the sensores attached. | ||
+ | <pre>mosquitto_pub -h mqtt.example.com -m '4' -t cmnd/example/gpio1</pre> | ||
+ | |||
+ | == Operation == | ||
+ | === Automatic === | ||
+ | One operation is done automatically by a script. When it is dark outside it starts randomly toggle the relays in random intervals. | ||
+ | |||
+ | <pre> | ||
+ | #!/bin/sh | ||
+ | |||
+ | secs=$1 | ||
+ | start=`date +%s` | ||
+ | end=$((start+$secs)) | ||
+ | |||
+ | while true ; do | ||
+ | if [ `date +%s` -gt $end ]; then | ||
+ | break | ||
+ | fi | ||
+ | |||
+ | mosquitto_pub -h mqtt.example.com -m 'toggle' -t cmnd/example/POWER$(( ( RANDOM % 3 ) + 1 )) | ||
+ | sleep $(( ( RANDOM % 100 ) + 1 )) | ||
+ | done | ||
+ | |||
+ | mosquitto_pub -h mqtt.example.com -m 'off' -t cmnd/example/POWER1 | ||
+ | mosquitto_pub -h mqtt.example.com -m 'off' -t cmnd/example/POWER2 | ||
+ | mosquitto_pub -h mqtt.example.com -m 'off' -t cmnd/example/POWER3 | ||
+ | |||
+ | exit 0 | ||
+ | </pre> | ||
+ | |||
+ | This script is ran by cron at sunset and exits at sunrise (~9.5h hard coded values right now) | ||
+ | <pre>38 19 * * * /home/user/script.sh 34260</pre> | ||
+ | |||
+ | === Manual === | ||
+ | The user can manually change the state of the relays. | ||
+ | |||
+ | Turn off the light: | ||
+ | <pre>mosquitto_pub -h mqtt.example.com -m 'off' -t cmnd/example/POWER1</pre> | ||
+ | |||
+ | Turn on the light: | ||
+ | <pre>mosquitto_pub -h mqtt.example.com -m 'on' -t cmnd/example/POWER1</pre> | ||
+ | |||
+ | Toggle the state of the light: | ||
+ | <pre>mosquitto_pub -h mqtt.example.com -m 'toggle' -t cmnd/example/POWER1</pre> | ||
+ | |||
+ | '''POWER1''' Coresonds to the first relay, in the current installation the one connected at D0/GPIO16 and it controls the Red LEDs. For Green change to '''POWER2''' and for Blue to '''POWER3'''. | ||
+ | |||
+ | === Subscription === | ||
+ | The Device periodically sends information about its state including the readings of the temperature sensors. | ||
− | + | From the terminal you can subscribe to receive those messages periodically with (and leave it running): | |
+ | * For the temperature sensors: <pre>mosquitto_sub -v -h mqtt.example.com -t 'tele/example/SENSOR'</pre> | ||
+ | * For the power states: <pre>mosquitto_sub -v -h mqtt.example.com -t 'tele/example/STATE'</pre> | ||
+ | [[Category:Documentation]] | ||
+ | [[Category:Projects]] |
Latest revision as of 13:41, 24 December 2017
A MQTT controlled device that reads outdoors and indoors temperature sensors and give the user control over 8 relays, including three that have an RGB LED Stripe under the front window.
Contents
Hardware
- NodeMCU
- 5V 8 Channel Relay Board with Optocouplers
- ~3m RGB LED Strip
- Two DS18B20 Temperature Sensors. Soldered the cables together plus 4.7kΩ resistor between data and VCC on the cable.
- Two Power Supplies -- 12V 2A, 5V 1A. Separate for Isolation.
- Router Case -- From the Junk Bench
- Wiring -- 10 Pin "Dupont" Male to Male Flat Cable from Relay Board to NodeMCU.
Software
Packages
- Sonoff-Tasmota
- Mosquito MQTT server -- Default Settings (Allow Anonymous)
Tools
Atom with PlatformIO.
Config
Disabled everything that is not used by this installation, preconfigured WiFi and MQTT broker address. leet-tasmota-user_config.h
Setup
NodeMCU in Tasmota is the "WeMos D1 mini" module
mosquitto_pub -h mqtt.example.com -m '18' -t cmnd/example/module
mqtt.example.com and /example/ are fake placeholders replace with real values to actually use any of this.
The relay board expects the optocouplers to be driven low, so we use the inverted relay module. Also the NodeMCU "D" Pins and the ESP GPIO are not matching. I ordered relay modules so that they are aligned with the flat cable.
mosquitto_pub -h mqtt.example.com -m '25' -t cmnd/example/gpio16 mosquitto_pub -h mqtt.example.com -m '26' -t cmnd/example/gpio5 mosquitto_pub -h mqtt.example.com -m '27' -t cmnd/example/gpio4 mosquitto_pub -h mqtt.example.com -m '28' -t cmnd/example/gpio0 mosquitto_pub -h mqtt.example.com -m '29' -t cmnd/example/gpio2 mosquitto_pub -h mqtt.example.com -m '30' -t cmnd/example/gpio14 mosquitto_pub -h mqtt.example.com -m '31' -t cmnd/example/gpio12 mosquitto_pub -h mqtt.example.com -m '32' -t cmnd/example/gpio13
For the DS18B20 "bus" I tried gpio15 but NodeMCU wouldn't boot with DS18B20 attached, so I moved it to gpio1 which is normally Serial TX, but seems to work fine, even when upgrading firmware over usb with the sensores attached.
mosquitto_pub -h mqtt.example.com -m '4' -t cmnd/example/gpio1
Operation
Automatic
One operation is done automatically by a script. When it is dark outside it starts randomly toggle the relays in random intervals.
#!/bin/sh secs=$1 start=`date +%s` end=$((start+$secs)) while true ; do if [ `date +%s` -gt $end ]; then break fi mosquitto_pub -h mqtt.example.com -m 'toggle' -t cmnd/example/POWER$(( ( RANDOM % 3 ) + 1 )) sleep $(( ( RANDOM % 100 ) + 1 )) done mosquitto_pub -h mqtt.example.com -m 'off' -t cmnd/example/POWER1 mosquitto_pub -h mqtt.example.com -m 'off' -t cmnd/example/POWER2 mosquitto_pub -h mqtt.example.com -m 'off' -t cmnd/example/POWER3 exit 0
This script is ran by cron at sunset and exits at sunrise (~9.5h hard coded values right now)
38 19 * * * /home/user/script.sh 34260
Manual
The user can manually change the state of the relays.
Turn off the light:
mosquitto_pub -h mqtt.example.com -m 'off' -t cmnd/example/POWER1
Turn on the light:
mosquitto_pub -h mqtt.example.com -m 'on' -t cmnd/example/POWER1
Toggle the state of the light:
mosquitto_pub -h mqtt.example.com -m 'toggle' -t cmnd/example/POWER1
POWER1 Coresonds to the first relay, in the current installation the one connected at D0/GPIO16 and it controls the Red LEDs. For Green change to POWER2 and for Blue to POWER3.
Subscription
The Device periodically sends information about its state including the readings of the temperature sensors.
From the terminal you can subscribe to receive those messages periodically with (and leave it running):
- For the temperature sensors:
mosquitto_sub -v -h mqtt.example.com -t 'tele/example/SENSOR'
- For the power states:
mosquitto_sub -v -h mqtt.example.com -t 'tele/example/STATE'