Create a gist now

Instantly share code, notes, and snippets.

@RChloe / Secret
Created Dec 4, 2015

# Import libraries for parsing the JSON output by the Wio Link
# Also import the Initial State Python library so we can stream
# the Wio Link readings to a visualization
import urllib2
import json
import os
import glob
import time
from ISStreamer.Streamer import Streamer
#### Wio Link Information ####
# The access token for your Wio Link
WIO_ACCESS_TOKEN = "Wio_API_Access_Token_Here"
# The name of the attached sensor
SENSOR_NAME = "GroveIRDistanceInterrupterDigital2"
# The name of the signal the sensor produces
SIGNAL_NAME = ["approach"]
### Initial State Information ###
# The name your bucket will appear with in Initial State
BUCKET_NAME = ":seedling: Wio Python"
# The hidden bucket key that associates the data w/a particular bucket
BUCKET_KEY = "wiolink"
# Initial State access key - found under "Account"
IS_ACCESS_KEY = "Initial_State_Access_Key_Here"
# Time between sensor readings
# Function to fetch the JSON from a particular Wio API URL
def get_reading(sensor,signal):
api_reading_url = "" + sensor + "/" + signal + "?access_token=" + WIO_ACCESS_TOKEN
print api_reading_url
f = urllib2.urlopen(api_reading_url)
print "Failed to get " + signal
return False
json_reading =
return json.loads(json_reading)
# Initialize the Intial State streamer
streamer = Streamer(bucket_name=BUCKET_NAME, bucket_key=BUCKET_KEY, access_key=IS_ACCESS_KEY)
# Loop through reading and streaming signal's value
while True:
# Read motion value from IR Distance Interrupter
motionReading = get_reading(SENSOR_NAME,SIGNAL_NAME[0])
if (motionReading != False):
if (motionReading['status'] != 205):
motion = motionReading['msg']['approach']
if motion == 0:
print "No motion"
streamer.log("Motion?","No motion")
if motion == 1:
print "Motion detected"
streamer.log("Motion?","Motion detected")
message = motionReading['msg']
print message
# Wait designated time between readings
except TypeError:
print "Type Error"

This comment has been minimized.

Show comment
Hide comment

awong1900 Jan 26, 2016

The return json format have changed. Maybe need fix the code.

The return json format have changed. Maybe need fix the code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment