Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## OBD
- def init_connection(baud_rate,com_port,fast):
- connection = obd.Async(com_port,baudrate=baud_rate, fast=fast)
- connection.watch(obd.commands.RPM, callback=new_rpm)
- connection.watch(obd.commands.SPEED, callback=new_speed)
- connection.watch(obd.commands.COOLANT_TEMP, callback=new_coolant_temperature)
- connection.watch(obd.commands.THROTTLE_POS, callback=new_throttle_position)
- connection.start()
- print("hello")
- #RPM
- def new_rpm(r):
- rpmValue=r.value.magnitude
- rpm_flag=1
- obdjson["rpm"]=rpmValue
- #SPEED
- def new_speed(r):
- #client.publish(mqtt_topic, qos=0)
- speed_flag=1
- obdjson["speed"]=r.value.magnitude
- jstemp["telemetry_data"]=obdjson
- json_temp = json.dumps(jstemp)
- print(obdjson)
- client.publish(mqtt_topic, str(obdjson), qos=0)
- #COOLANT TEMPERATURE
- def new_coolant_temperature(r):
- coolant_flag=1
- obdjson["coolant_temp"]=r.value.magnitude
- #Throttle position
- def new_throttle_position(r):
- throttle_flag=1
- obdjson["throttle_position"]=r.value.magnitude
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement