Sensor Democracy

Hot on the heels of talking with my friend Kevin about training for data is a revelation by my new favorite fitness company Wahoo makers of fitness sensors, devices and apps.

One of the challenges for any geek who wants to go beyond commercial products for their fitness regimen is the need to understand all the complicated protocols of sensors, namely Bluetooth and ANT+.

I recently acquired a biking cadence and speed sensor to match my heart rate monitor and realized that the app has a hidden gem of a feature!

Under the User Profile settings is a featured called Air Broadcaster, which states it Broadcast[s] your data live over Wi-Fi!!!

It must not be well known within the company, because their support email had no idea what I was talking about, but I was lucky enough to stumble upon the developer via twitter who gave me some code, enough to figure out how it works!

There are two quick and easy ways to get access to this data, the first using our trusty friend netcat:

 nc -w0 -dulk 51530

You should see some data such as:

{"HeartrateInstant":0,"LapRunningTimeString":"01:36","CadenceInstantString":"0","HeartbeartBitmap":"GBg8PH5+////////f/4//B/4D/AH4APAAYAAAAAAAAA=","HeartrateInstantString":"0","SpeedInstant":0,"DeviceName":"<YOURPHONE_NAME>","Email":"","DistanceWorkout":0,"BikePowerInstant":0,"WorkoutRunningTimeString":"02:35","CadenceInstant":0,"WorkoutState":"Running"}

Note, this was me testing it from my couch and not engaged in any physical activity, so the only sensor it had was GPS.

The second using some simple python:

#!/usr/bin/python

import socket
import json

UDP_IP = "0.0.0.0"
UDP_PORT = 51530

sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # UDP
sock.bind((UDP_IP, UDP_PORT))

while True:
    data_str, addr = sock.recvfrom(1024) # buffer size is 1024 bytes
    data = json.loads(data_str)
    print addr, " -> ", data

 

    Why is this cool?

This means I can spend my time working with my data, not trying to recreate a sensor bridge!

I’ll still have to spend some time figuring out what HeartbeartBitmap represents, but that’s (hopefully) trivial to reverse engineering how to connect to the sensor and it’s own protocol.

Posted in uncategorized | 1 Comment

Mailing for Thinkup – Hacking a Solution without using Sendmail

I’ve been meaning to try Thinkup for a long time now, and finally got around to trying it out.

I also decided this was also a good time to try a RaspberryPi and so the system I ended up running it on was not as complete as a normal linux server, or commercially provided host.

After installing dependencies, I quickly got stymied when I did not get a confirmation email.

Apparently this isn’t unique:

http://thinkupapp.com/docs/troubleshoot/common/emaildisabled.html

Also, their guidance is that; “We strongly recommend running ThinkUp on a web server which can send email.”

Using GMail as my SMTP server seemed the obvious choice, but that was before I learned that PHP’s mail() function does not support authentication in any way.

Apparently the most popular solution I found on Google was to use PHPMailer and this required some hacking that I wanted to document here.

I’m not sure if all of these steps are necessary, but it worked for me (TM):

  1. sudo vi /etc/php5/cgi/php.ini
    Add the line extension=php_openssl.so
  2. Download PHPMailer and extract it into your thinkup _lib directory [for me this was /usr/share/nginx/www/thinkup/_lib]
  3. Hack /usr/share/nginx/www/thinkup/_lib/class.Mailer
    • Add the following to the beginning of the file [right after "<?php"]: "ini_set("include_path", ".:./PHPMailer_v5.1/");
      require("PHPMailer_v5.1/class.phpmailer.php");
      "
    • Find "} else { mail($to, $subject, $message, $mail_header);" and comment it out [with //]
    • then add:
      /** KLUDGE ADDED - START **/
      $mail = new PHPMailer();
      $mail->IsSMTP();
      // $mail->SMTPDebug = 2;
      $mail->SMTPAuth = true;
      $mail->SMTPSecure = "tls";
      $mail->Host = 'smtp.gmail.com';
      $mail->Port = 587;
      $mail->Username = "YOURNAME@gmail.com";
      $mail->Password = "YOURPASSWORD";
      $mail->SetFrom("YOURNAME@gmail.com", "thingkup_notifications");
      $mail->AddAddress($to);
      $mail->Subject = $subject;
      $mail->Body = $message;
      $mail->WordWrap = 50;
      if(!$mail->Send()) {
      echo 'Message was not sent.';
      echo 'Mailer error: ' . $mail->ErrorInfo;
      }
      else {
      echo 'Message has been sent.';
      }
      /** KLUDGE ADDED - END **/

I hope that helps someone, I can't say it's extensively tested (I wanted to blog it all before I forgot) but it worked in my example test script, which has to be close enough, right!

Posted in code, opensource | 17 Comments

Trying to run Processing on Mac

So this is just a quick post as a breadcrumb for anyone with similar problems.

I’ve been trying to run Processing (after a long hiatus) on my MacBook, and was having no luck.

It would throw an error message like the following:

Exception in thread "Thread-7" java.lang.Error: Unable to launch target VM: 

java.io.IOException: Cannot run program "java": error=2, No such file or directory
	at processing.mode.java.runner.Runner.launchVirtualMachine(Runner.java:317)
	at processing.mode.java.runner.Runner.launch(Runner.java:118)
	at processing.mode.java.JavaMode$1.run(JavaMode.java:181)
	at java.lang.Thread.run(Thread.java:680)

I’d remembered a java problem before on Mac / OSX, and thought it was Processing, but a friend tipped me off that it was actually an Arduino issue.

For better or worse, they use the same “ide” environment, so that lead me in the right direction towards; http://arduino.cc/en/Guide/Troubleshooting#toc2

What’s strange, is that that doesn’t seem to be an option any longer for the latest Arduino install.

However, so it is an option on the latest Processing… but it didn’t help…

But it clued me in on some ideas and ultimately this trick; "arch -i386 /Applications/Processing.app/Contents/MacOS/JavaApplicationStub"

Allows it to run, although with errors like:

Jul  9 00:18:28 loki java[1933] : CGContextGetCTM: invalid context 0x0
Jul  9 00:18:28 loki java[1933] : CGContextSetBaseCTM: invalid context 0x0
Jul  9 00:18:28 loki java[1933] : CGContextGetCTM: invalid context 0x0
Jul  9 00:18:28 loki java[1933] : CGContextSetBaseCTM: invalid context 0x0

It’s still better than nothing!

I suspect it’s related to using Apple’s version of Java. I had allowed Apple to remove whatever version I had installed, since I hadn’t using Processing/Arduino, so when it needed java again I let it install the default.

It pains me to say it, but I may have to try Oracle’s version tomorrow….

Posted in frustration | 17 Comments

A Digital Revolution

As an exercise in citizen participation in Government I developed a Digital Government Tracker.

At a pivotal time in history, a famous man once said: “Four score and seven years ago our fathers brought forth on this continent, a new nation, conceived in Liberty, and dedicated to the proposition that all men are created equal.” – Gettysburg Address

It’s been almost 150 years since those words were first spoken, but the sentiment remains; a Nation, founded on principles and great expectations must continue to uphold those values, despite great change and through great turmoil.

Certainly no founding father, or citizen, could imagine all the challenges a Nation would face, and the strength of our Government is that “it can always be changed … the beauty of the Constitution is that it makes no set law other than faith in the wisdom of ordinary people to govern themselves.”1

This philosophy, and mandate for constant reaffirmation and reinvention, has never been truer than in the digital age we live in now.

I couldn’t state the case any better than to quote two other great characters in history;

  • “In 2011, global smartphone shipments exceeded personal computer shipments for the first time in history, and more Americans will soon access the Internet via mobile devices than desktop PCs.”2
  • and ultimately that the “innovative use of technology is fundamentally transforming how the American people do business and live their daily lives.”3

The new U.S. Digital Governmental Strategy attempts to outline how agencies can safely embrace this latest challenge, among the many that technology constantly brings.

Throughout this strategy, and activities such as the Open Government Initiative, I believe there are two overarching implications, beyond the obvious technical considerations:

  1. Citizens matter – Leaders in the ‘civic hacking’ community such as Jennifer Pahlka, Sunlight Labs, reporters such as Alex Howard, leaders like Todd Park, and many others have shown us that innovations and expectations outside government, can be pushed/pulled into the realm of agencies.
  2. Evidence-based impact – Never before has there been such an opportunity to illustrate the correlation between cost and value in our Government’s budget (pdf). Technology provides empirical data like nothing else and, given some of the high profile successes and failures in Federal IT, I think technology can link the cost of doing business with the civic value citizens expect and deserve (think SLA’s for Federal services).

Certainly there are are some high profile efforts to engage citizens in these activities, but when the WhiteHouse github account has only 2 followers (as of 6/2/2012) I can’t help but feel like the evidence for change is still unfolding.

Rather than being daunted by the circumstances, I decided to be inspired by these ‘digital government heroes’. I’m sure we’ll never be a country where developers get a nanoKardishian of attention, or receive the star treatment Europe bestows on board-game designers.

However, there is an important transformation looming, for geeks not just government. So I decided to create a personal project to, quite literally, codify some of my experiences and I’ve made it open source, to pay a small debt of gratitude to some of the geeks in government.

This Digital Government Tracker highlights, and tracks progress on, two elements of the Digital Government Strategy and the accompanying Presidential Memorandum.

Specifically the requirements for every agency to establish:

One of the interesting lessons I learned through this exercise, was that agencies are required to create two websites!

Although I have not participated in the creation of these policies, I have been involved as an analyst and advocate for government transformation, and my experience suggests that most participants assumed there was only URL.

I think this is a great example of how making dialogues tangible, through technology, reduces ambiguity and improves the results.

This site owes much to the SunlightLabs and the /Open Watcher site. NIST also has an excellent IPv6 and DNSSEC Deployment Monitor that may be a relative first in tracking success through empirical evidence based assessment. Perhaps The Government Accountability Office could partner with The Office of Management and Budget to developed these techniques, making process of government, not just its citizen services, more efficient and effective.

“I want us to ask ourselves every day, how are we using technology to make a real difference in people’s lives.”4 – President Barack Obama

I hope in some small way this manages to help.

Posted in code, inspiration, opengov, opensource, social | Comments Off

Postgresql Mac Installation

Just a quick note for Thanksgiving.

I’m doing some experimentation and thought, given my frustrations with Sun and Oracle that I’d check out PostgreSQL instead of mysql (my typical DB of choice).

Unfortunately, the Mac installer threw some issues, stating:

“The database cluster initialization failed.”

If you’re interested you can check out:

sudo less /tmp/bitrock_installer.log

And at the end you’ll probably see a failure such as:

“su: no directory”

I tried running the command manually, but got the same error and realized that’s because I set my user to “postgres” but that user doesn’t exist.

The installer tells you it will create the user, but apparently doesn’t. So if you run the initcluster.sh script as your normal user (or set the installer to use a user that exists) you should be ok.

Happy Turkey Day and hope that helps someone!!

Posted in frustration | 1 Comment