for veh in selected_vehicles: veh.disconnect() except Exception: _LOG.exception('Exception while handling received MQTT message:') client.on_connect = on_conn client.on_message = on_msg for vehicle in config['anki']['vehicles']: veh = Overdrive(vehicle['mac']) client.publish('%s/%s/connected' % (topic_prefix, vehicle['name']), True, qos=2) veh.setLocationChangeCallback(loc_change_callback) veh.setTransitionCallback(transition_callback) veh.setPongCallback(pong_callback) vehicles[vehicle['name']] = veh veh.ping() try: client.connect(config["mqtt"]["host"], config["mqtt"]["port"], 60) except socket.error as err: _LOG.fatal("Unable to connect to MQTT server: %s" % err) sys.exit(1) client.loop_start() try: while True: sleep(1)
params['addr'] = addr print( 'Location from {addr} : Piece={piece} Location={location} Speed={speed} Clockwise={clockwise}' .format(**params)) car.setLocationChangeCallback(locationChangeCallback) def transitionChangeCallback(addr, params): params['addr'] = addr print('Transition from {addr} From={piecePrev} To={piece} Offset={offset}'. format(**params)) car.setTransitionCallback(transitionChangeCallback) car.changeSpeed(500, 800) while True: inpt = input( '[ to change lane to left, ] to change lane to right, enter to stop.\n' ) if inpt == '[': car.changeLaneLeft(500, 800) elif inpt == ']': car.changeLaneRight(500, 800) else: break car.changeSpeed(0, 800)