Archives

All posts by K1WIZ

Sonoff: A Versatile WiFi Switch

I have been playing a lot with home automation technologies and the ESP82XX/arduino platform as hardware interfaces to my ever expanding control system. Most of the stuff I’m implemented has been Z-Wave, but though Z-Wave is an excellent technology, it is rather pricey to acquire. Since the ESP8266 & ESP8285 chips have started showing up in some finished electronics, it is now possible, now more than ever, to reprogram these devices with your own custom firmware!

One such device is made by iTead Studio and is called Sonoff. Sonoff allows you to switch an AC load using your mobile device or PC from anywhere via their own cloud. In my home automation implementation, I want as little cloud involvement as possible – to minimize attack risk, and to keep other firms from data mining my habits at home. The only way to do that is to use technologies that allow local control and without cloud reliance. Unmodified, the Sonoff is an excellent device and generally available for $7 per unit. If you don’t mind sharing your usage data with iTead Studio or relying on their cloud infrastructure to operate your device, then there’s no need to modify it – just use it as prescribed.

For those who want total control and privacy, you can easily use 3rd party firmware or write your own! In my case, I wrote my own firmware which enables a simple HTTP interface which can be called by my Domoticz controller or manually. Since I have a VPN connection to my home on a DDNS hostname, I can easily and securely operate any devices from anywhere in the world with no need for an outside 3rd party, right from my mobile. To flash a custom firmware, you will need a few things:

  • Sparkfun FTDI Basic 3.3v USB to Serial interface
  • 5 pin header (to solder into the Sonoff unit)
  • Arduino IDE software – to program the ESP8285 chip in the Sonoff
  • Screwdriver
  • Soldering Iron
  • Custom Firmware of your choosing or your own
  • Male to Female Dupont wires to wire the FTDI breakout to the header you’ll install (see diagrams)

*** WARNING *** WARNING *** WARNING ***

This project/information deals with MAINS CONNECTED equipment!  You should NOT attempt to undertake anything described herein unless you are familiar with and confident with working with electricity and electrical safety!  Risk of DEATH, FIRE, ELECTRIC SHOCK, and PROPERTY DAMAGE can result if you are attempt anything described here without being familiar with the concepts and safety herein.   I will not be liable for your use of any of this information should you or someone else be killed or injured.  I implore you to seek qualified and experienced help if you are unfamiliar with or unsure of anything described here.  PLEASE BE SAFE!

Let’s Get Started!

First, you will CAREFULLY disassemble your Sonoff unit and remove the curcuit board inside.  You will notice an unpopulated header where you will solder your 5 pin header to.  This is the programming interface.  (click for larger view)

Once you have soldered on the 5 pin header, you will now connect your FTDI serial breakout to your Sonoff:  (Click for larger view)

Once connected, now you will load your firmware into the IDE and choose the “Generic ESP8285” board and 1M size flash as shown: (click for larger view)

To flash: (NOTE: there is NO WAY to go back to stock firmware!  this is a final operation!!!)

  1. Remove 3.3v lead
  2. Hold down button & reconnect 3.3v lead (at the same time)
  3. Release the button
  4. Flash your firmware

That’s it!  Reassemble your Sonoff switch and your Sonoff should be ready to use!

Here’s my firmware.  You are free to use/modify it.   In my application I wanted the IP hardcoded, but you can easily change this to be DHCP.  I’m currently (at the time of this writing) trying to figure out how to serve the HTTP interface from SPIFFS but not quite there yet so for now, it is hardcoded and functional.

Here’s how mine looks:

Very simple!  You’ll notice that in my code, the switch responds to the URLs of /on and /off which makes it stupid simple to integrate with controllers like Domoticz, Wink, Smartthings, etc:  (click for larger view)

Once you configure this in your controller, you can then operate it as any other part of your system, and even with Amazon Echo (Alexa)!

First Project with the ESP8266 WiFi/MCU Module

The ESP8266 is an inexpensive WiFi-Serial MCU module that allows you to create sensors, switches, or just about any WiFi enabled connectivity for projects.  In my project, I decided to embark on a learning exercise by creating a real time energy threshold monitor to monitor my electricity usage and know when we were experiencing a time of high utilization.  The hope is that by doing so, we become more conscious about how much energy we use and that this can hopefully lead to better habits that reduce our energy costs.

We have a Z-Wave home automation system based on a Raspberry Pi, USB Z-wave stick, and Linux running Domoticz – an open source home automation suite.  Domoticz is a very capable system that lets you tie in a wide variety of control endpoints, data sources, and load switching.  To add the ESP8266 to Domoticz, I had to write some code (firmware) for it using the Arduino IDE (1.8.x) and install the community ESP8266 libraries.  I needed two channels (LEDs) to represent two states; low and high usage.  I used 2 GPIO ports on the module to light an LED (red or green) depending on what Domoticz detected for energy usage.  The interfacing is done as a simple HTTP request to the LED (see code).  In order to do this I had to also create a dummy switch in Domoticz under Hardware and create two separate instances; one for each LED.  

Once I had both virtual devices created, I was then able to see them in the devices list: 

It is a good idea to create a static IP reservation in the DHCP settings of your network, this way, the ESP8266 always comes up with the same IP address on your network: 

Now that we know what the IP address of the module will be, it was easy to assign each virtual switch in Domoticz to each LED (click for larger view):

You can see here how I created the linkage to each LED.  Domoticz makes it easy!  They now show up on the Control Board in the Domoticz web UI:

I still had to have logic in Domoticz to decide when to switch back and forth between red and green LEDs.  Fortunately, it’s easy to do and set that in the Events utility which allows you to build blocky style logic code that makes Domoticz pure magic:  

Here is a LINK TO THE SOURCECODE for the ESP8266 module for this project.  It should help you setup something similar.  These ESP8266 modules are the perfect thing for creating great automation solutions, only limited by your imagination!  Let me know how you use them in your project!  I plan to transfer my module into a decorative frosted glass globe that will glow and change color when the energy demand changes.  Meanwhile, here’s a video demonstration of the module in action:

 

I recently setup a wireless front door security camera to watch and notify of any visitors to our front porch.  During the holidays, there’s a lot of package stealing being reported in the news.  I am prepared!  My home made system does the following:

  • uses passive infrared (PIR) to detect motion within 30 feet
  • sends a push notification of the detection to my smartphone via pushover
  • records 2 minutes of 1080p video & converts it on the fly from H264 to .mp4
  • uploads the .mp4 file over wifi to my NAS for safe keeping and later viewing
  • sends another push notification when the .mp4 file is uploaded
  • continues to watch for the next motion event to record

The camera and PIR sensor are mounted in a weatherproof enclosure and can be powered from any DC source from 7-35v.  Here are some close up pictures.  Click for larger image:

file_000 file_001 file_002 file_003

 

 

 

 

 

 

 

 

 

 

 

 

 

The logic:

  • PIR motion event causes the sensor to send a 3v signal to GPIO pin 26 on the raspberry pi computer.
  • When pin 26 goes high, it is read by the “detect” function and stored in a variable.
  • The IF logic uses the variable for detection to either process video recording or return to the continuous loop.
  • The continuous loop runs every second

How to setup:

  • grab the latest copy of raspbian-jessie-lite image (no gui)
  • burn jessie lite image to MicroSD card
  • run raspi-config to set options (internationalisation, and turn the camera socket on if using a camera module – recommended)
  • log in using raspbian default pi user and install necessary packages, update, & reboot the pi:
    • sudo apt-get update
    • sudo apt-get dist-upgrade
    • sudo reboot
    • sudo apt-get install rsync wiringpi gpac htop exfat-fuse exfat-utils
  • insert a large capacity USB stick to cache video recording to & format it with exfat file system and mount to /video
    • fdisk /dev/sda (change partition to type exfat)
    • mkfs.exfat -n video /dev/sda1
    • create /video directory
    • edit /etc/fstab and set mount point for USB exfat key to /video (this ensures the USB is mounted on each boot) Your video files will process on the USB key before being uploaded by rsync (you need a NAS or server that can receive the incoming rsync stream).
  • setup wifi (/etc/wpa_supplicant/wpa_supplicant.conf)

wifi-setup

 

The loop is a simple bash loop called by /etc/rc.local and runs whenever the unit is turned on:

loop

 

The file containing the functions does all the heavy lifting:

pi-mocam

 

DIY Holiday Flickering Lights

Happy Holidays to all!  In case you are in the spirit to DIY your own window candles or make a flickering lantern/fixture, here’s a Arduino sketch I wrote that has lifelike flickering of up to 3 channels (candles).  If you only want one channel per light, just comment out the 2nd and 3rd LED lines in the LOOP code.  Here is the sketch, happy holidays!:

3-candle-flicker

Freedom to distribute is granted.


14390657_935708456556577_946885921814522288_n

The Busy Bee Chip

Does your employer or organization have a pushed policy that prevents you from changing your computer’s sleep/idle screen lock?  I have developed a solution, read on:

A typical computing experience without Busy Bee Chip

You’re busy throughout the day and you may have answered a 12 minute phone call from a colleague, after which you return to your computer to continue your work and find you have to log in again.  A pain in the arse for sure and if it happens several times a day, you are likely unhappy about it.  Going idle often also gives “Idle Snitches” in the office ammunition against you and you might find yourself the subject of deeper management scrutiny as a result.  Systems administrators, in an effort to improve security within the enterprise typically roll out policies that force this to occur on PCs.  The school of thought is that people forget to lock their computers when they step away and administrators use this as a solution to prevent that by removing the human element.

Installing software on a work computer is often a no-no or enough to get you fired or at least, in trouble with your IT manager.  But what if there was a hardware solution that was discreet and appeared in the Device Manager as an ordinary mouse?  I have seen and read articles on some clever mechanical tricks people use to thwart idle timeouts and some are quite clever, but again rely on some elaborate mechanical means of tricking the mouse in a way to make it think it was being moved.  Not very elegant, and aside from being noticeable, it also is not the best way.

How your day is with a Busy Bee Chip

  • No longer need to frequently log back in after going idle when you take a phone call or perform a non-computer task – saves time & hassle
  • You always appear active in monitored presence to Management, colleagues, and office snitches!
  • Easy to use; no drivers required – nothing to install, just plug Busy Bee Chip into an available USB socket – it goes to work immediately  (NOTE: Windows users – if asked to install a driver, just hit CANCEL)
  • Works on remote desktop sessions for road warriors & telecommuters (keep your mouse pointer in the center of your remote screen)
  • Not detectable by IT or Management – shows up as a standard “HID Device” (aka mouse) in Device Manager
  • Works on Windows, Mac, & Linux
  • Take short breaks without going “idle” in Skype for Business or other tools which have presence monitoring

Get your Busy Bee Chip today for just $25 dollars!   Shipping is free via first class post to anywhere in the USA!




 

FOR SALE

Hi, I have several items for sale.  Take a look and browse below to see if there’s something you might be interested in.  Should you be interested in any one of these items, just txt me at 508.326.1521 and make an offer.  If a price is listed herein, it is negotiable, so give it a try!   I offer local pickup for all items and should you desire to have anything shipped, I can do that at additional cost.  I accept the following payment methods:  VISA/Mastercard/Discover/Debit, Cash  (sorry checks are not accepted), or Paypal.

PLEASE NOTE:  all items have been tested and are known to function properly at the time of listing.  If you elect to ship an item, it is your responsibility to pay for insurance in addition to your applicable shipping fees.  Since many of these items are used, but in excellent condition, I recommend insured carriage.  30 day warranty is offered on all items sans shipping fees.  All items are in excellent condition unless otherwise stated.

 

  1. Kodi Media Center (Set Top Box) – Can also be used as light duty computer for Facebook/email, etc.  Asking $150 each.  Price is for base unit and power supply only – bring your own Keyboard/Mouse/Screen.   Two types shown below – I have 2 units (one each).  Click thumbnails for full size image: Photo-2016-07-05-20-05-23_1860Photo-2016-07-05-20-05-37_1861Photo-2016-07-05-20-05-49_1862 Photo-2016-07-05-20-07-43_1866Photo-2016-07-05-20-07-28_1865
  2. Complete Sirius Starmate docking boom box and receiver – this is a complete package.   I’m asking $200 for the entire setup.  This is everything you need to enjoy satellite radio anywhere.  Photo-2016-07-05-20-10-27_1868 Photo-2016-07-05-20-10-31_1869 Photo-2016-07-05-20-10-49_1870 Photo-2016-07-05-20-11-04_1871
  3. Complete Sony PS3 Gaming/Blu Ray Console – Asking $200 for all.   Photo-2016-07-05-20-15-25_1872
  4. Roku Soundbridge Internet Radio Streamer with remote.  Has analog and digital outputs, Ethernet and WiFi connectivity – SOLDPhoto-2016-07-05-20-17-25_1873 Photo-2016-07-05-20-17-48_1874
  5. Linksys E1200 router with DD-WRT opensource firmware on it – $10.00   Photo-2016-07-05-20-18-34_1875 Photo-2016-07-05-20-18-44_1876 Photo-2016-07-05-20-18-57_1877
  6. Cisco 1812 Branch Office Router IOS v. 12.4 – asking $40.00 Photo-2016-07-05-20-20-09_1878 Photo-2016-07-05-20-20-28_1879
  7. Cisco 3750 stackable managed Switch – 48 100mbps ports, 4 1gbps SFP ports.   asking $125 each (I have 2).  These are NON-PoE   Photo-2016-07-05-20-21-50_1880 Photo-2016-07-05-20-22-01_1881
  8. Motorola 2 CH VHF 20 watt Transceiver  – will program to HAM band and I will program your channels for free.  Includes PL259 adaptor & OEM Microphone – SOLD   Photo-2016-07-05-20-23-37_1882 Photo-2016-07-05-20-23-51_1883
  9. Motorola UHF 16 CH 25 watt Transceiver – Will program to HAM band and I will program your channels for free.   Includes OEM Microphone – Asking $35  Photo-2016-07-05-20-24-55_1884 Photo-2016-07-05-20-25-12_1885 Photo-2016-07-05-20-25-32_1886
  10. Ammo Can D-Star Hotspot – this is a complete turn-key 5 watt package – asking $550.  It is carefully designed and is a real unique piece of field gear.  I’m also including the T-Mobile 4G Rocket modem! Ammo Can Hotspot Hotspot Internals
  11. Motorola 900MHz Transceiver – SOLD   Photo-2016-07-05-20-26-50_1887 Photo-2016-07-05-20-27-14_1888
  12. Yaesu FT-2600 2 Meter VHF Transceiver with Manual – SOLD  Photo-2016-07-05-20-28-16_1889
  13. Pentium D desktop computer with hard drive array controller, drives, green cold cathode case lighting, dual Intel gb NICs.  Will run Windows 7 but has Linux onboard.   – Asking $80  Photo-2016-07-05-20-29-59_1890 Photo-2016-07-05-20-30-55_1891 Photo-2016-07-05-20-31-49_1892 Photo-2016-07-05-20-32-04_1893
  14. Home Theater PC – this beauty was built by me a few years back to build a Myth TV DVR unit and was awesome for recording off the air programs.  You could easily install Win 7 on it and run Windows Media Center or Myth on Linux.   Has HDMI output for sound and video connection to your entertainment center.  I modded the case and installed 3 blue lit fans for effect and cooling.  Looks pretty cool with blue light spilling out of the case.   Has DVD RW drive installed.  Asking $100 for the unit  You could make a really souped up home server with Kodi interface.  Photo-2016-07-05-20-36-43_1897 Photo-2016-07-05-20-36-49_1898 Photo-2016-07-05-20-37-01_1899 Photo-2016-07-05-20-37-12_1900 Photo-2016-07-05-20-37-24_1901
  15. Roku 2 XS Streaming Player, has Angry Birds game – SOLD  Photo-2016-07-05-20-38-16_1902 Photo-2016-07-05-20-39-03_1903 Photo-2016-07-05-20-39-22_1904
  16. Plasma lamp – asking $5  Photo-2016-07-05-20-42-43_1905
  17. Dell Latitude D830 Intel Centrino laptop (has serial port, WiFi, DVD, and Audio!) – asking $90  Photo-2016-07-05-21-01-15_1906 Photo-2016-07-05-21-01-30_1907 Photo-2016-07-05-21-01-40_1908 Photo-2016-07-05-21-01-50_1909 Photo-2016-07-05-21-02-13_1910 Photo-2016-07-05-21-02-28_1911 Photo-2016-07-05-21-02-51_1912
  18. Internet Labs DVAP D-Star hotspot – (missing stub antenna, add your own) – asking $200  Photo-2016-07-06-22-16-17_1914
  19. Nokia Lumia dual SIM phone – NEW – SOLD   Photo-2016-07-06-22-19-06_1915

Abstract

A mobile lifestyle is a way of life these days.  We have devices in our pockets, and the cloud is becoming more of a household resource than it ever was.  How often did you open an email on your mobile device (tablet, phone, etc) only to find that you really needed to go your laptop or desktop to print that email, or website?  Surely that moment can be a frustrating inconvenience, but with cloud printing, not any more!

By setting up cloud printing, you can put any printer online and make it shareable with others or your various devices and simply print from them like you do on your full service PC.  This can also make faxing a thing of the past (if it isn’t already) by sharing your printer with someone else using the sharing capabilities of the cloud.

In my solution, I use Google’s cloud printing technology as well as some of my own technology running in a Linux VM (virtual machine).  In this way, my printers can “go to sleep” and I don’t have to leave a computer running just for the sake of this convenience, yet they remain available in the cloud – willing and able, ready to serve. With Google’s cloud print, I can:

  • Share any printer anywhere in the world on any device
  • Manage print jobs from anywhere
  • Queue print jobs if my print server is offline – they print as soon as the server is back online again
  • make ANY printer (cloud based or not) accessible to any device – no need to buy expensive “cloud ready” printers or worry about compatibility with certain applications
  • connect the CUPS (Common Unix Print Server) to google, making hosted printers available to the cloud

I already have a Linux home server that runs many VMs that run various services for our home; (PBX phone system, DLNA server, Filesharing, local caching DNS, business applications, database, & automation tools).  Why not add a local print server and connect it to the Google Cloud?

Here’s how I did it:

First, install the required software to build a connector. I added this to a VM I already have running on my server (I use Ubuntu, but use any Linux you like).  Install the opensource chromium browser and a X virtual frame buffer (the frame buffer is needed because I run the server headless and it has no installed GUI, so the framebuffer fakes a screen for the browser to draw and therefore run):

sudo apt-get install chromium-browser

sudo apt-get install xvfb

We now create the kickoff script that will be used to start the browser automatically and then background the process, thereby creating a “service” that is used as a Google Cloud Print connector.  We save and then set the execute bit to make the script executable.  Notice how I am forcing the program to run as “john”.  I do this because I don’t want it running as root – this would open up nasty security implications – please don’t be “that guy” who runs everything as root – it’s really stupid and invites serious risk of abuse by hackers or malicious software:

vi gcpstart.sh

#!/bin/bash

su john -c /usr/bin/xvfb-run –server-args=’-screen 1, 1024x768x16′ /usr/bin/chromium-browser –no-startup-window > /dev/null &

~         

chmod +x gcpstart.sh

Once we’ve set it executable, we must now call it via /etc/rc.local so it starts anytime the VM is booted:

vi /etc/rc.local

#!/bin/sh -e

/home/john/gcpstart.sh

exit 0

But WAIT!  we’re not done just yet!  We need to install the CUPS print server so we can make the Linux system talk to local printers.  We install CUPS as follows:

sudo apt-get install cups

Once CUPS is installed, you then add printers to CUPS as local printers.  CUPS has a nice webUI for managing printers so you can do this all in a web browser on a headless server.  Just point your browser to https://ip.of.cups.server:631 and you are in business once you allow access to the CUPS interface by making a few simple config modifications to CUPS.  (CUPS setup and admin is not the scope of this article, so please refer to Google for how to setup CUPS).

Screen Shot 2016-05-28 at 9.40.14 AM

Screen Shot 2016-05-28 at 9.40.39 AM

Once your printers are added to CUPS, you then need to tell chromium-browser about them and log the browser into your Google Account.  This is the part that connects your CUPS hosted printers to your Google cloud.  You need to launch chromium-browser at least once to set this up.  I did this from my Linux workstation by SSH’ing into the VM server with the X forwarding flag set and launching the browser on the command line as the unprivileged user I intend to run the service as:

ssh -X john@ip.of.vm.host   (where john is the unprivileged user)

By running it once in this way, the browser executes on the VM but draws remotely on my workstation so I can graphically setup the browser, get it signed into my Google account, and then tell Google about my printers.  Once you “sign in” the browser to your google account, you then go into the advanced settings to add your local printers to the cloud – the rest is intuitive:

Screen Shot 2016-05-28 at 9.41.57 AM

Once you’ve registered your printers, you can then close the browser and reboot the VM and the script you used to call it on boot in /etc/rc.local will start chromium-browser as an unprivileged user in headless mode – thereby creating a connector service.  At this point, any mobile device within your Google cloud account can now see the printers and print directly to them from anywhere!

13323188_857347877725969_1905479514915840154_o

Simple Download Manager for Linux/Mac

If you’re like me and you travel often, you know all too well how badly hotel wifi sucks.  Often, any attempt to download a large file is often met with frustration when the signal drops and you have to restart your download all over again.  Fortunately, there is a simple and blissful answer to this.  Enter, the persistent wget download script:

download-mgr2

As you can see here, only a minimum of code is needed to ensure you get that large file, no matter how many times your hotel connection craps out.  Simply create a password file (if downloading from a SSL site) and supply any needed user/password credentials.  This allows you to simply paste in a link and then walk away while the script does its magic.

Dependencies:

You need to install wget into your linux or mac machine.  Once you have that package installed, then this script will work just fine.

In this example, I’m downloading a large movie file from my NAS at home while I’m overseas.  You can see how this works here:

download-mgr