Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. ## OBD
  2.  
  3. def init_connection(baud_rate,com_port,fast):
  4. connection = obd.Async(com_port,baudrate=baud_rate, fast=fast)
  5. connection.watch(obd.commands.RPM, callback=new_rpm)
  6. connection.watch(obd.commands.SPEED, callback=new_speed)
  7. connection.watch(obd.commands.COOLANT_TEMP, callback=new_coolant_temperature)
  8. connection.watch(obd.commands.THROTTLE_POS, callback=new_throttle_position)
  9. connection.start()
  10. print("hello")
  11.  
  12. #RPM
  13. def new_rpm(r):
  14. rpmValue=r.value.magnitude
  15. rpm_flag=1
  16. obdjson["rpm"]=rpmValue
  17. #SPEED
  18. def new_speed(r):
  19. #client.publish(mqtt_topic, qos=0)
  20. speed_flag=1
  21. obdjson["speed"]=r.value.magnitude
  22. jstemp["telemetry_data"]=obdjson
  23. json_temp = json.dumps(jstemp)
  24. print(obdjson)
  25. client.publish(mqtt_topic, str(obdjson), qos=0)
  26.  
  27. #COOLANT TEMPERATURE
  28. def new_coolant_temperature(r):
  29. coolant_flag=1
  30. obdjson["coolant_temp"]=r.value.magnitude
  31. #Throttle position
  32. def new_throttle_position(r):
  33. throttle_flag=1
  34. obdjson["throttle_position"]=r.value.magnitude
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement