def publishRaceTimes(hexUID, name, completionTime):
try:
# setup the log manager
myLog = logManager.logManager("main.py", "./log/")
myLog.disableFileOutput()
myLog.enableConsolePrint()
# setup the mqttCore variable
myPythonMQTTCore = mqttCore.mqttCore("rfid-aws", True, mqtt.MQTTv311, myLog)
myPythonMQTTCore.setConnectDisconnectTimeoutSecond(90)
myPythonMQTTCore.setMQTTOperationTimeoutSecond(10)
myPythonMQTTCore.config(thingHost, 8883, rootCA[0], privateKey[0], certificate[0])
# connect to the IoT service
myPythonMQTTCore.connect()
# get the current date and time and set the publish payload
now = datetime.datetime.now(pytz.timezone(timezone)).strftime('%Y-%m-%dT%H:%M:%S.%f%z')
payload = json.dumps({'uid' : hexUID, 'name' : name, 'raceTime' : completionTime, 'createdDateTime' : now })
# publish to the topic
myPythonMQTTCore.publish(publishTopic, payload, 0, False)
# disconnect from the IoT service
myPythonMQTTCore.disconnect()
# display a success message
displayPublishSuccess()
except AWSIoTExceptions.publishTimeoutException:
print "Syncing reported data: A Publish Timeout Exception happened."
except AWSIoTExceptions.publishError:
print "Syncing reported data: A Publish Error happened."
except Exception as e:
print e
# Function to display a success message to the user
# after the race time is published to the AWS IoT service.
评论列表
文章目录