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:

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

 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.