Projects

Here’s what I’ve built, or what I’m currently working on.

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!




 

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

I am working on a new build of D-Star hotspot which will be way better than the DVAP, or DHAP.  The new product will feature compact headless industrial design with super easy management and use.  Here are some highlights on the unit which is currently in development:

(but first, a teaser picture of the product – the finished prototype – click for larger images)

IMG_0078  IMG_0080  IMG_0081  Screenshot from 2015-04-13 16:36:18

  • Universal 9-35 VDC power input with internal regulation – power easily with Solar, DC, or portable source like Li-Po packs
  • UHF operation in the 70cm Ham Band
  • Easily shows operational status by panel mounted LEDs
  • Panel mounted NEUTRIK connectors for Ethernet & USB Tether connections for supreme field durability
  • Panel mounted coaxial DC input connection
  • fan-less design – no moving parts to wear out
  • Built in a compact die-cast aluminum enclosure that can stand the rigors of mobile field use
  • Easy web based configuration management via laptop on shortcable to ethernet port
  • Simple “Bat Shit Stupid” operation by 2 buttons, Reboot & Shutdown.
  • Seamlessly switch between USB tethered internet (iPhone & Android) and wired internet
  • You don’t need to be a Linux guru or programmer to operate this unit
  • Low power footprint (approx. 6 watts)
  • Panel mounted SMA antenna connector accepts any standard UHF SMA whip antenna, or for increased range, use an external antenna with an SMA adaptor
  • Approx. range is 1 mile line of sight but on average you can get .5 miles or more with just a whip antenna
  • Keeps you connected to the world-wide D-Star network while on the move or where D-Star repeaters are not available.
  • LED panel mount indicators for: ircddbgateway, dstarrepeater, internet reachability, & MicroSD card I/O for “at a glance” operational status.

Stay Tuned – more details and pictures to come soon!