Last active
October 19, 2019 02:57
-
-
Save bjyurkovich/9a26fcc97cb3afac70ceb346aa98ba07 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 time import time, sleep | |
| from iotery_embedded_python_sdk import Iotery | |
| import os | |
| # Need to specify the Iotery Team ID (I found this on the system page: https://iotery.io/system) | |
| TEAM_ID = os.getenv("IOTERY_TEAM_ID") | |
| # Instantiate the Iotery Connector object | |
| light_connector = Iotery() | |
| auth_data = { | |
| "key": "FRED_THE_LIGHT", | |
| "serial": "FRED_THE_LIGHT", | |
| "secret": "FRED_THE_LIGHT_SECRET", | |
| "teamUuid": TEAM_ID | |
| } | |
| # Get a JWT token from Iotery to be used in subsequent calls | |
| light_auth = light_connector.getDeviceTokenBasic(data=auth_data) | |
| # Set the token | |
| light_connector.set_token(light_auth["token"]) | |
| # Get info about Fred | |
| fred = light_connector.getMe() | |
| light_is_on = True | |
| while True: | |
| timestamp = int(time()) | |
| if light_is_on: | |
| print("I am shining brightly!") | |
| else: | |
| print("I am off.") | |
| # Data to send to Iotery | |
| data = { | |
| "packets": [{ | |
| "timestamp": timestamp, | |
| "deviceUuid": fred["uuid"], | |
| "data":{ | |
| "light_state": 1 if light_is_on else 0 | |
| } | |
| }] | |
| } | |
| # Report to Iotery | |
| response = light_connector.postData( | |
| deviceUuid=fred["uuid"], data=data) | |
| # Sleep for 1 second | |
| sleep(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment