Skip to content

Instantly share code, notes, and snippets.

@mindcruzer
Created January 15, 2016 05:46
Show Gist options
  • Save mindcruzer/bb10aac2bf654fb24ffe to your computer and use it in GitHub Desktop.
Save mindcruzer/bb10aac2bf654fb24ffe to your computer and use it in GitHub Desktop.
Polling script for displaying AWS IoT thing temperature
# -*- coding: utf-8 -*-
import json
import time
import os
from boto3.session import Session
session = Session(aws_access_key_id='<access key>',
aws_secret_access_key='<secret key>',
region_name='<region>')
iot = session.client('iot-data')
def get_temperature():
response = iot.get_thing_shadow(thingName='myThing')
json_string = b''
for chunk in iter(lambda: response['payload'].read(8192), b''):
json_string += chunk
data = json.loads(json_string.decode('utf-8'))
return float(data['state']['reported']['temperature'])
while True:
print "Updating..."
temp = get_temperature()
os.system('clear')
print "My Thing Temperature"
print "----------------------"
print u"{:.2f} °C".format(temp)
time.sleep(10)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment