I have worked since last day on this topic. I want to develop android application about obd-ii scanner. There are many open source project on Github or Google Codes. I have to find obd-ii simulator to developed this application without car or any odb-ii chip.
I found OBDSim to create sample data and answer the requests that send by my application. I encountered many problems and solved these problems by reading many documents and blog post. But I have last one problem and I need to your helps.
New version of OBDsim support Windows for Bluetooth connection now with using com0com. When I install com0com, I faced signature problem and I solved this problem to disable related windows feature. I have also set incoming port of Bluetooth to COM4. Everything are good so far. After that I want to create virtual ports by using com0com. It already create one pair when install. They are CNCA0 and CNCB0. I am only trying to change second port of this pair from CNCB0 to COM4. But windows gives error about COM4 is already using. Still I completed and assign COM4 instead of CNCB0. After that I run obdsim.exe and it start to create log like this;
SimPort name: CNCA0
Successfully initialised obdsim, entering main loop
10.046624 seconds. 0 samples, 0 queries. 0.00 s/s, 0.00 q/s
10.049810 seconds. 0 samples, 0 queries. 0.00 s/s, 0.00 q/s
10.049377 seconds. 0 samples, 0 queries. 0.00 s/s, 0.00 q/s
In this duration, I started to android application and press start live data button. I give and error on android phone about Bluetooth Connection Error - read failed, socket might closed or timeout. This is one scenario.
In second scenario, I removed the break com0com and I directly connect OBDsim to COM4. And I run obdsim.exe again. It also hava same output as before scenario. After I started t android application output change like this.
Echo disabled
Echo disabled
Echo disabled
10.066543 seconds. 0 samples, 6 queries. 0.00 s/s, 0.60 q/s
Echo disabled
Echo disabled
Echo disabled
Echo disabled
Echo disabled
10.030909 seconds. 0 samples, 5 queries. 0.00 s/s, 0.50 q/s
Echo disabled
Echo disabled
Echo disabled
Echo disabled
Echo disabled
Echo disabled
10.034040 seconds. 0 samples, 6 queries. 0.00 s/s, 0.60 q/s
Echo disabled
Echo disabled
Echo disabled
And I cant see any changes on my application.
If you know what is the problem or something that I made mistake or I forget, I am waiting or your help.
Thanks.
Okey. I solved my problem about this topic.
First of all, com0com is not necessary to communicate with OBDSim on Windows.
I can successfully connect to my application and OBDSim and I can see values on my android phone screen.
My problem was about OBD Reader program on Android. I didn't understand the reason of this situation but OBDSim couldn't connect to all OBD readers. I suggest you to use torque lite android application when you try connect OBDSim. And you should be careful on order of process.
Firstly, you should make pair your computer and mobile phone. (Sometimes it is necessary to remove pair and make pair again.)
After that you should run > obdsim.exe -w COMx (x is your Bluetooth income port name. You can set this port on your PC's Bluetooth settings -> Com Ports)
Lastly you should open your application and try to connect your computer by Bluetooth.
This solution works for me. You can try other application.
Thanks,
M. Salih.
Related
I'm developing an adaptation for an android app, to communicate with a remote control, which has some pre defined commands.
I've followed this implementation to do the Bluetooth communication and it's working fine for sometime.
This app should communicate with the remote control every 5 minutes or less, and I've been using the app for almost 6 months now. The last week I've some command clashes problem and looking at the logs I couldn't identify why did that happened. The last time that this had happened the app was running for more than 24h, communicating with the remote control, without any communication issue.
Two of it's commands have some similar characters, the first one that have to be done, to establish the connection.
OK_CONN
And an sniffer command which keeps the pilot awake listening for some sensor data:
N
Looking at the logs I can see the answer for command N, after applying the command OK_CONN.
Is it possible for a Bluetooth command to lost part of it's data, during an established communication or am I doing something wrong when writing to a characteristic? Should I change the command names to avoid this kind of clash?
I'm using android 9, at a Sony XPeria XZ phone.
Edit to clarify #Emil comment
07:02:12.880 [BleThread] writing <OK+CONN> to characteristic
07:02:12.368 [Binder:19249_F] [onCharacteristicChanged():274]:
n command confirme
Looking at the logs I see that the last written command as an ok_conn but it has written only the N, this is been show as the last line, it has confirmed to receive the n command alone, instead of receiving the full data of ok_conn.
By name clashes I mean that maybe the last N of the ok_conn command is been accepted as the command.
I just realized what's going on, you can post that as an answer #Emil, my problem was at the logic that sends the first command, sometimes I send this command and the micro controller is not started yet, that's probably the reason of it getting only part of the command.
Not sure what you mean by name clashes, but Android will always write what you told it to write, without packet loss, as long as you follow the rules to never have more than one outstanding operation (always wait for callback before you send the next operation) and that your data must fit within the maximum length for the corresponding operation.
Android phone that use usb connect to a PC, open the rndis, then do iperf test between the phone and the PC. After a few of hour's test, the endpoint of rndis, ep1out, didnot receive a xfercomplete event that the gadget driver should receve after sent transfer command.
I try to enlarge event buffer size from 256 to 4096, also enlage the grxfifosize from delault value , but the issue remains.
The phone have 8 cortex-A53 core , but we leave 1 little core(cpu0) and 1 big core(cpu7) online, and set the dwc interrupt not routing to cpu0 by setting the smp_affinity of the dwc irq because of the throughput reason. So the dwc3_interrupt runs at cpu7 ,and the dwc3_thread_interrupt also runs at cpu7.
Very strange that if we routing the irq to cpu0, and the dwc3_thread_interrupt runs at different core(cpu7), the issue disappear, canot understand why.
The code is open souce from the synopsys that you can find at kernel/drivers/usb/dwc3/gadget.c
https://github.com/aosp-mirror/kernel_msm/blob/e8adfc30ff9282a728fd8b666b6418308164c415/drivers/usb/dwc3/gadget.c
Thanks in advance.
Finally, found the answer, the event data in the eventbuffer was delayed behind the interrupt and the EVENTCOUNT register. When the issue happened, the data in the eventbuffer was dirty of the last round. By many times of reading the data, got the right one.
So, it was not missing the xfercomplete, but delayed. Don't know why the delay happened, the interrupt should be generated after the completes of the transferring.
I wanted to test Unified Remote (WiFi Remote for your PC) and I wasn't able
to connect to my PC in any way (although I could ping from PC to my Android). In the instructions it said I should try a ping from my Android to the PC, so I used the Android Terminal Emulator to try a ping and it just printed this:
ping: icmp open socket: Operation not permitted
My Android is rooted so I typed su and tried again and it worked. So I figured that Unified Remote needs su-rights to open a socket and connect to the server on my PC! The only problem is, that Unified Remote doesn't ask for su-rights... (Like the terminal. It didn't want root rights until i used su and I guess the same thing happens internally with Unified Remote)
Can I somehow start an App (in this case Unified Remote) with su-rights WITHOUT having it asking???
EDIT:
So now I tried 2 other remote control apps and none of them were able to find a server (neither detect it automaticly nor manually... And yes, I have installed and opened the server!) Again -> Ping works fine.... What surprises me is that only remote control apps have that problem... For example FTP with ES File Explorer works fine... Also I have an online game wich works fine too... I don't get it :(
Android device
ping: icmp open socket: Operation not permitted
Solution:
After Root my android mobile - PING socket error occured and I solved the issue by setting "ping" file permission as given below:
Read Write Execute
Owner Y - Y - Y
Group Y - N - Y
Others Y - N - Y
------------------
Set UID: Y
Set GID:
Sticky:
------------------
Octal Value: 4755 rwsr-xr-x
-------------------------------
You can edit permission by Root Explorer android software - Found - Play Store.
If the application it self not asking you for su rights than there is NO need to do it manualy.
I checked Google Play and in description of Unified Remote I dind't find any hint that it requires su rights.
I'm trying to achieve this goal: I have a bluetooth device connected to my android phone. Given this device can vibrate, is it possible to send a vibrate command to the device?
I have researched the bluetooth apis and the vibrate api on android developers' site but nothing clearly answers my question.
In bluetooth HFP (Handsfree) spec, there is no command (AT Command) to send vibrate to the peer device. As per the technical specification of bracelet "Vibration prompt for incoming phone" , once an AT command is send from phone to bracelet indicating a incoming call, bracelet generates vibration locally, phone does not ask/request to vibrate.
If you want peer device to vibrate,may be you have to use your own defined commands (AT command), with command recognized by the peer device.
I'm very glad to update this thread that I was able to programmatically vibrate the BT bracelet and in the right way using AT commands. So my application is based on Bluetooth Chat application in the Android samples. Here are the steps I followed:
connect the device to the phone
device follows BT Hands-Free profile specification. That requires "handshaking" by means of AT commands.
So I mimic this exchange of commands (with hard coded responses to bracelet's commands)
Once handshake is complete, I send AT command based on BT Hands-Free profile specification to RING and +CLIP:
On receiving the last set of response from application, the bracelet vibrates.
It seems simple, but without knowledge of BT Hands-Free profile specification, and sample AT commands this was nearly impossible.
#bt_user: Thanks for your pointer, that put me on the right track of R&D.
I was fiddeling with exaclty the same problem. After days of trial and error, I finally got it to work. I think it depends on the speed at wich you answer the HF's commands, as well as on the correct line-endings ([13][10]"COMMAND"[13][10]).
Here is my DroidScript which works. It's not cleaned up, but it works.
https://gist.github.com/t-oster/68a568ac4c4e133f67ac
The exact sequence, which works for my bracelet is:
CR is ASCII Code 13 and LF is ASCII Code 10
> AT+BRSF=0<cr>
< <cr><lf>+BRSF:0<cr><lf>
< <cr><lf>OK<cr><lf>
> AT+CIND=?<cr>
< <cr><lf>+CIND: ("service",(0,1)),("call",(0,1))<cr><lf>
< <cr><lf>OK<cr><lf>
> AT+CIND?<cr>
< <cr><lf>+CIND: 1,0<cr><lf>
< <cr><lf>OK<cr><lf>
> AT+CMER=3,0,0,1<cr>
> <cr><lf>OK<cr><lf>
from then on I can just send
<cr><lf>RING<cr><lf>
to make it vibrate.
i have developed a java android version
using parts from Thomas Oster and an example i found online
https://gist.github.com/shimondoodkin/a582d910045ab06ab68c
I have a problem that has been nagging me to an extreme extend in the past few days. I would like to write an Android sh script that does the following (to help me sync music, pics etc.):
1) Turn on wifi (wifi is off by default to save power)
2) Check if my wifi connection is in range (lets call it myWifi)
3) If myWifi is not in range, disable wifi, if it is in range, connect and start some synch software
Now, to enable / disable wifi, I use the following command, which requires root:
svc wifi enable / disable
To scan for avaible wifi connections, I use the following command:
iwlist eth0 scan
The strage thing is, that iwlist eth0 scan will only work if I am NOT logged in as root (I am very curious to why this is the case, if anyone knows anything?), running it while root will return:
eth0: Interface doesn't support scanning : Invalid argument
but running it while not logged in as root, will give me the info I need. I have tried different approaches to get around this problem. The most obvious one is logging in as the standard user in the Android system right before invoking the iwlist command:
su -c app_1
However, any command that involves su will return permission denied even when invoking it as root, and since sudo does not exist in Android, I feel pretty lost here. I did also try a workaround involving splitting the script into two parts, and trying to run the first as root and the second as non root (the default user in Android i app_1), but this will only delay the problem...
If anyone has an answer to how to either get around this user problem, or how to use iwlist eth0 scan (or another command that does the same) while logged in as root, I would be very gratefull.
Thank you.
According to man iwlist normal users can only see some left-over scanning results. To initiate a new scan as root you first need to start up your interface (after starting wifi):
ifconfig wlan0 up