Thursday, January 03, 2019

Wifi based DIY 5V switcher for led-lights


There are so called "USB Fairy Lights" or "USB String Lights" can be purchased from china for less than 3$ for a 10m/100Led set.



These are 5V USB powered and weather-proof(except the USB connector part). I was curious to know more about these lights, and had a detailed look, this is what i found,
















and a closup of the LED,















5V powered 100LED circuit was consuming around ~1.8Watts(though 5.1Ohm series resistor was really hot) and the brightness of the LED's were not bad, especially difference between first led and last led brightness didnt bother me it was hardly noticeable when seen from distance. So I decided to use them as a christmas decoration for my garden.

I wanted to use them with battery-bank as there was no power-outlet readily available(for the safety of my children, i would avoid any 230v circuit in my garden especially in wet weather).
Also I wanted them to be switchable remotely to avoid going out in the freezing cold. Hence this is what i came up with.. an "ESP-12F based USB-5V switcher"




























































Although It works as intended, but with tasmota firmware, due to missing deep-sleep feature, i need frequent battery charging(every few days). Larger battery bank and ESP-8266 deepsleep would make this setup work for weeks before battery needs recharge.

Incase if you want to build this 5v switcher, here are some details,


Note: Before starting the assembly, ensure that the ESP-12F module is pre-programmed with tasmota or any other firmware that supports OTA. For the first time programming of ESP-12F module, here is my blog explaining the details of ESP-12F module programming.

Items Needed:


Assembly Step-1:




Assembly Step-2:

Assembly Step-3:

Assembly Step-4:

Assembly Step-5:


















Assembly Step-6:



Assembly Step-7:






















Assembly Step-8:

Assembly Step-9:


















Final Assembly: 





Let me know in comments sections if you have suggestions or improvements. Hope you find this low-cost DIY project useful.


Tuesday, January 01, 2019

20$ Pocket router as Domoticz Home Automation Gateway


TLDR; I built a openwrt based custom firmware(autom8box), that packs router_functionality+domoticz_server+mqtt_broker which is all-in-one home-automation-gateway-solution running on a cheap $20 router that can be purchased off-the-shelf. 

Wifi based home automation products are cheaper compared to zigbee or z-wave products, but the downside is, wifi devices need internet connection to perform their function. Letting your home devices controlled by a bunch of cloud servers on the internet may not be the best idea.

Internet connectivity for home devices should be optional - user should be incharge of deciding whether he/she wants to expose the home-devices to internet(may be for remote monitoring/controlling purpose), but in today's world, there are so called "alexa"/"google-home" compliant wifi devices who insist on internet else they wont work.

Thanks to the opensource community(tasmota/espurna/etc) for helping us to jailbreak those wifi devices like sonoff/blitzwolf/teckin/etc.. but jailbreaking solves part of the problem, still the need for a home-automation gateway is a challenge and requires some advanced knowledge of setting-up wifi_access_point + mqtt_broker + automation_gateway_server(ex: domoticz/openHab).

To address this gateway problem in a simplest and cheapest way, here is my attempt to convert an existing Off-the-shelf cheap wifi-router into a full-automation-gateway to support following functionalities.

  • wifi-access-point
  • dhcp and dns server
  • mqtt broker(mosquitto)
  • domoticz
GL-MT300Nv2 is a ~$20 device which supports opensource firmware like openwrt. All I did was to build my own variant of openwrt firmware that includes all necessary components like domoticz and mqtt-broker.


Downside of using this device as an automation-gateway is the limited-wifi-range and limited set of domoticz plugins(because of 16MB flash limit). But its a good start if you want to start playing with home-automation on low-budget.

Ok, lets get started, follow these steps to overwrite OEM firmware with autom8box on GL-MT300N-v2 hardware.

1) Download the autom8box binary from here.
2) Power ON your GL-MT300N-V2 box and wait for device's ssid to show up on you PC.
3) with OEM firmware, this device's ssid is shown as "GL-MT300N-V2-xxx"














4) Go ahead and "Connect", when a password window shows up, enter "goodlife" (this info is also printed on the backside sticker of GL-MT300N-v2)















5) If everything goes well, you will see the following message on your windows PC.










6) Open a browser, and enter following address in the URL field:
http://192.168.8.1/cgi-bin/luci/admin/system/flashops



7) As shown above, leave the password box empty and click on "Login" button. Next window will take you to firmware update section as shown below.





8) As shown above, uncheck "Keep settings box" and choose the file(autom8box-mt300nv2.bin) which was downloaded from a link given in step-1.
































9) Click on "Flash Image" button and wait for next window to show up and click on the "Proceed" button.























10) Next window you will see as follows, wait for about 2minutes.















11) After 2minutes, check on your Pc's wifi-list, new ssid "autom8box"  will show up


















12) when connected, password request will show up, again "goodlife" is the password.















13) If everything goes well, then your PC will get the ip address in the range of 192.168.8.x

14) open the following URL in the  browser - there you go! your new shiny domoticz UI
http://192.168.8.1:8080





















 From here onwards i assume you know how to add and configure the devices on domoticz. But as part of initial setup, here are some important steps i recommend to secure your home-devices-network.

Q: What are the ssh login details?
A: user: root and pw: goodlife

Q: How to change the root password?
A: using ssh, login to the box and run the following command
         "passwd root" when asked, enter the new password

Q: How do i change the ssid key?
A: using ssh, login to the box and run the following command
         "uci set wireless.default_radio0.key=my-new-ssid-key-here;uci commit wireless;wifi"

Q: How do i change the ssid?
A: using ssh, login to the box and run the following command
         "uci set wireless.default_radio0.ssid=my-new-ssid-here;uci commit wireless;wifi"

Q: I dont trust your binary, can i build the image from sources? is it opensource?
A: As of today, my openwrt build scripts are not organized well, but you can try to build the image yourself and let me know if you face any problem. Sources and buildscripts are all opensource on github, here you will find the build instructions.


Important Note:
As of now, autom8box doesnt support automatic saving of domoticz database, for the moment, after adding all your domoticz devices, you need to ssh login and run manual "reboot" command, during reboot domoticz databased is saved from ram to persistant partition - if you do hard-power-cut your previously configured devices on domoticz may get lost - i plan to fix this in future.


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.