Wednesday, November 25, 2015

Simple FET Driven Strobe Light

 
We needed a strobe light around the house for some mechanical troubleshooting.  Most 'normal' people would just purchase one, but what's the fun in that.
-----
Our solution was to use a 555 timer chip to drive a MOSFET to drive a 12VDC LED spotlight.  The internet is filed with 555 timer chip examples so we will skip that discussion.  The problem is that a 555 is fine for blinking a standard small LED, but a small LED doesn't put out enough light to be used as a strobe.
-----
The simple schematic below shows how a MOSFET can be used as a simple switch that turns power ON/OFF to the 12VDC strobe LED to match the smaller signal generated by the 555 timer chip.  The nice thing about using a MOSFET as a switch is, being a voltage controlled device, it can work without biasing components (YMMV).
-----
Wire the MOSFET up with some JST connectors for convenience and you get:
-----
I know this isn't exactly "high tech", but the rig works fine.  Below is a short video of it "stopping" a ceiling fan from a distance of about 10 feet:
 -----

Thursday, November 5, 2015

NumerousApp: Easiest way to push RasPI data to your iPhone

-----
As a long time fan and user of IFTTT.com we would see the Numerous Channel from time to time and wonder what it did, how it could be used, etc.  The Numerous tagline is "Numerous follows the most important numbers in your life and keeps them all up to date, all in one place" and that certainly got our attention.
-----
Numerous runs on the iPhone and the app has a fantastic UI.  The developer must be some rare artist/SWE hybrid type or something.  The app flows well, takes advantage of new iOS features (TouchID, Apple Watch, etc.) and is easy to personalize.  The graphs are clear and it even lets you customize when you get notifications (value to big/small, value change, change percentage exceeded, comments updated) and more.  It short; it is a joy to use.

Also, there are dozens of pre-programmed "metrics" that you can follow.  Check them out.  They are interesting and useful, but could get boring and after a while you will want to roll your own metrics to track more personal data useful for your applications.
-----
That's where this blog post steps in.  Numerous is really easy to get your personal data into it.  After only a short time we had created "numerousNumerous App metrics to:
 - track temperature/humidity sensors scattered around the house
 - track Internet UP/DOWN status
 - track security system triggers
 - track UP/DOWN status of LAN devices (security cams, Raspbery PIs, Imps, etc.) 
 - several other miscellaneous things.... 
------
How to get data into Numerous?
One way is to use the Maker Channel on IFTTT.com as a trigger to the Numerous Channel on IFTTT.com.  This requires no coding and is an easy way to pass three variables in one Maker Channel event trigger.  If you want to include the Maker Channel trigger URL into a Python or PHP script the applications are endless.

If you don't mind a little extra Python code, the task is almost as easy and offers more power and flexibility.  To give credit where credit is due, it is made simple with the Python API App by outofmbufs

Here's my simple example using Python and a Raspberry PI to get data to the iPhone.  The example shows how to create a Numerous metric, write data and comments to it, and view a graph of the data.
-----
Run the Numerous app on the iPhone and create a new 'metric'.  See the "+" sign in the upper right.  Click that.
-----
Give your metric a name.  Don't worry about what you call it, you can change it later.  Remember, I told you the app was flexible....
 -----
After you create the metric you can customize the way it looks.  Change the title and description to suit your needs, add a meaningful background image, input data manually, set privacy and notification setting, etc.  There is even a way to set the units.  I put the units as "megaFonzies" in the example to denote how cool the Numerous App is.
-----
Making the appearance pretty is fine, but what we want is to feed the metric data from the Raspberry PI via a Python script.  For that you need two numbers:
                    - your personal and secret API key:  Get this by selecting "Settings/Developer Info" from the main screen of the Numerous app.  Don't share this API key.  It will start with "nmrs_" and is shown as "nmrs_xxxxxxxxxxx" in the source code example below.
                    - the METRIC ID that you are writing to:  In the Numerous app click on the tile for the metric you just created and customized.  In the upper right you will see the classic "menu bar" icon.  Click that then "Developer Info" to find your METRIC ID.

 -----
Modify the Python script below with your API Key and METRIC ID values and run it.  Your metric will start recording the values that you feed it:
-----
Want a graph of the data?  Turn the iPhone to landscape mode.  You can pinch to zoom in and out for both the X and Y axis!  How cool is that?  At least 52 megaFonzies!

-----
That's pretty much it.  The Python script example below will introduce you to all the basics.  It writes the system clock seconds value to the metric, but that could be any value your RasPI can produce or scrape from the web.  The Numerous metric in the example is 'Public' that anyone can view, update, and comment on.  Feel free to use it for testing.  Good luck!
-----
# WhiskeyTangoHotel.com [OCT2015]

# Super easy way to track/graph RasPI data to your mobile device using NumerousApp.
# This simple prog logs the "seconds" value of the localtime value to a Numerous metric.
# The Numerpus mobile app will log, track, and graph the data for you.
# Of course, this value could be a sensor reading, CPU usage, Core Temp, or any other numerical value.

# D/L the NumerousApp and install it on your mobile device.
#            iPhone: https://itunes.apple.com/us/app/numerous-lifes-most-important/id797642904?mt=8
#   Google Play: https://play.google.com/store/apps/details?id=com.numerousapp

#
# See http://numerousapp.com/ for full APIs and other really cool applications.

# https://github.com/outofmbufs/Nappy/blob/master/README.md

# Also check out the Numerous integration to IFTTT.com for more awesomeness.
# Numerous can act as a trigger and receive triggers from most IFTTT.com channels
# Teaming the Maker channel on IFTTT.com with Numerous is VERY powerful!

# 1st, do a one time install from the terminal using "sudo pip install numerous"
# Must have pip installed to do this: "sudo apt-get install python-pip"
# Needed for the following import line.
from numerous import Numerous   

import time                                              # Needed to get the system clock settings

MyKey = "nmrs_xxxxxxxxxxx"             # Your personal Numerous App API secret key.  

MyMetric = "2884060434653363716"    # Get this by clicking "Developer Info" from the numerous app
                                                                  # "2884060434653363716" is set as an open/public metric 

                                                                  # Anyone can write to, so you just enter your personal API key to test.
                                                                  # Link to load the metric to the app: https://nmrs.co/m/lwtm3kymv2tg
                                  
# Set up for calls
nr = Numerous(apiKey=MyKey)
metric = nr.metric(MyMetric)

# This will return the Numerous App Label string.
label = metric['label']

# This will return the current value of the metric
Current_value = str((metric.read()))
 

# Let's get the current seconds value of the system clock, convert that
# to a number, and write that seconds value to the Numerous metric
Timestamp_seconds = int(time.strftime("%S", time.localtime()))
metric.write(Timestamp_seconds)

# Uncomment the next line to add a like (a thumbs up) to the Numerous metric
#metric.like()

# This will add a comment to the Numerous metric
Comment_update = "System timestamp is: " + time.strftime("%a, %d %b %Y %H:%M:%S", time.localtime())
metric.comment(Comment_update)

#Print info to the screen
print " "
print time.strftime("%a, %d %b %Y %H:%M:%S", time.localtime())
print "Metric Name: " + label
print "----------------------"
print "Current value:" +  Current_value                # returns last current value of the Numerous metric   
print "New value: " + str(Timestamp_seconds)    # the value written to NumerousApp

-----