in telemetryThing.py [0:0]
def do_something():
# send current state to shadow
global state_dirty, message_count
if state_dirty:
tripSrc.useFileURI(state['file'])
iotConnection.updateShadow(state)
state_dirty = False
# assemble telemetry
telemetry = tripSrc.getSample()
# print(json.dumps(telemetry) + "\n")
if len(telemetry) == 0:
if state.get('at_end') == 'stop':
logger.info("end of file reached")
time.sleep(600) # wait 10 min for queued messages to clear
sys.exit()
return 30 # wait 30 seconds between runs
deviceid = state.get('deviceid', thingName)
timestamp_ms = getTimestampMS(telemetry)
payload = makePayload(telemetry)
topic = getTopicGenerator().make_topicname(deviceid=deviceid, timestamp_ms=timestamp_ms)
message_count += 1
logger.info(f"{message_count} - {topic}:{payload}")
sleep = [0, 1]
while not iotConnection.publishMessageOnTopic(payload, topic, qos=1):
logger.info("waiting to clear block")
# fibonacci backoff on wait
sleep.append(sum(sleep))
timeout = sleep.pop(0)
if timeout > 300:
logger.warn("timeout escalated to 30 sec -- re-connecting")
try:
iotConnection.disconnect()
time.sleep(10)
iotConnection.connect()
except Exception as e:
pass
sleep = [0, 1]
time.sleep(timeout/10.0)
# return the timestamp of the leg
return timestamp_ms/1000.0