简体   繁体   English

如何使用Android App自动连接到Arduino?

[英]How to Auto-Connect to Arduino with Android App?

I am currently working on an android application that blocks texting while driving. 我目前正在开发一个在行驶时阻止发短信的android应用程序。 It connects through Bluetooth to an Arduino Bluno that is connected to a car via the OBD-II port and scans for data received from a car (either 0 for a non-drive state or 1 if the car is going above 0 mph ie driving) and blocks texting if the car is in a drive state. 它通过蓝牙连接到Arduino Bluno,该Arduino Bluno通过OBD-II端口连接到汽车,并扫描从汽车接收的数据(非驱动状态为0,如果汽车以高于0 mph的速度行驶,则为1)。并在汽车处于行驶状态时阻止发短信。

What I would like to do is have the app/phone automatically connect to the Arduino once I enter the car with the phone and start driving. 我想做的是,一旦我用手机进入汽车并开始驾驶,应用程序/手机就会自动连接到Arduino。 I am not familiar with how to do so, if I need to use the native Android Bluetooth connection data to scan for the hardware or if there is some other approach. 如果我需要使用本机Android蓝牙连接数据来扫描硬件或是否有其他方法,我不熟悉该如何做。 Can I get some guidance as to how I can auto-connect? 我可以获取有关如何自动连接的一些指导吗?

Once the device is paired you can initialize the communication with your app or Arduino at any point. 设备配对后,您可以随时与应用或Arduino初始化通信。

So in your case I believe the best way would be to let the arduino initialize the communication with the app once you detect the car starts driving. 因此,就您的情况而言,我认为最好的方法是,一旦检测到汽车开始行驶,就让arduino初始化与应用程序的通信。 The phone would have no idea when that happens according to the setup you described above. 根据您上述的设置,电话什么时候都不知道。

To get an idea of how to use Bluetooth in your app (as always) you should have a look at the Android developer website. 要了解如何(一如既往)在您的应用程序中使用蓝牙,您应该查看Android开发人员网站。

Here are some links to get you started: 以下是一些帮助您入门的链接:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM