in lambdas/simulation/pushVehiclePosition/index.py [0:0]
def publish_location(trip_id, device_id, position):
logger.info("Publishing device: " + str(device_id) + " at lng:" + str(position[0]) + " lat:" + str(position[1]))
retries = 0
message = json.dumps(
{
"timestamp": datetime.now().isoformat(),
"trip_id": trip_id,
"device_id": device_id,
"latitude": float(position[1]),
"longitude": float(position[0])
}
)
try:
iot.publish(
topic=iot_topic,
qos=0,
payload=message
)
except iot.exceptions.InternalFailureException as e:
logger.error("Location InternalFailureException function error: " + str(e))
except iot.exceptions.InvalidRequestException as e:
logger.error("Location InvalidRequestException function error: " + str(e))
except iot.exceptions.UnauthorizedException as e:
logger.error("Location UnauthorizedException function error: " + str(e))
except iot.exceptions.MethodNotAllowedException as e:
logger.error("Location MethodNotAllowedException function error: " + str(e))
except Exception as e:
logger.error(str(e))