Professional Documents
Culture Documents
Hardware
Last update February 07, 2017
The software described in this manual currently uses Espressif SDK 2.0 from the
Espressif forum.
It is obtainable either as ROMS which can be flashed to an ESP-12 module or as a
complete project which works in the Windows Unofficial Development Environment.
This may change as updates to the SDK are made available by Espressif (ESP8266
designers). All information and examples can be found on the blog mentioned in
here.
1
This software is free and technically unsupported..
So the basic idea here is that you would have a number of ESP-8266-based boards
working alongside an inexpensive central controller could be a Raspberry Pi2/3 or
similar setup with MQTT and Node-Red (the blog also links to a script (see blog) to
install Node-Red, SQLITE, MQTT) and various tools onto a Pi2 or 3 with minimum
effort), this software communicates via serial or (mainly) MQTT commands over WIFI
to control a range of ESP8266-based, reliable devices with facilities including:
12v RGB LED strip via 3 MOSFETs with soft fade from one state to the next
Serial LED strip (tested up to 300 RGB serial LEDs) with soft fade from one
colour to the next
HSV version of above (more intuitive)
Kelvin temperature shade version of above from 1000-4000K (sad lamp?)
LED clock using 60 serial LEDs
General serial LED output to any of the output pins
A relay (for example) output with ON/OFF and timer operations covering
minutes or seconds (the latter might be useful for watering systems, for
example)
Various temperature/humidity/pressure chips including:
2
That does not mean I accept any liability for the software or hardware which is generally
designed for our own use and made freely available to other on which to experiment and
enjoy.
My setup is shown here the incoming MQTT node is subscribed (despite the
general turm login to esplogon. Thats simple esplogon with an o. The
ESP8266 units publish to this topic on power-up.
See http://flows.nodered.org/node/node-red-contrib-esplogin for the login node and
for my general purpose timer node
If using a Dallas temperature chip (which does not do humidity) then only the
temperature message is generated. Output is in degrees C (in case you were
wondering if it was very cold here when I took that reading).
AND NOW {pressure} if using the BME280 chip on I2c on GPIO4 and 5
GPIO14 is normally used as an input and can be polled. However a debounced
output also generates an automatic message on change:
If you dont understand MQTT read the following section first better yet Google
and become familiar with the basics of MQTT it is simple and it IS worth knowing
about.
Node-Red
When I first took an interest in Home Control having developed systems
independently in the past (Appcon in the 1980s) I wanted to use a standard - but
there are so many of them some are really restrictive or expensive to use if you
are a DIY type. Many had a large learning curve for even the simplest things and
Im sorry Im not paying 30 to turn a light on.
After many false starts, it began to make sense to use an inexpensive, powerful tool
such as the Raspberry Pi 2 or 3 to control the house using the cheapest end-
controllers I could get or make. It turns out that the ESP8266 in its various forms is
the cheapest and I think best solution and that is WELL covered in the blog so I
wont develop that further here.
Software was not as straight forward lots of options but I like to do my own thing
and understand what Im doing so I took a chance when the guys at IBM came up
with Node-Red. This runs no NodeJS which Id also not heard of. In a nutshell an
extremely powerful yet extremely easy to use visual interface using drag and drop
but allowing you to program, running on the likes of the Pi with other platforms
including the web, Windows PCs and more.
To get a feel for the simplicity of Node-Red I can think of no better example than
https://fred.sensetecnic.com/ - it is a little out of date now as UI has been
replaced by the vastly superior dashboard (currently at version 2) but once you
sign up for free you can start playing with Node-Red for free and with no installation.
Alternatively Raspberry Pi now supports Node-Red by default. I have a setup script
described on the blog to set up a Raspberry Pi. Really there are links to
documentation and examples on that site. A good starting point. There are others.
Once set up for example monitoring an input on a board and sending yourself an
email if something changes or tweeting or putting a timer on an output are all
trivial and by and large visual. If you are used to traditional line by line
programming it can be an eye opener and Node-Red is very reliable.
GPIO4 EN
GPIO4 CONTROL/DATA
GPIO12 data 4
GPIO13 - data 5
GPIO15 - data 6
GPIO16 - data 7
Boards
The software requires an ESP-12 or similar with 4MB of FLASH. Older boards
currently work with no OTA but as the software gets more commands this may not
always be the case.
adc
Function:
Returns the value of the ADC
Use: adc
Example: {adc?}
Return: Mqtt adc value. Serial: string containing the ADC value
Query: yes
Stored in Flash: no
ads1115
Function:
Sets up and returns the value of an I2c ads1115 ADC board
Use: ads:integer value
Example: {ads1115:1} to set up input A0 (2,3,4 for the other 3) then {ads1115:0}
to read
Return: Mqtt adc value. Serial: string containing the ADC value
Query: yes
Stored in Flash: no
calibrate
Function:
To calibrate voltage readings on our original board
Use: calibrate:integer_value
Example: To be completed
Return: Mqtt none. Serial: OK
Query: no
Stored in Flash: Yes
cpu_freq
Function:
Double the speed of the ESP from its normal 80Mhz (80) to 160Mhz (160) or returns
the current value
Use: cpu_freq:integer_value
Example: {cpu_freq:80}
Return: Mqtt none . Serial: OK or string containing speed of chip.
Query: yes
Stored in Flash: yes
Notes: Uses more power at higher speed! Timings generally unaffected. In a test
example of an ESP-01 modified for a larger FLASH (4MBYTE), total power
consumption including 3v3 regulator varied between 30ma and 40ma at 80Meg
rising to 40ma to 50ma at 160Meg.
On1: 08:00 Off1: 12:00 On2: 15:00 Off2: 23:00 Peak: 23c Off-peak: 19c Frost: 14c
IP: 192:168:1:25
ID: freddy
DESC: empty
FLAGS:
RSSI: -47
GPIO2 is an input
Sonoff setting=0
WiFi button=2
Invert settings=HEX( 4)
Serial2 settings=0
RGB Indicator=1
Electrodragon=0
No LED clock
Up Time: 0:25:54
dusk
Function:
To pass dusk to the unit number of minutes after midnight
Use: dusk:integer_dusk
Example: {dusk:1000}
Return: Mqtt none. Serial: OK
Query: no
Stored in Flash: no
enable13
Function:
Enable or disable GPIO13 as a general purpose output normally used as a status
indicator
Use: enable13:integer_parameter // can be 1 or 0
Example: {enable13:1} or {enable13:0}
Return: Mqtt none. Serial: OK
Query: no
Stored in Flash: yes
Notes: See rgb_ind
enable16
Function:
Allows general use of GPIO16 as an output when wifi_button is 2
Use: enable16:integer_parameter // can be 1 or 0
Example: {enable16:1} or {enable16:0}
Return: Mqtt none. Serial: OK
Query: no
Stored in Flash: no
flashsize
Function:
Returns manufacturer info on Flash size
Use: flashsize
Example: {flashsize?}
Return: Mqtt Flash size . Serial: string containing flash size
Query: yes
Stored in Flash: no
Notes: Not foolproof as not ALL Flash has the info.
gy30_init
Function:
Initialise I2c light sensor
Use: gy30_init
Example: {gy30_init:35}
Return: ok
Query: no
Stored in Flash: no
heap
Function:
Return heap size in bytes
Use: heap
Example: {heap?}
Return: Mqtt none. Serial: value
Query: no
Stored in Flash: no
hightemperature
Function:
To return temperature value * 10 with more precision than temperature
Use: hightemperature?
Example: {hightemperature?}
Return: Mqtt temperature * 10. Serial: string including temperature
Query: yes
Stored in Flash: no
Notes: See temperature
id
Function:
Set or read the name of the board
Use: id
Example: {id:kitchen_lamp} or {id?}
Return: Mqtt nothing. Serial: string containing the ID string if query or OK
Query: yes
Stored in Flash: yes
Notes: You should reboot after setting the ID
in_2bounce
Function:
Integer sets timing for bounce
Use: in_2bounce:integer_value (*25ms)
Example: An mqtt message will be generated when the threshold count is reached
after a level change on gpio2.
Return: Mqtt none . Serial: none
Query: no
Stored in Flash: yes
in14_count
Function:
Reads the number of state changes GPIO14 and kills the count
Use: in14_count
Example: {in14_count?}
Return: Mqtt value of counter. Serial: string containing value of counter
Query: yes
Stored in Flash: no
invert
Function:
To invert outputs as a group when using OUTx controls ignored by RGB and PWM
commands
Use: invert:integer-mask
Example: {invert 5} inverts OUT0:x and OUT4:x controls
led_timer
Function:
To temporarily alter the default 20ms LED timer for RGB/HSV timing etc.
Use: led_timer:integer_value
Example: {led_timer:1000}
Return: Mqtt none. Serial: OK
Query: no
Stored in Flash: no
Notes: minimum value 20 but is 32 bit so you should be able to make for a
ridiculously long timer value
mqtt_host
Function:
Set the address of the MQTT broker can be IP or full address
Use: mqtt_host:string_parameter
Example: {mqtt_host:192.168.0.10}
Return: Mqtt nothing. Serial: OK
Query: no
Stored in Flash: yes
Notes: Needs reboot to take effect
mqtt_port
Function:
Set the port of the MQTT broker usually 1883
Use: mqtt_port:integer_parameter
Example: {mqtt_port:1883}
Return: Mqtt nothing. Serial: OK
Query: no
Stored in Flash: yes
Notes: Needs reboot to take effect
nano
Function:
An early attempt at an Arduino-Nano-based universal i2c peripheral
Use: nano: integer_device, integer_command, integer_value1,integer_value2
Example: {nano:9,1,13,1} or {nano:9,2,12}
Return: Mqtt if 3 parameter query returns value else nothing. Serial: value or OK
Query: Yes but no question mark needed
Stored in Flash: no
Notes: Device can be changed by a command current commands are as follows:
SET_OUTPUT 1
READ_INPUT 2 (no pullups)
READ_INPUT 3 (inputs are set to pullup mode 20k internal pullup resistor)
SET_PWM 4 (values 0-255 only please)
READ_ANALOG 5 (reads 10 bit value back)
SET_ADDRESS 6 (note that address change has no effect until next powerup)
otaupdate
Function:
To update the code from an OTA server i.e. any old webserver able to return a .bin
file
Use: otaupdate
Example: {otaupdate} causes a reboot on success
Return: Mqtt none. Serial: some status info before the unit reboots
Query: no
Stored in Flash: n/a
0 off (if command {invert:1} then state is inverted (for positive-based relays)
1 on (see above)
-1 toggles the output between off and on. Handy for pushbuttons
7+ under thermostatic control holding at FROST temperature for every increase in
the number, frost status lasts one hour. So value 7 means stay at frost temperature for
2 hours then revert to thermostatic control. *
Example: {out0:1}
Return: Mqtt value of port if query . Serial: string containing value of port if query
or OK
Query: yes
Stored in Flash: yes
Notes: See wifi_button
0 off (if command {invert:4} then state is inverted (for positive-based relays)
1 on (see above)
-1 toggles the output between off and on. Handy for pushbuttons
Example: {out4:1}
Return: Mqtt value of port if query . Serial: string containing value of port if query
or OK
Query: yes
Stored in Flash: yes
0 off (if command {invert:8} then state is inverted (for positive-based relays)
1 on (see above)
-1 toggles the output between off and on. Handy for pushbuttons
Example: {out5:1}
Return: Mqtt value of port if query . Serial: string containing value of port if query
or OK
Query: yes
Stored in Flash: yes
1 on (see above)
-1 toggles the output between off and on. Handy for pushbuttons
Example: {out12:1}
Return: Mqtt value of port if query . Serial: string containing value of port if query
or OK
Query: yes
Stored in Flash: yes
1 on (see above)
-1 toggles the output between off and on. Handy for pushbuttons
Example: {out13:1}
Return: Mqtt value of port if query . Serial: string containing value of port if query
or OK
Query: yes
Stored in Flash: yes
Notes: Check enabled13 command first generally this port is reserved for status
indicator
1 on (see above)
-1 toggles the output between off and on. Handy for pushbuttons
Example: {out14:1}
Return: Mqtt value of port if query . Serial: string containing value of port if query
or OK
Query: yes
Stored in Flash: yes
Notes: See enable14 Normally GPiO14 is an input
1 on (see above)
-1 toggles the output between off and on. Handy for pushbuttons
Example: {out15:1}
Return: Mqtt value of port if query . Serial: string containing value of port if query
or OK
Query: yes
Stored in Flash: yes
1 on (see above)
-1 toggles the output between off and on. Handy for pushbuttons
Example: {out16:1}
Return: Mqtt value of port if query . Serial: string containing value of port if query
or OK
Query: yes
Stored in Flash: yes
Notes: Check your board does not tie GPIO16 to reset. See wifi_button which must
be set to 0 for GPIO16 to work as an output. If you set wifi_button to 0, you must
reset the board before this will take effect and GPIO16 becomes available.
0 off (high)
1 on (low)
Or
Xport:integer_value
pass2
Function:
Set the second password string of the network
Use: pass2:string_password
Example: {pass2:myotherpassword}
Return: Mqtt nothing. Serial: OK
Query: no
Stored in Flash: yes
Notes: See SSID2. Needs reboot to take effect
{pca9685:64,4,80} etc
{pca9685:64,8,160}
{pca9685:64,16,320}
{pca9685:64,32,1200}
{pca9685:64,64,2200}
{pca9685:64,128,4096}
port2out
Function:
Set to 1 to make GPIO2 an output
Use: port2out:integer_value
Example: {port2out:1}
Return: Mqtt value if query. Serial: value if query or OK
Query: yes
Stored in Flash: yes
pwmhsv
Function:
As for PWM but with HSV values (hue, saturation, brightness)
Use: pwmhsv:integer_hue (0-359), integer_s (0-255), integer_v (0-255),
integer_timing(optional min 20)
Example: {pwmhsv:99,40,20 }
Return: Mqtt none. Serial: OK
Query: no
Stored in Flash: no
Notes: The Espressif PWM is done under interrupts and no matter what, once you
start this up it WILL be running in the background. I2C may not work properly and
even RGB LEDs may fail. A better way might be to use a PWM expander board on
rebootnow
Function:
Reboot the board without storing anything in flash
Use: reboot_now
Example: {rebootnow}
Return: Mqtt none. Serial: none
Query: N/A
Stored in Flash: N/A
reset_config
Function:
Wipes config to defaults and resets the board warning you may lose access other
than via serial.
Use: reset_config
Example: {reset_config}
Return: Mqtt none . Serial: none
Query: no
Stored in Flash: yes
rgb_lcd
Function:
A series of functions to work with the Grove-LCD RGB Backlight boards which offer
16-char by 2 line Hitachi-style LCD but with RGB backlight. Includes _setup, _clear,
_cursor, _background and _write.
Use: rgb_ind:integer_value
Example:
{rgb_lcd_setup}
{rgb_lcd_background:255,0,0}
{rgb_lcd_cursor:0,0}
{tgb_lcd_write:Hi there}
Return: Mqtt none . Serial: OK
Query: no
Stored in Flash: no
rgbinstant
Function:
Allow for instant setting of serial RGB lights.
Use: rgbinstant:integer_gpio, integer_red(0-255), integer_green(0-255),
integer_blue(0-255), optional_integer_number (optional default 1)
Example: {rgbinstant:4,255,255,255}
Return: Mqtt none . Serial: OK
Query: no
Stored in Flash: no
Notes: switching large numbers of LEDs may cause undulation in PWM outputs due
to interrupts not as bad as the normal RGB commands however. With small
numbers, un-noticeable
rgbset
Function:
Fills in an array of values for the rgbgo command
Use: rgbset: integer_start, integer_number, integer_red(0-255), integer_green(0-
255), integer_blue(0-255)
Example: {rgbset:0,10,255,0,0}
Return: Mqtt none. Serial: OK
Query: no
Stored in Flash: no
Notes: In the above example, the buffer will be set so that the first 10 leds (out of
max 300) are set to red. Nothing will happen until the rgbgo command is used.
scan
Function:
Only works in serial scan for WIFI
Use:scan
Example: {scan} lists available SSIDs on success
Return: Mqtt none. Serial: list of SSIDs
Query: no
Stored in Flash: no
ssid
Function:
Set the ssid string of the network
Use:ssid
Example: {ssid:kitchen_wifi}
Return: Mqtt nothing. Serial: OK
Query: no
Stored in Flash: yes
Notes: Needs reboot to take effect
swap
Function:
Sets which SSID to try first on next boot (or returns 0 or 1)
Use:swap:integer_parameter 0 or 1
Example: {swap:1}
Return: Mqtt nothing. Serial: string containing 0 or 1 if query or OK
Query: yes
Stored in Flash: yes
Notes: Needs reboot to take effect
temp_type
Function:
To set the type of temperature sensor if any, normally used on GPIO2 can be 14
see below.
Use: temp_type:integer_parameter
Example: {temp_type:1}
Return: MQTT none. Serial: OK
Options:
0 DS18b20
1=DHT22
2=DHT11
3=BME280 on address 0x76
4=BMP280 on address 0x77 with (as appropriate to model) CSB at 3v3 and SDO at
3v3
Query: no
Stored in Flash: yes
See also: temperature port. BME280 uses GPIO4 and 5 for I2C. Depending on the
chip used, see also {temperature?}, {pressure?} and {humidity?}
time
Function:
To pass time to the unit in standard long number form number of seconds since
Jan 1970
Use: time:integer_time
Example: {time:34248792}
Return: Mqtt none. Serial: OK
Query: no
Stored in Flash: no
timeout_clear
Function:
Reset the monostable so something would call this regularly to stop the
monostable triggering
Use: timeout_clear
Example: {timeout_clear}
Return: Mqtt none . Serial: OK
Query: no
Stored in Flash: no
Notes: See timeout_set
uptime
Function:
returns a string in h:mm:ss since power up 32 bits so can handle long period. reset
on powerup or system reset.
Use: uptime?
Example: {uptime?}
Return: Mqtt string value . Serial: string value
Query: yes
Stored in Flash: no
voltage
Function:
Returns the value of the ADC converted to voltage assuming use of our board with
dividers
Use: voltage
Example: {voltage?}
Return: Mqtt voltage value. Serial: string containing the voltage value
Query: yes
Stored in Flash: no
web_setup
Function:
Causes the unit to reset into web setup mode as if youd pressed the button
Use: web_setup
Example: {web_setup}
Return: Mqtt none . Serial: none
Query: no
Stored in Flash: N/A