Sunday, December 30, 2018

Build your own IoT/MQTT node for less than $2

In this post, I will be explaining ESP-12F module usage with minimal set of components.
ESP-12F as a stand-alone module is of no use unless mounted on a base board like wemos-d1-mini.

This blog explains how to use ESP-12F module without the need of a base board but with minimal set of components.

Items needed(total cost of all the components is based on the prices from aliexpress)
1)1x ESP-12F module(pre programmed with tasmota firmware)
2)1x 10k SMD resistor
3)1x 10K thru-hole resistor.
4)2x 4001 SMD diode
5)1x USB male connector(PCB mount - smd).



Schematics:















Board Preperation Steps:
1)Ensure that ESP-12F module is programmed with tasmota firmware(here you can find the details on ESP-12F module programming)

2)mount 10k smd resistor between GND and IO15 pad of the ESP-12F module.













3)mount 10k thru-hole resistor between VCC and EN pad of the ESP-12F module.

4)Stick a piece of insulation tape on the right side of the ESP-12F module so that USB connector doesnt short any pads.
5)Place USB connector as shown below and smd pins of the USB connector shall be placed over the insulation tape.
6)on the backside of the board, fix the USB connector to the ESP-12F using hot-glue(dont apply hot glue on the smd pin side of the USB connector yet, this will be done at later stage)
7)solder two SMD diodes in series between Plus(+) line of the USB connector and VCC pad of the ESP-12F module.
8) Connect Minus(-) line of USB connecotr to the GND pad of ESP-12F module
9)Apply Hot glue on both the sides of the USB connector and ESP-12F for stability.



10)Power the board with 5v USB charger and look for open wifi ssid "sonoff-NNNN"
11)Follow the standard tasmota generic module configuration.

ESP-12F(ESP8266MOD) module programming


ESP 8266 based IoT modules can be purchased from aliexpress for as low as 1.3Euros. These cheap wifi modules can be handy for many home automation DIY projects(especially when used with opensource firmware like tasmota).

In this post, you will find an easy way of programming ESP modules by converting wemos-D1-mini development board as a pogo-pin based docking station.

Items needed:
1)Wemos-D1-Mini board
2)8 pogo pins
3)ESP-12F module
4)USB-to-micro-USB cable
5)clip for holding the ESP module on pogo-pin dock.




Preperation:
1)de-solder existing ESP module from the wemos-D1-mini board(this is the most difficult part, you need good soldering skills).

2)carefully solder 8 pogo pins on the exposed ESP pads on the wemos-D1-Mini(TXD0,RXD0,IO0,IO15,GND,VCC,EN,RST)


3)place a fresh ESP module on the newly prepared wemos-D1-dock



4) On your Linux-Host-PC, run following commands to prepare the programming setup.
  • cd ~
  • git clone https://github.com/espressif/esptool
  • cd esptool
  • wget http://thehackbox.org/tasmota/release/sonoff.bin
5) Connect  USB-to-MicroUSB cable between Linux-Host-PC and wemod-D1-dock and run to the following command on Linux-Host-PC for erasing ESP-12F flash
  • ./esptool.py --port /dev/ttyUSB0 erase_flash 
6) After erase operation, remove and connect the USB cable between host pc and wemos-d1-dock, and run the following command to program tasmota firmware
  • ./esptool.py --port /dev/ttyUSB0 write_flash -fs 1MB -fm dout 0x0 sonoff.bin
7) Congratulations! your ESP-12F module is ready for use, check my next blog about using ESP-12F as a standalone board for home automation projects.



Thursday, January 11, 2018

Remote accessing the Raspberry pi over internet

In this guide, an xmpp based client-daemon is used as a chat-bot, this chat-bot is written in C++ and it is based on gloox-xmpp-client library. Xmpp provides an easy way of communication between two clients which are typically behind a firewall. A jabber server with public-ip over internet helps to achieve this secure communication between two xmpp clients.
Following steps explain how to compile and run the xmpp-client-daemon(chat-bot) on raspberry pi. Here is a diagram showing typical setup of remote communication between raspi and a smart phone.

How to prepare raspberry-pi to act as a chat-bot?
(following steps are tested on a raspi running 2017-11-29-raspbian-stretch-lite.img)
  1.  Login to the linux-shell-terminal of your raspi using directly connected keyboard or ssh.
  2.  sudo apt-get update
  3. sudo apt-get install cmake git libjson-c-dev libgloox-dev openssl
  4. mkdir /home/pi/xmproxy
  5. cd /home/pi/xmproxy
  6. git clone https://github.com/hackboxguy/brbox
  7. cd /home/pi/xmproxy/brbox/sources
  8. cmake -H. -BOutput -DCMAKE_INSTALL_PREFIX=/home/pi/xmproxy/buildir -DAUTO_SVN_VERSION=OFF
  9. cmake --build Output -- install (suffix -j5 incase of quad-core-raspi for faster build)
  10. cd /home/pi/xmproxy/buildir
  11. echo "user: my-raspi-usrname@gmail.com" >/home/pi/xmproxy/buildir/xmpp-login.txt;echo "pw: super-secret-pw" >>/home/pi/xmproxy/buildir/xmpp-login.txt
  12. export LD_LIBRARY_PATH=/home/pi/xmproxy/buildir/lib
  13. /home/pi/xmproxy/buildir/bin/xmproxysrv --loginfile=/home/pi/xmproxy/buildir/xmpp-login.txt

Check on your android phone's hangout if "my-raspi-usrname" is online, if so, then send "help" message and the reply would show the list of available commands.

enjoy chatting with your raspi-chat-bot!!

Note-1: For proper operation of xmpp with google account, ensure that your Raspi's account has this allow-less-secur-apps setting enabled. 

Note-2: Two xmpp accounts need not be on google, any two jabber accounts would work. Here is an explanation on preparing the jabber accounts.

Note-3: steps explained above would work on any debian based linux distro machine.
source code is open, suggestions and contributions are welcome.

Sunday, January 07, 2018

Overwrite stock A5-V11 Chinese firmware with openwrt-based a5v11-xmpp-image

This is a step-by-step guide for overwriting stock OEM chinese-image of a5-v11 with openwrt based a5v11-xmpp image.

what is a5-v11?: This is a low cost(5Euro) wifi router capable of running openwrt linux.

what is a5v11-xmpp-image?: this is a customized openwrt image which includes a c++ based xmpp-client-daemon for IoT application - look here for details.

Setup: As shown in the picture below, item-1,2 and 3 are needed and item-4,5 and 6 are optional - they are needed only when you are unable to figure out the ip address of a5-v11 using its hostname. There are otherways to know the ip of your a5-v11, ex: looking at the dhcp client list on your home-router's webpage. For any reason if you are unable to figure out the ip, you can use a usb-to-i2c converter and ssd-1306-i2c-display. Upon linux boot, a5-v11 prints its ip-addr on this i2c display.



Step-1: Download a5v11-xmpp-factory.uimg to your pc's hard-disk.

Step-2: Connect a cat-5 or cat-6 cable between a5v11 and your PC.

Step-3: Power ON a5-v11 with 5VDC and wait for ~1minute till your pc gets the ip from a5-v11(your pc shall get an ip in the range of 192.168.100.xxx)

Step-4: Enter "192.168.100.1" in your browser's URL and you shall see the following page.
If you dont see this page - stop here!!!!, your a5-v11 might have a different firmware. I have a separate blog explaining the step-by-step guide for qualcomm-based a5v-11 firmware.

Step-5: Click on language dropdown list to switch to english
Step-6: Click on Admin->Firmware-Upgrade->Choose File xmpp-a5v11-factory.uimg(which was downloaded in step-1).  And then click "upgrade" button.

Step-7: You will have to confirm by clicking "OK"
Step-8: A second confirmation is needed, click "OK"
Step-9: Firmware upgrade starts, you will see the following pages

Step-10: Wait for about 40seconds, remove the power to a5-v11, also remove cat-5/cat-6 cable which was connected between a5-v11 and PC.

 Step-11: Using cat-5/cat-6 network cable, connect a5-v11 to your home-router and ensure that your PC is also connected on your home-router's network.

Step-12: Power ON a5-v11 and wait till the red-LEDon a5-v11 stops blinking.

Step-13: Using ssh or putty.exe, login to a5-v11's shell terminal using hostname "my-a5v11" - login username/password is root/brb0x. For any reason, if you are unable to figure out the ip of a5-v11, as discussed earlier, you can connect an i2c display on usb port of this router,  and reboot to see its ip as shown here in this picture.

Step-14: after login to ssh terminal of a5-v11, change the default password to your own using "passwd" command

Step-15: Set the xmpp(jabber) server's login credentials with this command(replace example user and password 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: Reboot a5-v11, you shall see that your device coming online on your smart phone's xabber chat client.

Next Steps: Follow my other blog to see how you can use a5v11-xmpp-chat-bot as an IoT gateway for home automation.

Saturday, January 06, 2018

Low cost - Uninterruptible power supply for broadband wifi router



There are places and situations where people are struggling with frequent power outages causing interruption in the internet access, this leads to dropped calls, dropped download sessions etc.

Typically, these power outages are of short duration as backup generator takes over the load within few minutes. A short disconnection of power causes reboot of broadband wifi routers and re-connection of internet for all the devices on the network.

To tackle this problem of short power outage, i found this interesting cable on aliexpress sold for 1Euro including shipping.
This 5v to 12v booster cable along with battery bank makes it a perfect low cost uninterruptible power supply for your broadband wifi router. Please note:  power output capacity of this bootster cable is in the range of 8Watts which should be enough for a standard broadband wifi router. (if you happen to have a router with higher than 8watt consumption, then look for highter capacity booster cable).

The black plastic housing towards the usb end contains a booster pcb(MT3068 converter) as shown here



As shown in the following picture, you can connect 5v Dc adapter to the battery bank's charging port and 5v output of batterybank powers the broadband wifi router through this booster cable.

Backup time of such a solution depends on capacity of the battery bank. In your situation if the power outage is of short duration, then you can manage with lower capacity battery bank, else you can go for a higher capacity one.