'How to enable Bluetooth in kivy(python framework) android app
I built an android app using kivy and buildozer. It is similar to obd2 apps like torque. I want to connect my app to car through Bluetooth to get live car engine data and diagnostic trouble codes. I am using python-OBD api (https://python-obd.readthedocs.io/en/latest/). When I click on GET RPM I get none because no connection to car

I am able to connect in local computer through virtual elm emulator(https://github.com/Ircama/ELM327-emulator).
in virtual machine(ubuntu)
in one terminal I am running emulator(and I mention port number connection = obd.OBD("/dev/pts/2")
in another terminal I am running my code.
I am getting rpm responses when I click on GET RPM button every time

(But how to get in android app)
source code
import obd
import kivy
from cgitb import text
from kivy.app import App
from kivy.uix.gridlayout import GridLayout
from kivy.uix.label import Label
from kivy.uix.button import Button
from kivy.uix.textinput import TextInput
connection = obd.OBD("/dev/pts/2")
# print(connection.query(obd.commands.RPM))
class obdApp(App):
def build(self):
self.window = GridLayout()
#add widgets to window
self.window.cols = 1
# style
self.window.size_hint = (0.6, 0.7)
self.window.pos_hint = {"center_x": 0.5, "center_y": 0.6}
#self.window.size_hint_y = None
self.greeting = Label(
text = "command lookup",
font_size = 24,
color = 'red'
)
self.window.add_widget(self.greeting)
self.button = Button(text = "GET RPM")
self.button.bind(on_press = self.callbackrpm)
self.window.add_widget(self.button)
self.button = Button(text = "GET SPEED")
self.button.bind(on_press = self.callbackspeed)
self.window.add_widget(self.button)
self.button = Button(text = "GET FUEL_TYPE")
self.button.bind(on_press = self.callbackfuel)
self.window.add_widget(self.button)
return self.window
def callbackrpm(self, instance):
self.greeting.text = str(connection.query(obd.commands.RPM))
def callbackspeed(self, instance):
self.greeting.text = str(connection.query(obd.commands.SPEED))
def callbackfuel(self, instance):
self.greeting.text = str(connection.query(obd.commands.FUEL_TYPE))
if __name__ == "__main__":
obdApp().run()
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
