Demo application for using the AT&T IoT Starter Kit Powered by AWS.
Dependencies: SDFileSystem
Fork of ATT_AWS_IoT_demo by
IoT Starter Kit Powered by AWS Demo
This program demonstrates the AT&T IoT Starter Kit sending data directly into AWS IoT. It's explained and used in the Getting Started with the IoT Starter Kit Powered by AWS on starterkit.att.com.
What's required
- AT&T IoT LTE Add-on (also known as the Cellular Shield)
- NXP K64F - for programming
- microSD card - used to store your AWS security credentials
- AWS account
- Python, locally installed
If you don't already have an IoT Starter Kit, you can purchase a kit here. The IoT Starter Kit Powered by AWS includes the LTE cellular shield, K64F, and a microSD card.
Diff: PythonGUI/ATT_AWS_IoT_Demo_GUI.py
- Revision:
- 20:ee34856ae510
- Parent:
- 19:488dad1e168e
- Child:
- 25:91d771247ac8
--- a/PythonGUI/ATT_AWS_IoT_Demo_GUI.py Tue Dec 06 22:45:00 2016 +0000 +++ b/PythonGUI/ATT_AWS_IoT_Demo_GUI.py Wed Dec 07 20:37:20 2016 +0000 @@ -40,20 +40,43 @@ window = Tkinter.Tk() window.wm_title("AT&T AWS IoT Demo") +# Setup frames topframe = Frame(window) -topframe.pack() +topframe.pack(fill=X, side = TOP) +frameR1 = Frame(window) +frameR1.pack(fill=X, side = TOP) +frameR2 = Frame(window) +frameR2.pack(fill=X, side = TOP) +frameR3 = Frame(window) +frameR3.pack(fill=X, side = TOP) bottomframe = Frame(window) -bottomframe.pack( side = BOTTOM ) +bottomframe.pack(fill=X, side = BOTTOM) -statusLabel = StringVar() -statusString = StringVar() +# Label vars (controls shown text) +ledStaticLabelTxt = StringVar() +ledStatusLabelTxt = StringVar() +tempStaticLabelTxt = StringVar() +tempStatusLabelTxt = StringVar() +humidStaticLabelTxt = StringVar() +humidStatusLabelTxt = StringVar() +versionStaticLabelTxt = StringVar() +versionStatusLabelTxt = StringVar() +versionLastValue = -1 # Control callbacks -def setStatus(statusStr): - if(statusString == statusStr): - statusString.set("unknown") +def setStatus(ledStatus, tempStatus, humidStatus, version): + global versionLastValue + + ledStatusLabelTxt.set(ledStatus) + tempStatusLabelTxt.set(str(tempStatus) + " (F)") + humidStatusLabelTxt.set(str(humidStatus) + " %") + + isStale = "" + if (versionLastValue == version): + isStale = " (stale)" else: - statusString.set(statusStr) + versionLastValue = version + versionStatusLabelTxt.set(str(version) + isStale) def offButtonCallBack(): sendLEDRequest("0") @@ -71,11 +94,25 @@ sendLEDRequest("7") # Create our Labels -StaticLabel = Label(topframe, textvariable=statusLabel, relief=FLAT) -statusLabel.set("AWS Reported LED Status: ") +ledStaticLabel = Label(topframe, textvariable=ledStaticLabelTxt, anchor=W, relief=FLAT) +ledStaticLabelTxt.set("Reported LED Status: ") +ledStatusLabel = Label(topframe, textvariable=ledStatusLabelTxt, anchor=W, relief=FLAT) +ledStatusLabelTxt.set("unknown (needs to sync)") + +tempStaticLabel = Label(frameR1, textvariable=tempStaticLabelTxt, anchor=W, relief=FLAT) +tempStaticLabelTxt.set("Reported Temperature: ") +tempStatusLabel = Label(frameR1, textvariable=tempStatusLabelTxt, anchor=W, relief=FLAT) +tempStatusLabelTxt.set("unknown (needs to sync)") -StatusLabel = Label(topframe, textvariable=statusString, relief=FLAT) -statusString.set("unknown (needs to sync)") +humidStaticLabel = Label(frameR2, textvariable=humidStaticLabelTxt, anchor=W, relief=FLAT) +humidStaticLabelTxt.set("Reported Humidity: ") +humidStatusLabel = Label(frameR2, textvariable=humidStatusLabelTxt, anchor=W, relief=FLAT) +humidStatusLabelTxt.set("unknown (needs to sync)") + +versionStaticLabel = Label(frameR3, textvariable=versionStaticLabelTxt, anchor=W, relief=FLAT) +versionStaticLabelTxt.set("IoT Shadow Version: ") +versionStatusLabel = Label(frameR3, textvariable=versionStatusLabelTxt, anchor=W, relief=FLAT) +versionStatusLabelTxt.set("unknown (needs to sync)") # Create our Buttons O = Tkinter.Button(bottomframe, text ="Off", fg="gray", bg="black", command = offButtonCallBack) @@ -93,8 +130,14 @@ W['font'] = font # Arrange our controls -StaticLabel.pack(side = LEFT) -StatusLabel.pack(side = LEFT) +ledStaticLabel.pack(side = LEFT) +ledStatusLabel.pack(side = LEFT) +tempStaticLabel.pack(side = LEFT) +tempStatusLabel.pack(side = LEFT) +humidStaticLabel.pack(side = LEFT) +humidStatusLabel.pack(side = LEFT) +versionStaticLabel.pack(side = LEFT) +versionStatusLabel.pack(side = LEFT) O.pack(side = LEFT) R.pack(side = LEFT) G.pack(side = LEFT) @@ -107,20 +150,26 @@ # ####################################################################################################################### # Shadow JSON schema: -# -# Name: Bot -# { -# "state": { -# "desired":{ -# "ledColor":<INT VALUE> -# } -# } -#} +''' +Name: AIT (AWS IoT Thing) +{ + "state": { + "desired": { + "ledColor": <UINT8> + }, + "reported": { + "ledColor": <UINT8>, + "temperature": <FLOAT>, + "humidity": <INT16> + } + } +} +''' def sendLEDRequest(color_input): if (color_input in accepted): JSONPayload = '{"state":{"desired":{"ledColor":' + str(color_input) + '}}}' - Bot.shadowUpdate(JSONPayload, customShadowCallback_Update, 5) + AIT.shadowUpdate(JSONPayload, customShadowCallback_Update, 5) else: print("WARN: Color input invalid - " + color_input) @@ -165,18 +214,23 @@ print(responseStatus) payloadDict = json.loads(payload) reportedColor = payloadDict["state"]["reported"]["ledColor"] + reportedTemp = payloadDict["state"]["reported"]["temperature"] + reportedHumid = payloadDict["state"]["reported"]["humidity"] + reportedVersion = payloadDict["version"] print("++++++++GET++++++++++") - print("ledColor: " + str(reportedColor) + " (" + colorDict[reportedColor] + ")") - print("version: " + str(payloadDict["version"])) + print("ledColor : " + str(reportedColor) + " (" + colorDict[reportedColor] + ")") + print("temperature: " + str(reportedTemp)) + print("humidity : " + str(reportedHumid)) + print("version: " + str(reportedVersion)) print("+++++++++++++++++++++\n\n") # Send payload to our status - setStatus(colorDict[reportedColor]) + setStatus(colorDict[reportedColor], reportedTemp, reportedHumid, reportedVersion) getTimerAlive = TRUE def customShadowTimer_Get(): while (getTimerAlive): - Bot.shadowGet(customShadowCallback_Get, 5) + AIT.shadowGet(customShadowCallback_Get, 5) time.sleep(3) ####################################################################################################################### @@ -363,13 +417,13 @@ myAWSIoTMQTTShadowClient.connect() # Create a deviceShadow with persistent subscription -Bot = myAWSIoTMQTTShadowClient.createShadowHandlerWithName(AWS_IOT_MY_THING_NAME, True) +AIT = myAWSIoTMQTTShadowClient.createShadowHandlerWithName(AWS_IOT_MY_THING_NAME, True) # Listen on deltas -Bot.shadowRegisterDeltaCallback(customShadowCallback_Delta) +AIT.shadowRegisterDeltaCallback(customShadowCallback_Delta) # Delete shadow JSON doc -#Bot.shadowDelete(customShadowCallback_Delete, 5) +#AIT.shadowDelete(customShadowCallback_Delete, 5) getTimer = Timer(3.0, customShadowTimer_Get, ()) getTimer.start()