Sunday, December 30, 2018

Build a $2 IoT/MQTT Node with a Bare ESP-12F

How to use a bare ESP-12F module as a standalone IoT/MQTT node — powered directly from a USB charger with just a handful of passive components, no base board required. Total cost: under $2.

Completed ESP-12F standalone MQTT node

Finished board — ESP-12F module with USB connector, ready to plug into any 5V charger.

Items needed

Prices based on AliExpress at the time of writing:

  • 1x ESP-12F module (pre-programmed with Tasmota firmware)
  • 1x 10k SMD resistor
  • 1x 10k through-hole resistor
  • 2x 4001 SMD diode
  • 1x USB male connector (PCB mount, SMD)

Schematic

ESP-12F standalone board schematic

Wiring diagram — USB 5V stepped down through two diodes to ~3.6V for the ESP-12F.

Board preparation

Step 1 — Ensure the ESP-12F module is programmed with Tasmota firmware. See the ESP-12F programming post for details.

Step 2 — Mount a 10k SMD resistor between the GND and IO15 pads of the ESP-12F module.

10k SMD resistor between GND and IO15

10k SMD resistor soldered between GND and IO15 pads.

Step 3 — Mount a 10k through-hole resistor between the VCC and EN pads of the ESP-12F module.

10k through-hole resistor between VCC and EN

10k through-hole resistor connecting VCC to EN (chip enable).

Another view of the VCC-EN resistor

Another angle showing the VCC–EN pull-up resistor.

Step 4 — Stick a piece of insulation tape on the right side of the ESP-12F module so the USB connector doesn't short any pads.

Insulation tape applied to ESP-12F

Insulation tape prevents shorts between the USB connector and ESP pads.

Step 5 — Place the USB connector as shown below. The SMD pins of the USB connector should sit over the insulation tape.

USB connector placed on ESP-12F

USB connector positioned over the insulation tape.

Step 6 — On the back side, fix the USB connector to the ESP-12F using hot glue. Don't apply hot glue on the SMD pin side yet — that comes later.

Hot glue fixing USB connector on back side

Hot glue secures the USB connector on the back side.

Step 7 — Solder two SMD diodes in series between the + line of the USB connector and the VCC pad of the ESP-12F module.

Two SMD diodes in series for voltage drop

Two 4001 diodes in series drop 5V USB to ~3.6V for the ESP-12F.

Step 8 — Connect the line of the USB connector to the GND pad of the ESP-12F module.

GND wire from USB to ESP-12F

USB ground connected to the ESP-12F GND pad.

Step 9 — Apply hot glue on both sides of the USB connector and ESP-12F for stability.

Hot glue applied for stability

Hot glue on both sides for mechanical strength.

Completed board from another angle

Completed board — ready for testing.

Testing

Step 10 — Power the board with a 5V USB charger and look for an open Wi-Fi SSID named sonoff-NNNN.

Step 11 — Connect to the SSID and follow the standard Tasmota generic module configuration.

Your $2 IoT/MQTT node is ready. Plug it into any USB charger, configure Tasmota to connect to your MQTT broker, and start automating.

Pogo-Pin Programming Dock for ESP-12F Modules

How to convert a Wemos D1 Mini into a pogo-pin programming dock for flashing Tasmota (or any firmware) onto bare ESP-12F modules — no breadboard wiring needed.

Pogo-pin programming dock for ESP-12F

Completed pogo-pin dock — a modified Wemos D1 Mini ready to flash ESP-12F modules.

Why?

ESP8266-based IoT modules can be purchased from AliExpress for as low as 1.3 EUR. These cheap Wi-Fi modules are handy for many home automation DIY projects, especially when used with open-source firmware like Tasmota. But programming bare ESP-12F modules requires connecting 8 pins — tedious on a breadboard and error-prone with dupont wires.

A pogo-pin dock lets you drop in a module, clip it down, and flash — repeatable and reliable.

Items needed

Items needed for pogo-pin dock

Everything you need to build the programming dock.

  • Wemos D1 Mini board
  • 8 pogo pins
  • ESP-12F module
  • USB-to-Micro-USB cable
  • Clip for holding the ESP module on the pogo-pin dock

Preparation

Step 1 — De-solder the existing ESP module from the Wemos D1 Mini board. This is the most difficult part — you need good soldering skills.

Wemos D1 Mini with ESP module removed

Wemos D1 Mini after removing the original ESP module.

Step 2 — Carefully solder 8 pogo pins onto the exposed ESP pads on the Wemos D1 Mini: TXD0, RXD0, IO0, IO15, GND, VCC, EN, RST.

Pogo pins soldered onto Wemos D1 Mini

Pogo pins soldered onto the exposed ESP pads.

Step 3 — Place a fresh ESP-12F module on the newly prepared dock and secure it with a clip.

ESP-12F module placed on the pogo-pin dock

ESP-12F seated on the pogo-pin dock, ready for flashing.

Pogo-pin dock with clip holding ESP-12F

Clip holds the ESP-12F firmly against the pogo pins during programming.

Flashing firmware

Step 4 — On your Linux host PC, clone esptool and download the Tasmota firmware:

cd ~
git clone https://github.com/espressif/esptool
cd esptool
wget http://thehackbox.org/tasmota/release/sonoff.bin

Step 5 — Connect the USB cable between your host PC and the Wemos D1 dock. Erase the ESP-12F flash:

./esptool.py --port /dev/ttyUSB0 erase_flash

Step 6 — Disconnect and reconnect the USB cable, then flash the Tasmota firmware:

./esptool.py --port /dev/ttyUSB0 write_flash -fs 1MB -fm dout 0x0 sonoff.bin

Your ESP-12F module is now flashed and ready for use. Check the next post about using an ESP-12F as a standalone board for home automation projects.

Close-up of pogo pins contacting ESP-12F pads

Close-up showing the pogo pins making contact with the ESP-12F module pads.

Another angle of the pogo-pin dock

Another angle of the completed pogo-pin programming dock.

Thursday, January 11, 2018

Access Your Raspberry Pi Remotely via XMPP Chat

How to remote-access a Raspberry Pi over the internet using an XMPP-based chat-bot — no port forwarding or dynamic DNS required. The chat-bot is written in C++ using the gloox XMPP client library, and communicates through a public Jabber server.

Setup diagram — Raspberry Pi chat-bot communicating with smartphone via XMPP

Typical setup — Raspberry Pi behind a firewall communicates with a smartphone via a public XMPP/Jabber server.

Building the chat-bot on Raspberry Pi

Tested on Raspbian Stretch Lite (2017-11-29). These steps work on any Debian-based Linux distro.

Step 1 — Log in to the Raspberry Pi shell (keyboard or SSH) and install dependencies:

sudo apt-get update
sudo apt-get install cmake git libjson-c-dev libgloox-dev openssl

Step 2 — Clone and build:

mkdir /home/pi/xmproxy
cd /home/pi/xmproxy
git clone https://github.com/hackboxguy/brbox
cd /home/pi/xmproxy/brbox/sources
cmake -H. -BOutput -DCMAKE_INSTALL_PREFIX=/home/pi/xmproxy/buildir -DAUTO_SVN_VERSION=OFF
cmake --build Output -- install    # add -j5 on quad-core Pi for faster build

Step 3 — Configure XMPP credentials and start the chat-bot:

cd /home/pi/xmproxy/buildir
echo "user: my-raspi-username@gmail.com" > xmpp-login.txt
echo "pw: super-secret-pw" >> xmpp-login.txt
export LD_LIBRARY_PATH=/home/pi/xmproxy/buildir/lib
/home/pi/xmproxy/buildir/bin/xmproxysrv --loginfile=/home/pi/xmproxy/buildir/xmpp-login.txt

Testing

Check on your Android phone's Hangouts (or any XMPP client) if my-raspi-username is online. Send help and the chat-bot will reply with the list of available commands.

Notes

For Google accounts, ensure Allow less secure apps is enabled on the Raspberry Pi's account.

The two XMPP accounts don't need to be on Google — any two Jabber accounts will work. See this guide for preparing Jabber accounts.

These steps work on any Debian-based Linux distro, not just Raspbian.

SOURCE CODE

github.com/hackboxguy/brbox — XMPP chat-bot sources and build instructions

Sunday, January 07, 2018

Flash XMPP ChatBot Firmware onto A5-V11 Router

Step-by-step guide to replace the stock Chinese firmware on an A5-V11 pocket router (~5 EUR) with an OpenWrt-based image that includes an XMPP chat-bot daemon for IoT applications.

What is A5-V11?

A low-cost (~5 EUR) Wi-Fi router capable of running OpenWrt Linux.

What is a5v11-xmpp-image?

A customized OpenWrt image that includes a C++ based XMPP client daemon for IoT applications. See this blog post for details on using it as a smart-home gateway.

Setup

As shown below, items 1–3 are required. Items 4–6 (USB-to-I2C converter and SSD1306 display) are optional — they help display the router's IP address on boot if you can't find it via your home router's DHCP client list.

A5-V11 setup: router, Ethernet cable, PC, and optional I2C display

Setup overview: A5-V11 router, Ethernet cable, PC (required), plus optional USB-to-I2C converter and SSD1306 display for IP readout.

Flashing steps

Step 1Download a5v11-xmpp-factory.uimg to your PC.

Step 2 — Connect an Ethernet cable between the A5-V11 and your PC.

Step 3 — Power on the A5-V11 with 5 V DC and wait ~1 minute until your PC gets an IP in the 192.168.100.x range.

Step 4 — Open 192.168.100.1 in your browser. You should see the Chinese OEM firmware page:

A5-V11 Chinese OEM firmware web UI

Chinese OEM firmware web interface — confirm your router shows this page.

Stop here if your page looks different. You may have the Qualcomm firmware variant — follow this other guide instead.

Step 5 — Click the language dropdown to switch to English:

Switching language to English

Switch the web UI language to English.

Step 6 — Navigate to Admin → Firmware Upgrade → Choose File, select a5v11-xmpp-factory.uimg (downloaded in Step 1), then click "Upgrade".

Step 7 — Confirm by clicking "OK":

First firmware upgrade confirmation

First confirmation dialog.

Step 8 — A second confirmation is needed — click "OK" again:

Second firmware upgrade confirmation

Second confirmation dialog.

Step 9 — The firmware upgrade begins:

Firmware upgrade in progress

Firmware flashing in progress.

Firmware upgrade completing

Firmware flash completing.

Step 10 — Wait about 40 seconds, then remove power and disconnect the Ethernet cable from the PC.

Step 11 — Connect the A5-V11 to your home router via Ethernet. Make sure your PC is also on the same network.

Step 12 — Power on the A5-V11 and wait until the red LED stops blinking.

Post-flash configuration

Step 13 — SSH into the router using hostname my-a5v11 with credentials root / brb0x.

If you can't find the router's IP, connect an I2C display to the USB port — the router prints its IP on boot:

A5-V11 displaying IP address on I2C OLED display

Optional: SSD1306 I2C display showing the router's IP address after boot.

Step 14 — Change the default password:

passwd

Step 15 — Set your XMPP (Jabber) login credentials (replace with your own):

echo "user: test-slave-account@xabber.de" >/etc/xmproxy/xmpp-login.txt
echo "pw: chatbotpw" >>/etc/xmproxy/xmpp-login.txt
reboot

Step 16 — After reboot, your device should appear online in your smartphone's Xabber chat client.

Next steps: Follow this blog post to use the A5-V11 XMPP chat-bot as an IoT gateway for home automation.

Saturday, January 06, 2018

DIY Router UPS for Under $2 with a Battery Bank

A low-cost uninterruptible power supply for your broadband Wi-Fi router using a USB battery bank and a 5 V to 12 V DC boost cable (~1 EUR from AliExpress). Keeps your router running through short power outages so you don't lose calls or downloads while the backup generator kicks in.

The boost cable

A USB 5 V to DC 12 V step-up cable with a 2.1 × 5.5 mm barrel connector — sold for about 1 EUR including shipping.

USB 5V to 12V DC boost cable

USB 5 V to 12 V boost cable — the black housing contains an MT3068 converter PCB.

MT3068 boost converter PCB inside the cable housing

Inside the housing — MT3068-based boost converter.

This cable provides up to ~8 W output, which is enough for a standard broadband router. If your router draws more than 8 W, look for a higher-capacity boost cable.

Setup

Connect a 5 V DC adapter to the battery bank's charging port. The battery bank's USB output feeds the boost cable, which powers the router at 12 V.

Complete UPS setup — adapter, battery bank, boost cable, and router

Complete setup — 5 V adapter charges the battery bank, which powers the router through the boost cable.

Backup duration depends on the battery bank capacity. A smaller battery handles short outages (a few minutes while a generator starts); a larger one extends runtime for longer outages.