![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Catie fork
Dependencies: SDFileSystem X_NUCLEO_IKS01A1
Fork of ATT_AWS_IoT_demo by
Diff: PythonGUI/ATT_AWS_IoT_Demo_GUI.py
- Revision:
- 19:488dad1e168e
- Parent:
- 17:46780b2de3e4
- Child:
- 20:ee34856ae510
diff -r 6370da1de572 -r 488dad1e168e PythonGUI/ATT_AWS_IoT_Demo_GUI.py --- a/PythonGUI/ATT_AWS_IoT_Demo_GUI.py Tue Dec 06 22:31:15 2016 +0000 +++ b/PythonGUI/ATT_AWS_IoT_Demo_GUI.py Tue Dec 06 22:45:00 2016 +0000 @@ -21,6 +21,7 @@ import logging import time import json +import re import getopt import Tkinter import tkFont @@ -134,9 +135,6 @@ print("version: " + str(payloadDict["version"])) print("+++++++++++++++++++++++\n\n") - # Send payload to our status - setStatus(colorDict[payloadDict["state"]["ledColor"]]) - # Custom Shadow callback def customShadowCallback_Update(payload, responseStatus, token): # payload is a JSON string ready to be parsed using json.loads(...) @@ -221,19 +219,22 @@ # AWS IoT Config Parameters. The user needs to enter these (they should match the parameters in aws_iot_config.h) # ####################################################################################################################### -useWebsocket = False -# TODO Move params to aws_iot_config.txt -AWS_IOT_MQTT_HOST = "a3sptpklzib7sa.iot.us-west-2.amazonaws.com" +useWebsocket = False # The FRDM-K64F demo isn't designed to work with web socket +hardCodeMQTT = False # Set this to true if you want to hard code the MQTT params below + +# AWS parameters +AWS_IOT_MQTT_HOST = "TODO" AWS_IOT_MQTT_PORT = 8883 -AWS_IOT_MQTT_CLIENT_ID = "EesFRDM" -AWS_IOT_MY_THING_NAME = "EesFRDM" +AWS_IOT_MQTT_CLIENT_ID = "TODO" +AWS_IOT_MY_THING_NAME = "TODO" +AWS_MQTT_CONFIG_FILENAME = "C:/Temp/certs/mqtt_config.txt" AWS_IOT_ROOT_CA_FILENAME = "C:/Temp/certs/rootCA-certificate.crt" AWS_IOT_PRIVATE_KEY_FILENAME = "C:/Temp/certs/private.pem.key" AWS_IOT_CERTIFICATE_FILENAME = "C:/Temp/certs/certificate.pem.crt" ####################################################################################################################### # -# Arg Parser +# Arg Parser (TODO) # ####################################################################################################################### ''' @@ -291,7 +292,47 @@ # Main Code # ####################################################################################################################### -# Makes sure files exist +# This block parses the MQTT file. +''' Example format for mqtt_config.txt: +AWS_IOT_MQTT_HOST=1234asdf.iot.us-west-2.amazonaws.com +AWS_IOT_MQTT_PORT=8883 +AWS_IOT_MQTT_CLIENT_ID=MyThingName +WS_IOT_MY_THING_NAME=MyThingName +''' + +if (not hardCodeMQTT): + if not os.path.exists(AWS_MQTT_CONFIG_FILENAME): + print "ERROR: MQTT Config file not found, " + AWS_MQTT_CONFIG_FILENAME + exit(1) + + mqtt_file = open(AWS_MQTT_CONFIG_FILENAME) + mqtt_tokens = re.split('=|\n', mqtt_file.read()) + print mqtt_tokens + + if (len(mqtt_tokens) != 8): + print "ERROR: Detected incorrect MQTT file format" + exit(1) + + index = 0 + for token in mqtt_tokens: + if (token == "AWS_IOT_MQTT_HOST"): + AWS_IOT_MQTT_HOST = mqtt_tokens[index+1] + if (token == "AWS_IOT_MQTT_PORT"): + AWS_IOT_MQTT_PORT = int(mqtt_tokens[index + 1]) + if (token == "AWS_IOT_MQTT_CLIENT_ID"): + AWS_IOT_MQTT_CLIENT_ID = mqtt_tokens[index + 1] + if (token == "AWS_IOT_MY_THING_NAME"): + AWS_IOT_MY_THING_NAME = mqtt_tokens[index+1] + + index += 1 + + print "MQTT Params:" + print "AWS_IOT_MQTT_HOST = " + AWS_IOT_MQTT_HOST + print "AWS_IOT_MQTT_PORT = " + str(AWS_IOT_MQTT_PORT) + print "AWS_IOT_MQTT_CLIENT_ID = " + AWS_IOT_MQTT_CLIENT_ID + print "AWS_IOT_MY_THING_NAME = " + AWS_IOT_MY_THING_NAME + +# Makes sure cert/key files exist if not os.path.exists(AWS_IOT_ROOT_CA_FILENAME): print "ERROR: Root CA file not found, " + AWS_IOT_ROOT_CA_FILENAME exit(1) @@ -338,4 +379,4 @@ # Kill our timer after the GUI closes getTimerAlive = FALSE -getTimer.cancel() +getTimer.cancel() \ No newline at end of file