Skip to content

Instantly share code, notes, and snippets.

@avirup171
Created October 5, 2019 06:35
Show Gist options
  • Save avirup171/3846e1e435da003e9e519457dab1bfdd to your computer and use it in GitHub Desktop.
Save avirup171/3846e1e435da003e9e519457dab1bfdd to your computer and use it in GitHub Desktop.
## 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment