Created
December 1, 2017 00:56
-
-
Save refugeesus/37824ac7210e8af49740f0d28099c8d8 to your computer and use it in GitHub Desktop.
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
from helium_client import Helium | |
import json | |
helium = Helium("/dev/serial0") | |
helium.connect() | |
channel = helium.create_channel("aws_test") | |
# Access an instance of Configuration | |
config = channel.config() | |
# Get device state from cloud | |
state = config.get("channel.state") | |
config.set("channel.state", state) | |
while(1): | |
if state == True: | |
# sensor reading and processing code | |
# ........ | |
# Make a json payload to send OTA | |
payload = json.dumps({}) # Your dictionary key:value | |
json.loads(payload) | |
# Get the channel setting for interval_ms | |
interval = config.get("channel.interval_ms") | |
config.set("channel.interval_ms", interval) | |
# Get the channel setting for state | |
state = config.get("channel.state") | |
config.set("channel.state", state) | |
# Report the device having set interval_ms | |
channel.send(payload) | |
time.sleep(int(interval)) | |
else: | |
print("idle") | |
time.sleep(5) | |
state = config.get("channel.state") | |
config.set("channel.state", state) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment