Difference between revisions of "Lit"

From Hackerspace.gr
Jump to: navigation, search
m (Sotiri moved page Leet to Lit)
(No difference)

Revision as of 13:11, 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.

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):

mosquitto_sub -v -h mqtt.example.com -t 'tele/example/STATE'