Created
January 15, 2016 05:46
-
-
Save mindcruzer/bb10aac2bf654fb24ffe to your computer and use it in GitHub Desktop.
Polling script for displaying AWS IoT thing temperature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- 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