Documente Academic
Documente Profesional
Documente Cultură
ESP-12 Hardware
Last update August 21, 2018
The software (ESP-GO) described in this manual is version 2.5.05 and it currently uses Espressif SDK 2.1.0
from the Espressif forum.
ESP-GO is obtainable either as ROMS which can be flashed to an ESP-12 or similar module or as a
complete project which works in the Windows Unofficial Development Environment.
All information and examples can be found on the blog mentioned in the footer. See also my video
channel at https://wwww.youtube.com/peterscargill
The software started off life as an extension of TUANPM’s MQTT demonstration software but rapidly
developed from there. Over time I added more and more of my own code and of course bits and pieces
from around the web as I learned more and more about the ESP8266 – one of the most useful and best
value WIFI modules in the IOT world. The code is tested to work with various generic ESP-12 boards
detailed in the blog at https://tech.scargill.net - Article "Home Control 2018" and boards designed by
Aidan Ruff and myself, used in the Nextion project (all on the blog) which incidentally won 2 nd place in
the first ESP8266.com awards in April 2016. Aidan Ruff’s board designs are usually up on the blog or you
can talk to him directly. I am currently using the Chinese Wemos Mini D1 boards which work fine (except
you would need to use an off-board health indicator LED). Note that the Wemos boards program using
DIO mode, most others use QIO mode.
Important: Adding more features and fonts to this software including a large 7 segment font in FLASH
for the ILI display means I’ve long since given up on the original ESP8266 boards with only 512KB of
FLASH –I use ESP-12 based boards with 4MB of FLASH or more (and encourage Itead to put 4MB in all
of their boards so we don’t have to bodge them).
The current software plus SDK, despite its size, leaves a quite reasonable amount of free RAM.
1
This software is free and technically unsupported.
Preface.....................................................................................................................................................3
Contents..................................................................................................................................................4
In a Nutshell...........................................................................................................................................10
Automatic responses.............................................................................................................................14
Node-Red...........................................................................................................................................16
MQTT.................................................................................................................................................17
OLED displays.........................................................................................................................................23
When the board initialises, it sends out mqtt xxxx/fromesp/status and payload {powerup}................31
QD_TECH Displays.................................................................................................................................35
Sleep_mode...........................................................................................................................................37
Deep_sleep............................................................................................................................................37
General Commands...............................................................................................................................39
Queries..................................................................................................................................................40
Boards....................................................................................................................................................40
List of Commands..................................................................................................................................42
ads1115.............................................................................................................................................42
attrib..................................................................................................................................................43
calibrate.............................................................................................................................................43
clock...................................................................................................................................................44
comment...........................................................................................................................................44
cpu_freq............................................................................................................................................44
dawn..................................................................................................................................................46
debug.................................................................................................................................................47
desc...................................................................................................................................................49
dusk...................................................................................................................................................49
electrodragon....................................................................................................................................50
enable13............................................................................................................................................50
enable14............................................................................................................................................51
enable16............................................................................................................................................51
ext......................................................................................................................................................52
flashsize.............................................................................................................................................52
gettime..............................................................................................................................................53
gy30_init............................................................................................................................................53
gy30_read..........................................................................................................................................54
heap...................................................................................................................................................54
hitachi................................................................................................................................................55
hightemperature................................................................................................................................55
hsv.....................................................................................................................................................56
humidity............................................................................................................................................57
i2c......................................................................................................................................................58
i2c_check...........................................................................................................................................59
in14....................................................................................................................................................60
in_2bounce........................................................................................................................................60
in_14bounce......................................................................................................................................61
in14_count.........................................................................................................................................61
in2_count...........................................................................................................................................62
ina219_begin.....................................................................................................................................62
ina219_getall.....................................................................................................................................63
ina219_getcurrent.............................................................................................................................64
ina219_getvoltage.............................................................................................................................64
invert.................................................................................................................................................65
invertset.............................................................................................................................................66
invertreset.........................................................................................................................................67
ip........................................................................................................................................................67
kelvin.................................................................................................................................................68
led_timer...........................................................................................................................................68
mist....................................................................................................................................................70
mqtt_host..........................................................................................................................................70
mqtt_pass..........................................................................................................................................71
mqtt_port..........................................................................................................................................71
mqtt_user..........................................................................................................................................72
nano...................................................................................................................................................73
ota_host.............................................................................................................................................74
ota_port.............................................................................................................................................75
otaupdate..........................................................................................................................................75
out0...................................................................................................................................................76
out5...................................................................................................................................................78
out12.................................................................................................................................................79
out13.................................................................................................................................................80
out14.................................................................................................................................................81
out15.................................................................................................................................................82
out16.................................................................................................................................................83
xport..................................................................................................................................................84
pass....................................................................................................................................................85
pass2..................................................................................................................................................85
pca9685.............................................................................................................................................86
polling_interval..................................................................................................................................87
port2out............................................................................................................................................87
pwm...................................................................................................................................................88
pwmhsv.............................................................................................................................................88
rainbow..............................................................................................................................................89
readtemperature...............................................................................................................................89
rebootnow.........................................................................................................................................90
reset...................................................................................................................................................91
reset_config.......................................................................................................................................91
rgb_ind..............................................................................................................................................92
rgb_lcd...............................................................................................................................................92
rgb.....................................................................................................................................................93
rgbgo..................................................................................................................................................94
rgbinstant..........................................................................................................................................94
rgbstop...............................................................................................................................................95
rgbset.................................................................................................................................................95
rgbperm.............................................................................................................................................98
romswitch..........................................................................................................................................99
scan....................................................................................................................................................99
set_serial.........................................................................................................................................100
sonoff...............................................................................................................................................102
ssid...................................................................................................................................................102
ssid2.................................................................................................................................................103
swap................................................................................................................................................103
temperature....................................................................................................................................104
temp_type.......................................................................................................................................104
temperature_port............................................................................................................................105
time.................................................................................................................................................105
timeout_set.....................................................................................................................................106
timeout_clear..................................................................................................................................106
to_nextion.......................................................................................................................................107
to_serial2.........................................................................................................................................108
uptime.............................................................................................................................................108
ver....................................................................................................................................................109
voltage.............................................................................................................................................109
warning............................................................................................................................................110
web_setup.......................................................................................................................................110
wifi_button......................................................................................................................................111
xport................................................................................................................................................111
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 “the Script”(see blog) to install Node-Red, SQLITE, MQTT and various tools onto a
Pi2 or 3 and similar with minimum effort), ESP-GO communicates via serial or (mainly) MQTT commands
over WIFI to control a range of ESP8266-based, reliable devices with facilities. Features of the software
include:
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-RGB-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:
o Dallas DS18b20 – temperature
o DHT11, DHT22 – temperature and humidity
o BMP280 - temperature and pressure
ESP-GO needs the 4MB Flash of the likes of the ESP-12. It will not work with older boards with less FLASH
– if you want to run Sonoffs without modification, consider Tasmota.
Older boards can generally be upgraded with a cheap FLASH chip and a fine soldering iron. I have
blogged how to do this. See https://tech.scargill.net/esp8266-home-control-update/
There is an on-board 3v3 linear regulator on our own board designs to ensure a smooth supply to the
ESP. Extensive experience suggests that the software is rock-solid – however – no guarantees. The
author has 2 houses both of which rely on several of these boards working 24-7 2 and they are in two
different countries so “popping in” to fix is not an option.
In order for this all to work correctly, ESP8266 boards with ESP-GO, at power up will try to log into a
general WIFI access point – clearly you will need to alter the SSID and password of this along with details
of your MQTT “broker” – either by serial commands – or by WIFI setup.
When I set up my boards - I send this serially (115Kbaud) using my terminal program.
{ssid:"wififorus"}
{ssid2:"wififorus"}
{pass:"xxxxxxxxxxx"}
{pass2:"xxxxxxxxxxx"}
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.
You must set your access point up, with or without a password. There is a second access point entry for
fall-over. Make the second one the same as the first if you only wish to use one access point.
You should then set up the address and optional port, username and password of your MQTT server. For
my own purposes I use an MQTT broker with username and password on the default port 1883.
This will get you started – the board will log into your access point, then it will connect to your MQTT
server – and it will try to log in. It will do this repeatedly, handing over its ID and description via MQTT
until it gets a response.
It is possible to respond using MQTT from a command line – but it is a lot easier to let my Node Red
NODE handle logging in and responding for you. The node can be installed as npn install node-red-
contrib-esplogin.
My setup is shown here – the incoming MQTT node is subscribed (despite the general term “login” to
esplogon. That’s simple “esplogon” with an ‘o’. The ESP8266 units publish to this topic on power-up.
http://flows.nodered.org/node/node-red-contrib-bigtimer
The only output on that yellow login nodeabove that you need to use is the first one and that is fed to an
MQTT output – no info necessary other than the correct MQTT setup – the rest is optional speech
output, log file output and Sqlite output.
With this in place, the boards should log in – get the time and more from the yellow ESPLOGIN node and
that’s about it. The same node will refresh them every day automatically with the time – and of course,
any time they log in (after a power failure for example).
Elsewhere you will find info on the “Nano peripheral” – code for the Atmega 328 boards with all 6 analog
inputs available from AliExpress and elsewhere for around £1.50 sterling. The software is ready to go and
supported by ESP-GO – massively increasing the IO capability of the ESP8266 at the expense of losing
GPIO4 and 5 for I2c control (those pins can simultaneously drive other supported I2c chips).
If a DHT11 or DHT22 sensor is selected {temp_type:x} (for values of x read the relevant command) then
readings are currently taken every 30 seconds and stored in variables which can be polled at any time –
however, MQTT messages are also automatically generated.
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 (SDA) and 5 (SCL)
GPIO14 is normally used as an input and can be polled. However as a debounced input it also generates
an automatic message on change:
Using the command {input45:45} puts GPIO4 and 5 into input mode with pull-ups (survives power
cycling) so they can generate similar trigger messages. Note that any other value (i.e. {input45:0})
returns 4 and 5 to normal use.
GPIO2 can do the same as GPIO14 but it is also used for a variety of other purposes – for example can be
used as the web-setup pin or temperature sensing pin. To enable GPIO2 to act as another debounced
input pin you should first ensure that it is not being used for other purposes.
For example – let’s say you want automatic readings from GPIO2 (typical) using a DHT22 chip. Set
{temperature_port:2} and {temp_type:1}
From there on – you may see this when monitoring MQTT – in my case – from the pergola. If Node Red
subscribes to “pergola/fromesp/auto_temperature” and “pergola/fromesp/auto_humidity” it will
receive this information regularly.
If you don’t understand MQTT – read the following section first - better yet – Google it and become
familiar with the basics of MQTT – it is really simple and it IS worth knowing about.
Node-Red
When I first took a serious interest in Home Control having developed systems independently in the past
(Appcon in the 1980s) I wanted to use a set of standards - 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 I’m sorry – I’m 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 VERY cost-effective and I think best low-cost solution – and
that is WELL covered in the blog so I won’t develop that further here.
Software was not as straight forward – lots of options – but I like to do my own thing and I’m keen to
learn, so I took a chance when the guys at IBM came up with Node-Red. This runs NodeJS which I’d not
heard of at the time. 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 Raspberry Pi – also available on
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/ - once you sign up for free you can start playing with Node-Red for free
and with no installation. Note that Raspberry Pi now supports Node-Red by default. I have a setup script
described on the blog and called “the Script” to set up a Raspberry Pi or similar (and in fact in my setup I
remove the default Raspberry Pi Node-Red installation and start from scratch, including a wide variety of
“nodes”. Anyway – there are links to documentation and examples on that Sensetronic site. A good
starting point. There are others.
Once Node-Red is 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, Node-Red is very
reliable and fun to use.
Fast and efficient, communication is made in this project either serially by sending commands to the
ESP8266 boards or by sending a topic and a payload (with the command in it) via MQTT over WIFI. MQTT
is ideal for IOT applications because it is simple and easy to understand.
You can install an MQTT “broker” or server on a Raspberry Pi for example – or there are public brokers –
it’s a big subject but keep in mind that at the end of the day it is not complicated - the codes overleaf are
my own – not some complex part of MQTT. In the simplest case you send a TOPIC which is a text-based
field – and a PAYLOAD which is also a text-based field. The topic is to identify where the payload must go
to (destination) – the payload is whatever you want. An ESP8266 unit (such as ESP-GO) equipped with
an MQTT client “subscribes” to a topic or topics and the broker both accepts messages and makes sure
they get to who they’re supposed to. So the broker, wherever it is located helps form a comms network
– really WAY easier to use than explain.
To become familiar with MQTT you can mess with MQTT by using a public broker and the free MQTT-SPY
(client). A couple of machines running MQTT-SPY can send messages to each other via the broker. It is
even fun once you grasp it. Certainly it does not need to be any harder than sending text messages. A
client “listens” for a particular topic or topics. There are many explanations of MQTT on the web.
Together, Node-Red and MQTT make a powerful tool – any device on the system can talk to Node-Red or
to any other device. Personally rather than having a million protocols I like to make everything talk to
Node-Red via MQTT – then it can decide what to send out to whom. With the many “nodes” available
for Node-Red including my own BIGTIMER and others – what you can do is largely down to your
imagination. I usually add SQLITE into the installation as a simple database for logging information that is
not too heavy on writing (excessive writing is not good for SD-based boards such as the PI) and as well as
automatic timing I have devices controlled by mobile phone (Node-Red-Dashboard) and Amazon Alexa
voice control.
A simple command {clock:0} for example will start a serial RGB LED clock on GPIO0 and this will be
maintained through power cycle. The clock knows the time because the central server (Pi or similar)
sends the time in the logon system. The clock uses serial LEDs and needs 60 of them. You can do this
with some RGB serial LED strip – or you can buy a 60 LED ring usually in the form of four quadrants. The
likes of AdaFruit sell them but on EBay, Electronics Lee sells them for less.
http://www.uctronics.com/ring-wall-clock-60-ultra-bright-ws2812-5050-rgb-led-lamp-panel-for-
arduino.html?___SID=U
Around £12 for the entire ring – you just need to solder the bits together. EBay sell plastic disks as well!!
So typically you are looking at 5v, signal and ground – I’ve used variable brilliance lighting to give a wide
bar for hours (5 LEDS) and the single LED is seconds… All looks lovely in the dark!
To end this – set the number to 255 i.e. {clock:255}. Don’t set the clock to use an input.
So what you’re looking at on the right – the glowing thing at the top is an
FTDI – basically there for me to program with and to provide a little power.
The blue prototyping board is in fact a test board - an ESP-12 with a
regulator running my software as described in here.
The red thing in the middle is an i2c expander – cheap – basically i2c in on
2 wires (the expander has its own pull-up resistors) – 8 IO lines. Here, I’m
using them only as IO and I’m only using 6 of them – the top 4 data lines,
enable and the control line.
The least significant bit is enable, next is the control line, top 4 are MSB
data lines on the LCD.
Essentially – from either MQTT or serial you fire a command at the ESP
board and text appears on the LCD. There are of course some set up and
control commands and I’ve incorporated them into a string.
In the example you see here, this is the string I fire at the display every
second from MQTT
Simple enough, device 39 (in this case) and some text with control signals starting with $
$p and $h – temperature and humidity readings – assuming you have a sensor running and wait a couple
of mins before using after power up. Note temperature and humidity readings remain at 0 (zero) until
WIFI and MQTT are connected.
GPIO4 – EN
GPIO4 – CONTROL/DATA
GPIO12 – data 4
GPIO13 - data 5
GPIO15 - data 6
GPIO16 - data 7
You should ground the Read/Write pin on the LCD – and you
may wish to consider a resistor from the contrast pin to ground –
150 ohms is generally ok – and some LCDs may require separate
wiring for backlighting (I just took the backlighting A to +5v, K to
ground).
Note that the instant you use this – any flashing light on GPIO13 will stop – can’t have it both ways
This of course leaves you with GPIO2 and 14 for use as inputs – just a thought – GPIO2 as temperature
sensor – GPIO14 as up/down temperature control.
Example: {seeed:$s$g3Hello$g11Hello”}
{seeed:"$sHello there$5$i$6temp:$pc$7Hum:$h%$11$t"}
See also OLED further down – the seeed displays are now
deprecated in favour of standard ssd1306 OLED displays.
With apologies to anyone using the older command sequence I’ve updated this to match other OLED
displays (other than the SEEED one which is now deprecated). These SSD1306 displays in both 128x64
and 128x32 form are cheap and exceedingly useful – you can even buy an ESP8266 board with one build
in!
Numerical arguments are comma or semicolon delimited and the actual number can be missed out if the
required value is 0... if the next character is non-numeric, even the trailing semicolon/comma is un-
necessary - i.e. $P,Hello
Setup (number 0 for the 32 line display, 1 for the 64 line display. Default 32 line)
Position (x,y)
Mono (1 or 0)
Font (0-12)
Line (x1,y1,x2,y2)
rEctangle (x,y,width,height) (foreground colour)
fIll (x,y,width,height) (foreground and background colours)
Wipe to background
Time
Example – puts up “Hello” – the time and date and a coloured rectangle
{ssd1306:"$S$P10,10;$C255,255,255;Hello\n$T\n$D$B0,0,255;$I80,80,30,30"}
Or..
{ssd1306:"$S1Hello !!!$P0,10$O$P0,20$V$P0,30$N$P0,40$U$P0,50$R"}
For wiring:
It is assumed only one SPI device is used hence tie CS low and RST to processor reset:
// WEMOS D7 ESP8266 GPIO13 is MOSI (dout)
// WEMOS D5 ESP8266 GPIO14 is clock
// WEMOS D0 ESP8266 GPIO16 as the D/C line.
// 5v power and ground
The “ssd1351” function handles everything in the string using $ to start off special commands - $$ to
show a dollar sign.
Numerical arguments are comma or semicolon delimited and the actual number can be missed out if the
required value is 0.. so for example - $C255,0,0; which is colour RED can also be expressed as $C255,,; -
if the next character is non-numeric, even the trailing semicolon/comma is un-necessary - i.e.
$C255,,Hello
Setup
Position (x,y)
Colour (r,g,b)
Background (r,g,b)
Mono (1 or 0)
Font (0-12)
Rotate (1 or 0)
Line (x1,y1,x2,y2)
rEctangle (x,y,width,height) (foreground colour)
fIll (x,y,width,height) (foreground and background colours)
Wipe to background colour
Time
Date
Address (IP address)
Example – puts up “Hello” – the time and date and a coloured rectangle
{ssd1351:"$S$P10,10;$C255,255,255;Hello\n$T\n$D$B0,0,255;$I80,80,30,30"}
{ili_set:1}
{ili_text:"\e[35;40mHello there \e[32;40mmate\r\n"}
{ili_status:"All working exceedingly well"}
{ili_title:"\e[37;40mESP8266 Status Monitor"}
{ili_rssi}
The ili_set command if set to 1 will immediately reset the display and enable it to accept messages – this
survives power out and the display will automatically initialise on power-up. Setting the value to 0
disables the display – again through power cycling.
// WEMOS D7 ESP8266 GPIO13 is MOSI (dout)
// WEMOS D5 ESP8266 GPIO14 is clock
// WEMOS D0 ESP8266 GPIO16 as the D/C line.
// 5v power and ground – the backlight should be connected to 3v3 – not 5v.
So then given the unit name of “thisone” a simple bit of Node-Red directs all MQTT traffic to the display
(along with some colour commands).
tmpPayload=msg.payload;
tmpTopic="\\e[36;40m"+msg.topic+"\\e[32;40m\r\n";
if (msg.topic!="thisone/toesp")
{
msg.topic="thisone/toesp";
msg.payload="{ili_text:\"" + tmpTopic + tmpPayload + "\r\n\"}";
return msg;
}
I’ve deliberately stopped traffic for that unit – as it ends up in infinite loop otherwise. For wiring, the LED
requires +3v3 (don’t connect the LED to +5v – it will look good but soon burn out) and power for the
board need to go to +5v, reset goes either to the ESP8266 reset or via a 4k7 to +3v3…. and then
GPIO14=SCLK, GPIO13=MOSI, GPIO15=CS and GPIO16=D/C - MISO (last pin) is not used.
No, the software does not support a whole other range of boards, just this one – but as it’s one of the
cheapest out there, that’s fine.
The ili_rssi command puts up (in the status line) the current time and date bottom left and a rough signal
strength for this particular ESP along but that only works of course assuming you are using my Node-Red
node which updates the ESP8266 boards with the correct time.
This seems to be surviving constant testing – I even took it for a walk using a battery pack and it survived
going out of signal range and coming back in. Clearly the use of these ports on the ESP8266 stops some
other operations thanks to using their pins… but what a great general purpose MQTT display!
Important note: The {ili_set:1} command survives power cycling – do not leave this on when playing
with the landscape mode or other display boards as it will fire out commands not appropriate to
anything other than the terminal mode. Turn it off if you don’t plan to use terminal mode with the
ILI8340 display.
The “ili” function handles everything in the string using $ to start off special commands - $$ to show a
dollar sign.
Numerical arguments are comma or semicolon delimited and the actual number can be missed out if the
required value is 0.. so for example - $C255,0,0; which is colour RED can also be expressed as $C255,,; -
if the next character is non-numeric, even the trailing semicolon/comma is un-necessary - i.e.
$C255,,Hello
Setup
Position (x,y)
Colour (r,g,b)
Background (r,g,b)
Mono (1 or 0)
Font (0-12)
Rotate (1 or 0)
Line (x1,y1,x2,y2)
rEctangle (x,y,width,height) (foreground colour)
fIll (x,y,width,height) (foreground and background colours)
Wipe to background colour
Both this display and the qdtech driver mentioned elsewhere have the following fonts available by
number (default is font 0):
0 calibri16x17
1 digital36x69
2 digital17x32
3 trebuchet
4 calibri21x22
5 calibri32x34
6 petesfont24x28
7 meteocons21x25
8 ms_reference_sans_serif16x16
9 basic8x8
10 assorted1_19x21
11 assorted2_19x21
12 assorted3_19x21
When the board initialises, it sends out mqtt xxxx/fromesp/status and payload {powerup}
This can be used to send $S and any line framework and fixed text to the display. Same for the QDTech.
Using this single pin you could for example control set temperature on a thermostat, you could even use
i2c temperature sensors, or you may wish for more control and handle sensors elsewhere.
See example on previous page. A touch button cycles through a range of available set temperatures.
To do the latter, there is a command (the change survives power cycling) – topic = myboard/toesp
payload = {input45:45}
Any value other than 45on the right above and gpio pins 4 and 5 work as normal, however with this
command and the value 45, you can turn gpio4 and 5 into inputs which will automatically generate those
auto responders only change of state of the relevant input pin. There are weak pull-up resistors in the
ESP8266 chip so no need to worry about that, buttons can simply ground the two inputs when pressed.
msg.payload='{ili:"$S"}'; node.send(msg);
msg.payload='{ili:"$C255,255,255$E0,0,320,240"}'; node.send(msg);
msg.payload='{ili:"$L0,37,319,37"}'; node.send(msg);
msg.payload='{ili:"$L0,194,319,194"}'; node.send(msg);
msg.payload='{ili:"$L280,38,280,194"}'; node.send(msg);
Example icons and weather code from a service – icons are in the icon sets available:
var currently=global.get("weather").daily.data[0].icon;
var tomorrow=global.get("weather").daily.data[1].icon;
var day3=global.get("weather").daily.data[2].icon;
var day4=global.get("weather").daily.data[3].icon;
var day5=global.get("weather").daily.data[4].icon;
var day6=global.get("weather").daily.data[5].icon;
var precip=global.get("weather").daily.data[0].precipProbability;
node.status({fill:"blue",shape:"dot",text:precip});
precip=120-parseInt(precip*120);
msg.payload='{ili:"$C255,255,255$B255,0,0$I260,60,10,120$B0,0,255$I260,60,10,' + precip +
'$B0,0,0";}'; node.send(msg);
I’ve now updated the code for these displays to use the same –in-
string controls I’ve put on other LCD boards. That means that the
string “$S” initialises the display. Setup for the display is volatile and
deliberately does not survive reboot – so this is the first thing you do
in initialisation of your display on power up or reboot.
The “qd_string” function handles everything in the string using $ to start off special commands ( $$ to
show a dollar sign).
Numerical arguments are comma or semicolon delimited and the actual number can be missed out if the
required value is 0.. so for example - $C255,0,0; which is colour RED can also be expressed as $C255,,; -
if the next character is non-numeric, even the trailing semicolon/comma is un-necessary - i.e.
$C255,,Hello
Setup
Position (x,y)
Colour (r,g,b)
Background (r,g,b)
Mono (1 or 0)
Font (0-12)
Rotate (1 or 0)
Line (x1,y1,x2,y2)
rEctangle (x,y,width,height) (foreground colour)
fIll (x,y,width,height) (foreground and background colours)
Wipe to background colour
Time
Date
Address (IP address)
Graphic (number 1-3 followed by character)
For example – puts up “Hello” – the time and date and a coloured rectangle
This translates to – initialise the display, set the cursor to 10,10, the colour to white and print “Hello2” –
followed by carriage return then the Time, carriage return then the data. Then set the background colour
to blue and fill a rectangle at 180,80 size 30 by 30.
When using the display, GPIO13 will stop acting as a flashing indicator because it is needed to supply
data to the board.
In order to do deep sleep – which can put the processor into low power deep sleep for up to 71 minutes
(4260 seconds) – GPIO16 must be deployed. It should have some kind of pull-up to 3v3
As you may realise by now – GPIO16 is used a lot for a general purpose output. So before any deep sleep
can happen, GPIO16 must be disabled as an output – a record must be stored of this so it won’t turn into
an output on power-up – and a record must be stored that we’re in deep sleep “mode”. This is all done in
the sleep_mode command,
Sleep_mode
{sleep_mode:1} Once you send that command, GPIO16 is no longer generally usable – this will survive
power cycling. ONLY after issuing this command, you can attach GPIO16 to the RESET line.
{sleep_mode:0} will restore GPIO16 but only after the next power up.
Deep_sleep
{deep_sleep:x} where x is in seconds up to 4260 seconds. Any higher and the value will be truncated. The
instant you issue this command, the processor will turn off – and not wake up until the time specified
has passed. Nothing special about the wakeup – the unit will act as if it is being turned on as normal,
will connect to the WIFI and to MQTT - and proceed about its business.
In a typical application, you might let the unit turn on – wait until you get the first reply from new
instruction {readtemperature?} from the unit (for example) and then send via MQTT a message to turn
the unit off (and get a confirmation) for up to 71 minutes. Simple. Power savings will vary depending on
your boards and setup.
How does this work? Well, an internal real time clock is the only thing left on – and it has a timeout timer
in it - the value you set. When that times out – it simply forces GPIO16 to ground – and that of course
resets the processor. There is a flag we could read to determine how the board reset but as the same
operations need to be done anyway (log onto WIFI, sign on etc., I didn’t bother with any of that – keep it
simple.
Possible issues
One clone used 35-80ma (with obvious peaks well over 150ma when WIFI is operating) generally and
dropped to 14ma on deep sleep – thanks to hardware limitations of the clone which has a USB to serial
convertor and regulator on board – the USB convertor alone can use 10ma. If you want REALLY low
current i.e. possibly as low as 0.1ma according to some, you need boards which do not have these
features.
Given device ID X (a string with no spaces) - the MQTT “topic” will be X/TOESP
The MQTT message will always be surrounded by {} and a colon separates the command and the first
arguments – subsequent arguments use commas. This is all my choice – again not MQTT specific. The
format bears a vague resemblance to JSON.
Why X/TOESP ?? Well, I wanted an easy way for a device to accept messages just for itself – or for
EVERYONE. So let’s say we call a board “fred”.
The board “subscribes” to fred/toesp and toesp (you don’t have to worry about this – just give it an ID –
the software does the rest).
If say the Pi needs it to listen to messages meant for everyone – send to topic “toesp” – If you want to
send a message to that board only, send to topic “fred/toesp”.
To turn the relay on (on our original board, attached to GPIO0): {out0:1}
Simple – you can send a message complete with topic over WIFI using MQTT or just blast the topic
followed by CRLF through the serial at 115k baud.
In the list to follow, * indicates information is subsequently stored in FLASH so for example if you set up a
clock – you want it to start up after loss of power. Also if you set an output ON – general after a power
failure you want it to resume where it left off. Up to now this FLASH info saving has proven 100%
reliable.
Please note: As of Feb 2016 – references to OUT0 may go to output 0 or 16 – this is settable by
command. This is because we want to reserve GPIO0 not only for programming but also for WEB setup –
GPIO0 was only historically used for relays because of the ESP-01.
{query?}
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. Wemos and other similar ESP-
12-based boards work just fine.
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
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
Use: attrib
Query: yes
calibrate
Function:
To calibrate voltage readings on our original board
Use: calibrate:integer_value
Example: To be completed
Query: no
Query: no
Notes: Attach 60 serial LEDs to the port – make sure the time is set – will make beautiful serial clock
comment
Function:
Comment field for up to 120 characters (checked)
Query: 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}
Query: yes
Use: dawn:integer_dawn
Example: {dawn:400}
Query: no
Stored in Flash: no
Use: debug
Example: {debug}
Time: 13:56:55 11/08/2016
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
Query: yes
Stored in Flash: no
Use: desc
Query: yes
dusk
Function:
To pass dusk to the unit – number of minutes after midnight
Use: dusk:integer_dusk
Example: {dusk:1000}
Query: no
Stored in Flash: no
Return: Mqtt – Electrodragon status. Serial: String containing the status of Electrodragon variable
Query: yes
Notes: A quick bodge to allow use of the cheap Electrodragon WIFI boards with 2 relays – see the blog.
enable13
Function:
Enable or disable GPIO13 as a general purpose output – normally used as a status indicator
Query: no
Query: no
enable16
Function:
Allows general use of GPIO16 as an output
Query: yes
Use: ext:string_parameter
Example: {ext:”hello”}
Query: no
Stored in Flash: no
flashsize
Function:
Returns manufacturer info on Flash size
Use: flashsize
Example: {flashsize?}
Query: yes
Stored in Flash: no
Use: gettime
Example: {gettime?}
Return: Mqtt –none. Serial: returns string including time and date from NTP server
Query: yes
Stored in Flash: no
Notes: No daylight saving or local time incorporated – but it works. Not used for anything as boards get
time from ESPLOGIN node including time and dusk/dawn etc (subscribe to “logon” without the quotes).
gy30_init
Function:
Initialise I2c light sensor
Use: gy30_init
Example: {gy30_init:35}
Return: ok
Query: no
Stored in Flash: no
Use: gy30_read
Example: {gy30_read:35}
Return: Mqtt –light level. Serial: returns string including light level
Query: yes
Stored in Flash: no
heap
Function:
Return heap size in bytes
Use: heap
Example: {heap?}
Query: no
Stored in Flash: no
Example: {hitachi:39,”Hello”}
Query: no
Stored in Flash: no
hightemperature
Function:
To return temperature value * 10 with more precision than temperature
Use: hightemperature?
Example: {hightemperature?}
Query: yes
Stored in Flash: no
Example: {hsv:4,300,255,100,10}
Query: no
Stored in Flash: no
Notes: Maximum number of LEDs 300 typically, Delay is in millisecs and is a soft fade from previous
colour to current colour. HSV makes it easier to make a given colour or shade brighter or darker or to
increase or decrease saturation for pastel colours.
Use: humidity
Example: {humidity?}
Return: Mqtt – humidity. Serial: string including humidity (if using DHT11 or DHT22)
Query: yes
Stored in Flash: no
Use: i2c: integer_address // for reading a byte from a device – port expander for example
Return: Mqtt –value if single argument or arg2==1. Serial: string containing the value or OK
Query: yes
Stored in Flash: no
Notes: Assuming device PDF8574T with address lines high (7) – address is 39. So {i2c:39,0,1} will set the
first output bit high – the rest low. Set outputs HIGH before reading values – {i2c:39} will return the byte
value of inputs and state of outputs. Uses GPIO4 and 5. GPIO4 is SDA, GPIO5 is SCL. This is the opposite
of earlier software (v1).
For special cases - my Arduino code – set param 1 to 1 to indicate return byte expected.
So – {i2c:8, 0,1,12,1}
Address 8, no return expected, 1 means port output… 12 is the port number and 1 is the value
{i2c:8, 1,2,12}
Address, expect return, 2 means port input, port 12 – should return the value of port bit 12
Use: i2c_check
Example: {i2c_check}
Return: Mqtt – nothing. Serial: string containing list of connected I2c devices
Query: yes
Stored in Flash: no
id
Function:
Set or read the name of the board
Use: id
Query: yes
Use: in14
Example: {in14?}
Query: yes
Stored in Flash: no
in_2bounce
Function:
Integer sets timing for bounce
Example: An mqtt message will be generated when the threshold count is reached after a level change
on gpio2.
Query: no
Example: An mqtt message will be generated when the threshold count is reached after a level change
on gpio14.
Query: no
in14_count
Function:
Reads the number of state changes GPIO14 and kills the count
Use: in14_count
Example: {in14_count?}
Query: yes
Stored in Flash: no
Use: in2_count
Example: {in2_count?}
Query: yes
Stored in Flash: no
ina219_begin
Function:
Initialises an ina219 voltage/current monitoring chip i2c address 0x40 for 32v 2 amp operation
Use: ina219_begin
Example: {ina219_begin}
Return: ok
Query: no
Stored in Flash: no
Avoid calling this more than once per second as display update (expecially 64 pixel) takes time. Excessive
speed could crash ESP8266
Example: {ina219_getcurrent}
Return: voltage and current values as labelled JASON, optionally displays on OLED
Query: yes
Stored in Flash: no
Note: Chip initialised on first use of this or the command – NO need for separate $Sx
Use: ina219_getcurrent
Example: {ina219_getcurrent?}
Query: yes
Stored in Flash: no
ina219_getvoltage
Function:
Reads voltage from an ina219 voltage/current monitoring chip i2c address 0x40 for 32v 2 amp operation
Use: ina219_getvoltage
Example: {ina219_getvoltage?}
Query: yes
Stored in Flash: no
Use: invert:integer-mask
Query: yes
Use: invertset:integer-mask
Query: no
Use: invert:integer-mask
Query: no
ip
Function:
Query th IP address and gatway
Use: ip?
Example: {ip?}
Return: Text containing status i.e. dhcp or static, IP address and gateway IP address
Query: ONLY
Stored in Flash: No
Query: no
Stored in Flash: no
Notes: Maximum number of LEDs 300 typically, KELVIN values very approximate. Delay is in millisecs and
is a soft fade from previous colour temperature to current colour temperature – lower value is warmer.
Value of zero will fade the light out – suggest using a longer delay. So for example, to fade out 10 lights
on GPIO4, {kelvin:4,0,10,1000}
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}
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
{manual_ip:1,192,168,1,100,1}
Use:manual_ip:integer 1 or 0, integer first part of address, integer second part of address, integer third
part of address, integer end part of address, integer end part of router/dns address
If the first argument is zero, addressing is DHCP as per default, otherwise you are responsible for setting
the internal IP address of the unit and that of your router/dns
Query: no
See also: IP
Use:
mist:integer_gpio, integer_on_seconds, integer_off_seconds, integer_repeat_count
Example: {mist:0,5,60,100} - i.e. on GPIO, 100 sessions of 5 seconds misting followed by 60 seconds off
– do this 100 times
Query: no
Stored in Flash: no
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”}
Query: no
Use: mqtt_pass:string_parameter
Example: {mqtt_pass:”mypassword”}
Query: no
mqtt_port
Function:
Set the port of the MQTT broker usually 1883
Use: mqtt_port:integer_parameter
Example: {mqtt_port:1883}
Query: no
Use: mqtt_user:string_parameter
Example: {mqtt_user:”admin”}
Query: Yes
Return: Mqtt – if 3 parameter query returns JSON else nothing. Serial: JSON or OK
Stored in Flash: no
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 power-up)
SEROUT 10 - so for example {nano:9,10,”Test 1 2 3” – string will come out of NANO serial
port at 115200
SERVO 2-13 value - where value is 0-180 or 255 to kill that servo. See blog for more.
Support for Dallas DS1802b recently added see blog for Node-Red support…
No changes to this software needed or the Nano code for these various commands, it is all done
in Node-Red.
Use: ota_host:string_parameter
Example: {ota_host:”www.fred.net”}
Query: no
Use: ota_port:integer_parameter
Example: {ota_port:80}
Query: no
otaupdate
Function:
To update the code from an OTA server – i.e. any old webserver able to return a .bin file
Use: otaupdate
Return: Mqtt –none. Serial: some status info before the unit reboots
Query: no
Use: out0:integer_value
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
Use: out4:integer_value
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
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
Use: out12:integer_value
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
Use: out13:integer_value
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
Notes: Check enabled13 command first – generally this port is reserved for status indicator
Use: out14:integer_value
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
Use: out15:integer_value
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
Use: out16:integer_value
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
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. Also to enable GPIO16 – you should set the flag to allow it’s use as
an output – this is done by {enable16:1}
0 – off (high)
1 – on (low)
Or
Xport:integer_value
Return: ok
Query: yes
Notes: Assuming a PCF8574A port expander starting at address 39 and working down – to gpio4 and 5
for I2c. Note outputs are inverted as it is expected that these open-collector devices will be used with,
say, LEDS connected to VCC. Not stored in FLASH, on power-up the pins are inputs high (off). Do not use
with background I2c operations such as temperature sensors.
Use: pass:string_password
Example: {pass:”mypassword”}
Query: no
pass2
Function:
Set the second password string of the network
Use: pass2:string_password
Example: {pass2:”myotherpassword”}
Query: no
Example: {pca9685:64,3,4000}
Query: no
Stored in Flash: no
Notes: special command – pin 0 followed by frequency <1600 is setup. Otherwise pins OR’d together so
that 3 means 1 and 2, 0xffff is all
{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}
Use: polling_interval:integer_value
Query: no
Stored in Flash: no
port2out
Function:
Set to 1 to make GPIO2 an output
Use: port2out:integer_value
Example: {port2out:1}
Query: yes
Use: pwm:integer_red (0-99), integer_green (0-99), integer_blue (0,99), integer_timing(optional min 20)
Example: {pwm:99,40,20 }
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 I2C as discussed in the blog. Not aware of any other adverse
interactions.
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 }
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 I2C as discussed in the blog. Not aware of any other adverse
interactions.
Example: {rainbow:4,10,1000,20}
Query: no
Stored in Flash: no
readtemperature
Function:
Actually triggers a chip read – does not return anything – useful for some deep sleep setups –
Manually triggers the temperature call-back (temperature_cb) which may or may not also read humidity
and pressure
Use: readtemperature
Example: {readtemperature}
Query: N/A
Use: reboot_now
Example: {rebootnow}
Query: N/A
Use: reset
Example: {reset}
Query: no
reset_config
Function:
Wipes config to defaults and resets the board
WARNING: You cannot use this with other commands as it is going to reset the board to defaults (not
your defaults – the ones in the ROM).
Use: reset_config
Example: {reset_config}
Query: no
Use: rgb_ind:integer_value
Example: {rgb_ind:0}
Query: 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. See enable13.
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”}
Query: no
Stored in Flash: no
Use: rgb:integer_port,integer_red,integer_green,integer_blue,integer_optional_number_of_LEDS
(default 10), integer_optional_delay (default and minimum 2)
Example: {rgb:4,255,255,255,10}
Query: no
Stored in Flash: no
Notes: Maximum number of LEDs 300 typically, RGB values 0-255. Delay is in milli-secs and is a soft fade
from previous colour to current colour. See rgbperm if you want this state restoring on power-up.
Example: {rgbgo:4,10}
Query: no
Stored in Flash: no
Notes: Should not be used until the rgbset command has filled in values for your RGB LEDs. In this case
10 serial LEDs on GPIO4 will be programmed.
rgbinstant
Function:
Allow for instant setting of serial RGB lights.
Example: {rgbinstant:4,255,255,255}
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
Use: rgbstop
Example: {rgbstop}
Query: no
Stored in Flash: no
rgbset
Function:
Fills in an array of values for the rgbgo command
Example: {rgbset:0,10,255,0,0}
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.
{rgbstop}
{rgbadd:1,0,4,0,0,255,500}
{rgbstop}
{rgbstart:4,8}
{rgbadd:1,0,4,255,0,0,0}
{rgbadd:1,4,4,0,0,255,1000}
{rgbadd:1,0,4,0,0,255,0}
{rgbadd:1,4,4,255,0,255,1000}
{rgbadd:2,50}
{rgbadd:3} - End loop. Put stuff in the middle. You can have loops within loops.
You MUST put the {rgbstop} at the beginning as this clears out buffers UNLESS you are re-using an
existing buffer.
Animation will start with the first “rgbadd” instruction and run until power-off or an rgbstop or command
4 (see below).
For example {rgbadd: 1,0,200,255,255,255,2000} takes in total 10 bytes. You probably won’t run out of
animation storage – currently set to 600 bytes.
{rgbadd:4}
You will stop the existing sequence and return the pointer to the start without damaging anything – so
for a sequence you wish to use over and over, simply clear the LEDs to whatever state you want at the
end of the sequence and finish with command 4.
To start the sequence over at any time use the start command – you can even use a difference output
next time if you wish:
If you want to STORE this sequence in FLASH – {rgbstore:x} and to get it back {rgbrecall:x} where x is 0-3
– then use {rgbstart:port,number_of_leds} to play it back. Currently there are 4 non-volatile buffers.
Example: {rgbinstant:12,255,255,255,10}
Query: no
Notes: This command is identical to the rgb command other than the permanent storage of state which
survives power cycling. In the event of a power failure, any serial RGB setting is restored – because these
LEDs have a tendency on power up to enter a random state – not ideal for household lighting (“why
couldn’t you have bought ordinary lights like everyone else”) – with possibly just one LED on – it was felt
better to restore the previous state. If you no longer wish to use permanent RGB – set the port to above
16 or -1.
Use:romswitch
Query: no
scan
Function:
Only works in serial – scan for WIFI
Use:scan
Query: no
Stored in Flash: no
Example: {set_serial:0}
Parameter:
2 - gpio4 and gpio5 become I/O for the Nextion serial display at 57600 baud. The Nextion itself
must have been set to this speed externally using another source.
3 - gpio4 and gpio5 become I/O for the Nextion serial display at 38400 baud. The Nextion itself
must have been set to this speed externally using another source.
4 - gpio4 and gpio5 become I/O for the Nextion serial display at 19200 baud. The Nextion itself
must have been set to this speed externally using another source.
5 - gpio4 and gpio5 become I/O for the Nextion serial display at 9600 baud. The Nextion itself
must have been set to this speed externally using another source.
Once set, the board will immediately re-boot to set the ports up correctly.
Query: yes
Example: {si1132_visible}
Query: yes
Stored in Flash: no
Notes: Needs reboot if board unplugged then replugged as init done on first use
Use: sonoff:integer_value
Example: {sonoff:0}
Query: no
ssid
Function:
Set the ssid string of the network
Use:ssid
Example: {ssid:”kitchen_wifi”}
Query: no
Use:ssid2
Example: {ssid2:”ceiling_wifi”}
Query: no
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}
Query: yes
Use: temperature?
Example: {temperature?}
Query: yes
Stored in Flash: no
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}
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
5=SHT30 (also processes higher temp resolution – see hightemperature
Query: no
See also: temperature port. BME280 uses GPIO4 and 5 for I2C. Depending on the chip used, see also
{temperature?}, {pressure?} and {humidity?}
Use: temperature_port:integer_parameter
Example: {temperature_port:2}
Query: yes
Notes: Valid values are 0, 2 or 14. If set to 0 no temperature sensing takes place and hence no auto-
MQTT reporting. If 2 or 14 are set as temperature port- that port cannot be used for input sensing at the
same time.
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}
Query: no
Stored in Flash: no
Example: {timeout_set:100,10,1,4,0}
In this example –times out in 100 seconds – stays “on” for 10 seconds, turns “off” and repeats, in
this case does NOT invert the output… all this on GPIO4 (here)
Query: no
Stored in Flash: yes including initial state of pin – set timeout to 0 to turn this off (and reboot)
timeout_clear
Function:
Reset the monostable – so something would call this regularly to stop the monostable triggering
Use: timeout_clear
Example: {timeout_clear}
Query: no
Stored in Flash: no
Use: to_nextion:string_value
Sends a string to the software serial port suffixed by 0xff 0xff 0xff for the Nextion displays.
You must use the command to set serial2 to value 2 in order to use this.
If you wish buttons on the Nextion to send commands – they must use a tilde as a separator and
use the GET command to ensure the output from the Nextion ends with FF FF FF.
So – for a nextion button…. talking to device fred (might be this one – might be another one on
the network)
get “fred/toesp~{out0:1}”
The parser handles \r \n \t and \xZZ where zz are 2 hex digits 0-9 or A-F or a-f
Query: no
Stored in Flash: no
Use: to_serial2:string_value
You must use the command to set serial2 to value 2 in order to use this.
The parser handles \r \n \t and \xZZ where zz are 2 hex digits 0-9 or A-F or a-f
Query: no
Stored in Flash: no
uptime
Function:
returns a string in h:mm:ss since power up – 32 bits so can handle long period. Reset on power up or
system reset.
Use: uptime?
Example: {uptime?}
Query: yes
Stored in Flash: no
Use: ver
Example: {ver?}
Return: Mqtt version number value. Serial: string containing the version number
Query: yes
Stored in Flash: no
voltage
Function:
Returns the value of the ADC – converted to voltage assuming use of our board or similar with dividers
Use: voltage
Example: {voltage?}
Return: Mqtt –voltage value. Serial: string containing the voltage value
Query: yes
Stored in Flash: no
Example: {warning:255,0,0}
Query: no
web_setup
Function:
Causes the unit to reset into web setup mode as if you’d pressed the button
Use: web_setup
Example: {web_setup}
Query: no
Example: {wifi_button:2}
Query: no
Notes: The DEFAULT is now GPIO0 as the WIFI button. If set to 2, GPIO0 is used for general relay
operations and output 16 is not enabled (legacy). If set to 0, GPIO0 is an input and is used for both
programming (ground BEFORE power-up) and as a WIFI button (ground AFTER power-up) and GPIO16
acts as the general relay output.
When the board is powered up, if the WIFI programming button is held low, you should see a sequence
of + signs on the serial monitor (assuming you have a serial monitor attached at 115,200 baud).
xport
Function:
Sets up ports if using i2c and support for both the PCF8574 and PCF8574A giving up to 128 I/O lines with
8 of each chip.
Example: {xport:2,2}
Query: yes
Stored in Flash: no
I.e. if you blow something up - it's your problem. On the other hand if you improve the code I’d like to
know about it. Please subscribe to https://tech.scargill.net
If you blow the code – and on power-up you see via the serial monitor, +++++ the board sees the web
programming button as being held LOW… if this is deliberate – that’s fine – if not – check the WIFI-
BUTTON command.
Twitter:
https://twitter.com/scargill
Facebook:
https://www.facebook.com/esp8266wifi
https://www.facebook.com/iotstuff/
Google+:
https://plus.google.com/+PeterScargill
General:
http://www.scargill.net
http://www.bedrock.es
http://www.hollyberry-cottage.co.uk
ICON SET 1
0 1 2 3 4 5 6 7 8 9
0 1 2 3 4 5 6 7 8 9
A B C D E F G H J I K L M
A B C D E F G H J I K L M
N O P Q R S T U V W X Y Z
N O P Q R S T U V W X Y Z
a b c d e f g h i j k l m
a b c d e f g h i j k l m
n o p q r s t u v w x y z
n o p q r s t u v w x y z