Category Archives: computers

ZHA Visualization

Overview

This visualization of a home automation shows a mesh network of smart switches, smart plugs, and sensors.

The rectangle object in the diagram identifies a Zigbee Coordinator (radio adapter) which is the go-between for the automation hub. Sensor end devices (circular object) that are within close proximity can signal back to the Coordinator directly. Data is transmitted using a low power RF so signal strength is a factor. Happily, since this is a mesh network, the more distant end devices can chain relay through smart devices (oblong object) which relay amplify to the Coordinator like a router.

Router Detail

Winter is Coming

In sympathy with peoples abroad who might be chilling these next few months and in consideration of rising energy costs closer to home I am implementing a new routine with hopes for conserving.

The first step is to adopt a “time of use” billing strategy that utility companies offer. The utility solicits a pricing incentive for customers to refrain from and reduce consumption during the part of day that is historically prime time for energy usage. My humble abode is equipped with a heat pump and that is a big consumer so I give you the following strategy:

On-peak is from  6 a.m. to 9 a.m., Monday through Friday excluding holidays, so I don’t intend to use the heat pump(s) or worse — system AUX heating, a big draw item. So to comply, the thermostat will be turned down for this time slot. To mitigate rise and shine shivering or breakfast hour discomfort the living space will be pre-heated using the Off-peak ($0.067) rate before it cuts off. On-peak is a penalizing $0.39 per kilowatt hour and to be avoided.

thermostat – settings

  • 0500-0600 74 degrees (pre-heating)
  • 0600-0900 65 degrees (On-peak)
  • 0900-1600 68 degrees
  • 1600-2145 72 degrees
  • 2145-0500 65 degrees

A Smart Thermostat simplifies the task of micromanaging the setting adjustments.

extra credit

Ensuring that the water heater, also electric, will never draw current during the On-peak is a bit more involved but easily controlled. A relay to open/close the 240v contactors for the heating element can be actuated by a 120v smart plug. An [smart-hub] automation routine then will pause the appliance like a timer.

future plan

There is a Super Off-peak between the odd hours of 10 at night and 5 in the morning. At a mere $0.043 cents per kWh this will be an opportune time period to charge the EV.

maybe…

At some point go off grid? Solar array? Powerwall? In any event, please stay warm.

screen grab a la 1958

A computer screenshot is trivial today. Using software or even simple button press of PRT SC on the keyboard. But, the terminology comes from the act of literally taking a picture of the screen — the television screen that is.

B&W televised demonstration of working steam engine recorded in the first grade classroom and broadcast as local news.

Using a hand held [Argus C3] film camera in 1958, the resulting capture lost contrast clarity as it was a copy of a copy. (a flatbed scanner was used to scan the original photographic print just posted here so a copy of a copy of a copy) The light would have to be right as the camera would not have had automatic exposure and any glare or refection on the TV screen minimized. Camera focus would be a consideration; pre WYSiWG. Though grainy, it was a resourceful method and the proud parental event was luckily/successfully recorded.

We have it easy. SAVE AS would have archived the entire video and WITH sound, but back in the day this screenshot example was high tech.

It’s a Goner

My initial concern was one of monetary loss ($750). My connected device was gone. Misplaced. Standing-by in the left front pocket of my trousers, normally, it lends a sense of form against my thigh. An occasional pat or  brush of hand reassures that it is secure. Previous experience told me that this was a good location. Too rigid for a hip pocket and prone to spill from an open shirt pocket; it had only slipped a very view times when seated within the soft confines of sofa or pillow chair. One naturally makes a wallet / phone check upon exit.

The last reaffirmation check revealed that the usual location was empty. Confounded, I checked the other pocket possibilities. Nope. It was missing.

Recovery would be a puzzle. I would have to recollect when last handled as well as account for all events and movements since. A window of confidence was roughly 45 minutes but then you realize that a general summary recollection is clear but all of the small ‘witness’ details insignificant at the time, are brain stored in short term low level memory. Initially I was assuring myself that my phone was likely safe and would “turn up” but no; it took hours of revisualization and introspective thought to reconstruct.

The other pilot and I were leaving the airport on foot for an impromptu round trip to Cooper’s Island but not before a quick pit back at the jet to retrieve hat and sunblock. I reckoned that while crouching beside open suitcase in the bag compartment perhaps it had deposited there (False hope.  It hadn’t ).

Early on along our route we encountered two young girls opposite direction who were keen on our uniforms. We side stepped clear of the road and had a pleasant chat on the shoulder  with one being a Londoner and the other a Local. Before carrying onward there was a FB friending and group Selfie. Did I withdraw my (camera) phone and mis pocket opening? Did it fall silently into the deep grass? I would later retrace this 1/2 mile stretch trying unsuccessfully to recall the exact spot we all stood. Sweep scanning blades of  green for a glint of case or reflection on gorilla glass a dark thought occurs. Pickpocket! (Possible I suppose but a stretch)

Having arrived at the park entrance and while stalling for a bit while the other fellow captured some white sand beach setting photo I angled my leg to retie shoe lace. (squeezed from pocket opening) Was it the first beach or the next? Which fence railing?

24 hours had elapsed and I had gone back twice to search replaying everything but to no avail. I had to exhaust the possibility that it wasn’t just laying there undiscovered. After all, an opportunist would surely have attempted to access and the clever Find-my-Smartphone feature would broadcast its coordinate location. Alas, being out of country as I was the phone’s antenna was in airplane mode and therefore off network. A thief would merely have to wait it out knowing that the owner would probably remotely erase the device contents eventually after losing hope.

In fact, I was seriously poised to do that very thing. A data breach would be ugly with personal information of every kind risking exposure. The phone is locked by 4 digit PIN but with time and sophistication a good hacker might succeed. I learned that while the data wipe feature would allay these concerns, this option would also kill any possibility of tracking or easily identifying the device. In fact, it would make it possible for the discoverer to activate a fresh install — finders keepers.

Disgusted that I lost control of my property, resigned to writing off the asset as a loss, disappointed in having failed to find it, soul searching; why I am such a slave to the thing in the first place. Like so many by habit, I find myself staring at the small screen during every possible moment. How to go about replacing? Perhaps now is a good time to go cold turkey and kick this addiction?  I’m part way there.

By the next day I’ve traversed many states of mind; bummed, gloom, depression withdrawal but I’m less frequently checking the empty pocket or having phantom sensations. I’m actually gazing about spaces and at people during the idle moments.

By now the lost phone should be at lo-batt or nearly depleted. Seriously ready to Nuke…

Reunited

[spoiler alert: review the previous post first]

The CSR behind the desk at airport FBO doubted that I’d ever see it again. It had not shown up at their lost & found. I hadn’t expected it to. Whoever picks it up will keep it, she says. Just the same, I was wondering if perhaps an honest citizen might  turn it in. I had asked a Park Service  maintenance employee if they knew and the suggestion was floated that I try the local Police Substation. The CSR was dubious and I was primed to agree but then somehow we decided; let’s try.

She picked up the phone. I was only party to the one sided conversation but when she started relaying bullet questions from the other end such as: What color is it? and: What is the screensaver? (Sailboat) and then: What is the name on the boat? it became crystal there was going to be a happy outcome.

The CSR personally drove me over to claim it. I would have liked to have rewarded the soul who turned it in. My faith in humanity is restored. May that individual enjoy their good Karma.

I credit good police work. The officer had actually called over to the Bermudian Maritime Authority and determined that the yacht pictured from the lock screen was not in country. I explained that a year ago that it had been and the official confirmed this to be known.

property receipt
BTW, I’m off the wagon but trying to be diligent about usage. It goes without saying I’m installing a collar and chain 😉

episode with git

A key piece to web developer modernization is a scheme called GIT which allows synchronization of files and versioning control. Further, one can easily invite collaborators to join in on a project or fork to their own. FTP gone social.

There is a learning curve. There isn’t a user friendly face on GIT. All interaction is via the command line. A new language with artful terms such as Branch, Merge, Add, Commit, Push, and Pull to understand along with esoteric switch options: e.g. -a -u -m

It can be simple or complex. Unfortunately I blundered into the latter by creating several local repositories. One of which was innocently placed downstream of a root repository thereby creating a submodule. I had no idea what I had done apart from the realization that I was no longer able to modify the contents of this submodule from within the main project. In laymans terms; it was screwed up. Simple to implement but so difficult to undo.

A search result offered instructions to eliminate a submodule reference with all sorts of caveats and cautions.

I eventually made a draconian choice and abandoned my local directory tree structure by emptying the files. The submodule became its own repository after I split it off from the root but kept the original files. Its git tracking was undisturbed. In the root repository it was hoped that a simple Clone from the remote would restore all but this didn’t pan out. The remote was linked to deleted files in the old structure and *new* copied files refused to be tracked. A fresh local directory with a new name was established in order to begin again.

While learning the complexities (the hard way), I plan to “keep it simple” going forward.

Heroku and mysqli

Giving Heroku another try, it was straight forward to deploy a php app / mysql database. The routine is similar to the OpenShift PaaS and Heroku is not much different using the CLI as well. Console functionality is barebones.

My test app bombed during its maiden run however with a fatal error: Class ‘mysqli’ not found in /app/www/db.php on line 5. I learn that the mysql_connect() syntax in php is old hat and myslqi is to be encouraged instead. The old way works fine on Heroku but for some reason mysqli syntax has not been configured — and my app is peppered with mysqli.

Thanks to this search result, what one does  is to configure Heroku to use a custom buildpack (see below).

1
heroku config:set BUILDPACK_URL=https://github.com/travstoll/heroku-buildpack-php

Then create an empty commit and push the app again to force heroku to recompile the runtime:

1
2
3
git commit --allow-empty -m "empty commit"
git push heroku master

That worked and my app is restored without recoding.

Modernization

S’man advises that using a traditional hosting service to render web pages is passe. Not wanting to be eclipsed by new technology I followed his encouraging to advance. Aided by online postings, hints, and narratives one can learn the new jargon and implement the latest in cloud computing methods.

OUT

IN

There are many solutions offerings. I discounted Google App Engine off the bat because their implementation is a bit arcane. Ditto the Amazon Elastic Compute Cloud. Heroku was limited in their programing language offerings. AppFog looked promising with a generous CPU allotment but their console system behavior was discouraging. OpenShift by Red Hat however, seems like a winner with excellent documentation and performance. Beware: Most PaaS(s) rely on the Command Line Interface but as the concept matures; user friendly interfaces will develop.  App templates are currently provided for common setups but fine tuning requires knowledge of the command line.

A domain name is furnished with each app that you build on OpenShift. The domain that you are viewing currently is actually: wordpress-strombotne.rhcloud.com/ It is possible to use a CNAME record to point to that URL with one more personalized i.e. the sub-domain  blog.strombotne.com One uses their domain name registrar for this purpose and this is fine. However, a weakness that I’ve discovered is in using a naked domain, e.g. strombotne.com for an OpenShift app. Here’s where it becomes a bit wonky.  You can’t use CNAME with a domain name but typically use an A record resource with an IP number. The OpenShift DNS is limited as one isn’t provided. The fix is to try Domain Forwarding and Masking — a band-aid.

 

 

for the dedicated small audience

Discovered YouTube Channels and have subscribed to some niche programming like: DRIVE, a worthwhile video source if you happen to lust for cars like the GT3 cup car. These are all short works because there is only so much time in the day that one can spend consuming media. Here’s a representative piece on Lowriders from Motortrend .  They are cinematic and skillfully done in the artistic vein of Top Gear — which has its own channel as well.  There are numerous categories from which to choose should automobilia not be your thing. You can immerse in Kinetic Art or Surfing or… whatever your interest.
Unfortunately you can not replicate the YouTube channel subscription experience in your living room on your HDTV.  Not yet.  A few 3rd parties using YouTube APIs are trying and some have tried but Google has locked down this functionality. It is probable that Google is seeking a monetization model.
TiVo has “Web Videos“, some of them in HD, that showcase the Internet connected TV. Example:  The excellent production of CNET video podcasts  offerings can be viewed via YouTube Channel but on your high definition TV via TiVo Season Pass the experience is complete. One can see what Google needs to achieve.

runmeter export display

Runmeter is an iPhone app useful for GPS tracking outdoor exercise and as such does a fine job eclipsing some of the other variants. Runmeter features the ability to export and share your (KML,GPX,CSV) data via email or link. Although Runmeter has excellent data analysis menu choices on the iPhone itself and can recall and layout event history; the Runmeter does not have a co-branded display and summary website. However, it is possible to mirror your events and statistics on a personal remote web page. Using the Runmeter export feature you might try uploading a GPX file to Everytrail or Trailguru. I prefer to roll my own and follows is a tutorial on how it can be done.

Add a table, which mimics Runmeters CVS file column headings, to your mysql database.

CREATE TABLE raw_runmeter_data (
  Route varchar(35) NOT NULL,
  Activity varchar(10) NOT NULL,
  Start_Time datetime NOT NULL,
  Time_normal time NOT NULL,
  Time_normal_seconds smallint(6) NOT NULL,
  Time_stopped time NOT NULL,
  Time_stopped_seconds int(11) NOT NULL,
  Distance decimal(5,2) NOT NULL,
  Average_speed decimal(5,2) NOT NULL,
  Average_pace time NOT NULL,
  Average_pace_seconds int(11) NOT NULL,
  Climb int(11) NOT NULL,
  Calories int(11) NOT NULL,
  Fastest_speed decimal(5,2) NOT NULL,
  Fastest_pace time NOT NULL,
  Fastest_pace_seconds int(11) NOT NULL,
  Notes text
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

With this table constructed use PHP to retrieve your event data from the Runmeter server and store it in the mysql table. This code downloads your Runmeter CSV file and after some housekeeping, imports the data events to your mysql.

import_cvs.php
[php]
<?php

/**********************************/
/* This file is named import_cvs.php
/* As the file name implies, this code will import your data from Runmeter. You may run this file manually or better still, by setting up a cron job.
/* Edit the entry below to reflect the appropriate value i.e. your unique Runmeter export URL which should look something like this: “http://share.abvio.com/438h2 53u978cd/Runmeter-Route-All.csv”
/*********************************/
$inp = file(‘http://share.abvio.com/***********/Runmeter-Route-All.csv’);
/*********************************/
/* If you use this code, find a flaw, enhance or otherwise improve it then please let me know
/* via comment or link.
/* End Edit (nothing to do below this line)
/*********************************/

include ‘dbinfo.inc.php’; // your variable constants for database access

if (!$inp) {
echo “<p>Unable to open remote file.\n”;
exit;
}
$out = fopen(‘runmeter_clean.csv’,’w’); // a flat file which will temporaily hold your imported data
for ($i=1;$i<count($inp)-1;$i++) // step through the cvs file to leave out the first line ($i=1) and the last line of the file (count($inp)-1) because the first line is a header row and the last line has extraneous data
{
fwrite($out,$inp[$i]);
}
fclose($out);

echo “<font color=red>{$i} Runmeter events</font><br>”;

$file_handle = fopen(‘runmeter_clean.csv’,”r”);

$con = @mysql_connect($databasehost,$databaseusername,$databasepassword) or die(mysql_error());
@mysql_select_db($databasename) or die(mysql_error());

// first task: let’s empty the mysql table (remove all existing recors)
mysql_query(“TRUNCATE $databasetable”);

// now insert the new recent data. Process Each Line
while (!feof($file_handle) ) {

$data = fgetcsv($file_handle);

$Route = mysql_real_escape_string($data[0]); // this function escapes out the pesky apostrophe character (and double quuotes etc.

$sql_insert = “insert into $databasetable ( Route, Activity, Start_Time, Time_normal, Time_normal_seconds, Time_stopped, Time_stopped_seconds, Distance, Average_speed, Average_pace, Average_pace_seconds, Climb, Calories, Fastest_speed, Fastest_pace, Fastest_pace_seconds, Notes)
values ( ‘$Route’, ‘$data[1]’, ‘$data[2]’, ‘$data[3]’, ‘$data[4]’, ‘$data[5]’ ,’$data[6]’ ,’$data[7]’, ‘$data[8]’, ‘$data[9]’, ‘$data[10]’ , ‘$data[11]’, ‘$data[12]’ , ‘$data[13]’, ‘$data[14]’, ‘$data[15]’, ‘$data[16]’ )”;

echo $data[0].”<br>”;

mysql_query($sql_insert);
}
fclose($file_handle);
@mysql_close($con);
?>
[/php]

Runmeter furnishes a unique and user specific download URL. Replace the URL (line #8) in import_csv.php file code above with yours. If not already familiar with the Runmeter app, review the screenshots from the app below. Start with the Routes Tab then touch Email/Export All. Next screen choose CSV File URL. (Runmeter sends your event data from your device to update your file CSV File on their server) In the third screen you are provided the discreet link which you will need for access. This URL does not normally change so you will not necessarily need to alter your php configuration above but note that current Runmeter app behavior does require you to refresh their data by doing this little procedure each time.

You can run import_csv.php as needed manually from a web browser. I created a cron job that will do this automatically. (once daily so as not to hammer the Runmeter server)

* * * * * wget -q http://www.strombotne.com/import_cvs.php > /dev/null 2>&1

With the event data in place. It is a simple task of writing some queries that will display the information in meaningful way. For example, this snippet will count the number of days run within the last 30.
[php]
<?php
include (“../dbinfo.inc.php”);
/********************************/
/* Code from http://strombotne.com/
/* The query in this file is for PHP5 only
/* If you use this code, find a flaw, enhance or otherwise improve it then please let me know
/* via comment or link.
/********************************/
$con = @mysql_connect($databasehost,$databaseusername,$databasepassword) or die(mysql_error());
@mysql_select_db($databasename) or die(‘Could not connect: ‘ . mysql_error());

$dataArray=array();

//get data from database
$sql=”SELECT COUNT(*) AS Last30Days FROM $databasetable WHERE Activity = ‘run’ AND DATE_SUB(CURDATE(),INTERVAL 30 DAY) <= Start_Time”;
$result = mysql_query($sql) or die(‘Query failed: ‘ . mysql_error());
$event_count=mysql_fetch_object($result);
$event_count=$event_count->Last30Days;

// days run will be $count_events_data from 30 == days off
$days_off = 30 – $event_count;

@mysql_close($con);
?>
[/php]

Google has an API for charting that neatly displays the query output.
[php]

<img src=”http://chart.apis.google.com/chart?cht=p3&chs=375×125&chd=t:<?php echo $event_count.’,’.$days_off.’&chl=’.$event_count.’+Days+Run|Days+Off&chtt=Last+30+Days’;?>”>
<!– uses query_count_events_last_30.php –>

[/php]

And the output looks like this:




There are additional queries and charts in the zip file, along with the complete code for this project for download here. Please share a link to YOUR Runmeter Statistics display in the comments section.