I’m often asked about setting up MQTT, Node-Red etc. on the likes of Raspberry Pi, NanoPi or similar, with a view to controlling ESP8266 devices.
Novice readers start here
Usually it is difficult for me to see this from a beginner perspective, but having spent 2 months in hospital thanks to an untimely stroke from which I’m still recovering, 4 months after the event, I recently found myself doing new installs without the benefit of doing this stuff every day. I am just SO glad I blog everything.
Over time and with lots of help, I’ve developed an install script to put all the tools I need onto a Raspberry Pi or similar board. This should be used on a virgin board with nothing but the full operating system. We’ve never tested and don’t intend to test NOOBS. Instead, the script has been tested on Raspberry Pi 2 and 3 (and 3B+) with Raspbian including the STRETCH variety.. and also on various (detailed in the code) boards such as Orange Pi Zero and others, Roseapple Pi, various FriendlyArm boards and more, using DIETPI, Ubuntu Core, Armbian and Debian.
The script includes full setup for Mosquito MQTT, Nod-Red and lots of nodes including my own, SQLITE and many great utilities. Please check the script to see what it has been tested on, if a board or operating system is not mentioned, it has NOT been tested. Please don’t try “pick and mix” – use the script as indicated.
All work at the PC end, i.e. setting up, is generally done on a Windows PC, not mandatory but I sit at a PC, not a MAC or Linux box so that’s my perspective.
Here is the link for “the script”. https://bitbucket.org/snippets/scargill/ekon6o/the-script
The main blog entry https://tech.scargill.net/the-script/ has information to wget the script straight onto the likes of a PI as root user.
In the comments inside the script, you will find all information on systems tested.
Typically “the script will be run on a board with nothing but a clean operating system on it. It helps if remote root access and SCP is enabled. On a Raspberry Pi, user “pi” will usually exist, on other boards, the script will set up this user and the needed group access. You might also want to ensure that I2c is enabled in the board setup if you wish to use this.
You need nothing else but a copy of the script as this will install software as needed from online resources.
For ESP8266, you can install code from the binaries I provide or compile the source. https://bitbucket.org/scargill/esp-mqtt-dev2 – this now even has its own brand identity ESP-GO
No, I don’t use the Arduino model, I just code in C with the Espressif SDK version 2.0 (later versions don’t leave enough RAM, earlier versions work but have minor bugs so grab 2.0 – better, just use the binaries). RAM used specifically for code as against data, soon runs short with ambitious coding on the ESP8266 no matter what you do – don’t confuse this with heap RAM, shortage of which could affect reliability.
I use ESP8266Flasher.exe from NODEMCU to blow ROMS. For flashing generally use QIO mode as set up in the but the WEMOS boards seem to want DIO mode, all of which is down to the kind of FLASH used on the board.
At 00000, flash rboot.bin from my firmware folder, at 0x2000 (and assuming an ESP12 or similar with 4MB Flash – I no longer support the old ESP01 with only 512KB Flash) you need my rom.bin file from the same place and lastly at 3fc00 you should flash esp_init_data_default.bin from the ESPRESSIF site. It is also in my ROMS public folder with the other ROMS. http://roms.scargill.net
Occasionally on new boards I find it useful to erase the entire flash before doing the above, using esptool or similar. I use the .exe version of esptool out of preference.
In the above photo, two separate projects on one board, I’ve used a LED on GPIO13 (to use the Espressif naming) which flashes automatically and another on GPIO12 which turns on and off depending on the state of a Node Red BigTimer (I usually use my own Node-Red-Contrib-Bigtimer for this, with various devices able to trigger manual timer overide via MQTT messages. Also, in each case above, GPIO4 and 5 are I2c data and clock to the displays, with pull up resistors to 3v3.
As for talking to the ESP8266 from the Pi, I exclusively use Node=Red and mostly MQTT, all of which you will find detailed in the WORD document that is stored in the BitBucket repository along with the source. the code supports a wide range of LCD and OLED displays as well as 2 line LCDs, a range of temperature, humidity, pressure and other sensors (some simple one-wire, some I2c on GPIO4 and 5) including DHT11 and 22, Dallas temperature sensors, SHT30 light sensors, BME280, BMC180 and many more. More device support than I’ve seen elsewhere all at once.
There are several large blog entries in here covering all of this.
Options out there
Why this and not other ways? Well, all of the above has been widely tested over time in different countries and proven to be rock-solid. I use this ESP8266 code except for the odd occasion I’m using SONOFF boards. SO Much work has gone into the Tasmota software it seems daft to re-invent the wheel if Sonoffs are involved and the software supports Alexa.
You will find lots of discussion in here and also lots of info in my YouTube channel and on my Facebook pages ESP8266WIFI and IOTSTUFF.
See “Home Control 2017” (I may rename that to 2018 or later in time), “The Script”, “Nano I2c Peripheral” and “Big Timer” for starters.
When I started to see limits to I/O on the ESP8266, I added what I call my NANO i2c peripheral as an option to the project to give loads of extra I/O, PWM (now 6 channels i.e. 2 RGB channels) and analog inputs via a dirt cheap Arduino NANO type clone. One variation of this, not fully tested yet, includes infra-red. The code for these boards is available below and they will (via i2c) provide lots of extra I/O to the ESP8266 along with serial, PWM, analog inputs and servo control.
In the example photo above, the ESP12-based board drives the Nano via I2c, with two pull-ups to 3v3. GPIO 4 and 5 on the ESP8266, A4 and A5 on the Nano. GPIO12 on the ESP8266 can be turned on and off by Node-Red and D6 on the Nano similarly, or depending on the instruction in Node-Red (via MQTT) turned up or down. Note the latter only works with pins able to do PWM. All I/O pins on the Nano are available to be used in the software (except 0,1 and A4,5),
At £1.50 from AliExpress there simply is no more cost effective way to add I/O to the ESP8266 if you need it. As for the ESP8266 itself, I find the ESP12-based Wemos D1 Mini (again usually from AliExpress) to be unbeatable unless you need a board with relays etc. already fitted.The two together come in way cheaper than an ESP32 for example while (depending on your needs) offering more. If you are convinced you need an ESP32 as the ESP8266 isn’t fast enough for you, try double clock speed (160Mhz). I’ve an instruction for that.
This home control project is on-going, I started messing with control boards for the home, last century, way back before WIFI was so universal and continue to enjoy new innovations as they appear. The ESP32 may eventually compete on cost, right now there is almost nothing I can do with the ESP32 that I cannot do equally well with the ESP8266. No doubt about it though, more program space RAM (not FLASH, got loads left) would be good.