Category: Uncategorized

Setting up a commuters dashboard: Part 1 – Collecting freeway traffic

Elastic stack see here

Python traffic collector

Set the stage for the rest of the script. Importing everything necessary to pull traffic via googlemaps API and log results to a file

import googlemaps
 from datetime import datetime
 import os, json
 import logging, sys,time, yaml

logger = logging.getLogger('maps')
 fh = logging.FileHandler('/var/log/maps.log')
 # create console handler with a higher log level
 ch = logging.StreamHandler(sys.stdout)
 # create formatter and add it to the handlers
 formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
 # add the handlers to the logger


To keep the keys outside the code, I used a yaml file to reference the my simple config. Depending on the use case and other implementations, system environmental variables or other configurations could be used here.

def getKey():

GKEY = yaml.load(yaml_file)['gkey']

return GKEY
 except Exception as stderr:


The brain of the script is calculating the duration from point A to point B. This is done with googles gmaps API by using geocoded locations and making a call for directions. Part of the response is the duration in traffic. The logger object allows us to log to a file while seeing it in the terminal. This can eventually be fed into an S3 bucket for long term retention, and followed in real time for live interactions

def duration(geocoded_a, geocoded_b):
 now =
 geolat_a = json.dumps(geocoded_a[0]['geometry']['location']['lat'])
 geolon_a = json.dumps(geocoded_a[0]['geometry']['location']['lng'])

geolat_b = json.dumps(geocoded_b[0]['geometry']['location']['lat'])
 geolon_b = json.dumps(geocoded_b[0]['geometry']['location']['lng'])

loc_a = json.dumps(geocoded_a[0]['formatted_address'])
 loc_b = json.dumps(geocoded_b[0]['formatted_address'])

directions_result = gmaps.directions('{},{}'.format(geolat_a,geolon_a),

 duration_traffic=json.dumps(directions_result[0]['legs'][0]['duration_in_traffic']['value'])'{a} - {b} - {duration} - {duration_traffic}'.format(a=loc_a, b=loc_b, duration=duration, duration_traffic=duration_traffic))


The calls are made forever, sleeping every 10 minute to avoid running out of API calls. The traffic doesn’t update more frequently, so this is an acceptable refresh rate.

 gmaps = googlemaps.Client(key=GKEY)

geocoded_a = gmaps.geocode(LOCATION_A)
 geocoded_b = gmaps.geocode(LOCATION_B)

while True:
 duration(geocoded_a, geocoded_b)
 duration(geocoded_b, geocoded_a)
 except Exception as stderr:



com0com to simulate COM Port data

Com0Com can bridge two COM ports within a single windows machine.

A project I am working on opens a COM port and waits for data from a micro controller. I am working on windows application first and will build the hardware later. It costs virtually nothing during this stage of design which is a pro, but verifying functionality is tricky without any hardware to talk to. This is where Com0Com comes in.

I use Com0Com to bridge two ports on the windows machine. The application I am working on opens Com2. In the completed design, Com2 would be the link for the application to talk to the hardware micro controller. Since Hardware is not yet available, Com4 is bridged to Com2. With this, I can open up a terminal on Com4 to talk to the application on Com2. In my case, ill use putty to put the same data the micro controller will spitting out in the future. Now the application has something to talk to!

USB Breakout

Created this board to use as a simple tool for analyzing what is going through the USB cable. It plugs inline of a usb host device and the device to be tested.

All signals are normally open with pin headers attached to allow signal probing, current/voltage metering, rerouting, etc. Headers also allow other boards to be attached, making it easier to attach other monitoring tools.

Schematic design
Schematic design
PCB design
PCB design
Finally, the printed product. Note USB Male is not populated, but Micro usb works fine.
Finally, the printed product. Note USB Male is not populated, but Micro usb works fine.