Android OBD-II: How to get distance traveled in meters? - android

I'm making an android app that connects to an OBD-II device (ELM327 - http://www.dx.com/p/elm327-bluetooth-odb2-v1-5-car-diagnostic-interface-126921#.V86wdih97IU) via Bluetooth.
I'm also using the https://github.com/pires/obd-java-api/ library to get the data from the device.
I am able to connect to the device and get data without any problems but when I try to retrieve distance it always returns it in KM. Is there a way to get the distance of a trip in meters instead?
I tried using the Torque Lite app (https://play.google.com/store/apps/details?id=org.prowl.torquefree&hl=en) and its able to return Trip distance in KM with one decimal place (0.0 KM).
Would like to know what command it uses to actually get the values or does it derive it from something else.

Unfortunately, a standard PID for distance traveled simply doesn't exist. See this for a list of standard PIDs.
The code you are using now, DistanceSinceCCCommand, uses standard Mode 01 PID 0x31 to retrieve the distance driven since the last clear codes command. The PID has units of integer kilometers and thus cannot give you the precision you are seeking.
I tried using the Torque Lite app (https://play.google.com/store/apps/details?id=org.prowl.torquefree&hl=en) and its able to return Trip distance in KM with one decimal place (0.0 KM).
The torque app used location(GPS) information from the android device to record geo location. I'd guess that it is using that information to determine the trip distance to the precision of 0.1km.
Recommendation
I'd recommend you follow their lead and use location data to determine distance traveled if you need that sort of accuracy.
Use a Location Listener from the google location api and Location.distanceTo(location) to determine the incremental location changes.
More On Enhanced PIDs
Enhanced PIDs (also called DIDs) are mode 22 parameters that are vehicle specific.
There exist many other vehicle parameters that are not publicly documented and may offer better precision. They are vehicle specific (but usually common to a subset of vehicles from the same manufacturer). They are Mode 22 enhanced PIDs. Here's a list of old Ford DIDs. If anyone can find a newer list of mode 22 DIDs, please edit my post and add it as I know there are many more than I've found available publicly.
GM Chevy Spark PIDs

You could read the OBD-II Mode 1, PID 0D to get the speed at regular intervals. This would give a decent distance reading in metres if you read often enough and apply the distance = speed * time calculation.

Most of the classes implement
ObdCommand
which has a method
useImperialUnits(boolean)
so, if you use, say, DistanceSinceCCCommand, then
DistanceSinceCCCommand distanceSinceCCCommand = new DistanceSinceCCCommand();
distanceSinceCCCommand.useImperialUnits(true);
would do the conversion.
You can find interesting stuff if you examine the library source.

You can also use
getImperialUnit()
if you just want the numeric value rather than the string with a trailing units label.

Related

How to Find each & every room's latitude and longitude inside Organization/Office in android

I am working on location based android application using Location Manager & Geo Fencing. Below are the scenario/Example for my implementation.
In our Home/Organization we have total no of 10 Rooms. When a user enter into different Rooms need to notify the Admin User about user changing the Room. The same is achieved by using android Geo-Fencing .
As mentioned in Google Geofencing as ,
"For getting best results from your geofences is to set a minimum radius of 100 meters" for single Geo-Fencing.
In our scenario inside the organization , a room to another room distance may be below 1 meter as well. Here I have some questions regarding Geo-Fencing as ,
How can we use Geo-Fencing in each room.?
The Lat/Long values are differeed in last 2/3 decimal digit values in every room. So how can we get every rooms accurate lat/lang?
How can we use multiple Geo-Fencing (10 rooms) inside the organization within one meter distance because of the Android Geo-Fencing min required radius of 100 meters for best result as mentioned in above link?
Note: Inside room GPS is not working . So we have used the Network provider. We can't get accurate location(Lat/Long) values in Network Provider.
So could you please provide the roadmap or solution for achieve the above.
Thanks in Advance.
The only relible indoor locationing are iBeacons or similar devices. That are low energy blue tooth devices delivering an beacon id, and the estimated distance to that beacon.
You can install one in each room.

Why does the Android GPS-Fix vary by 200 ms?

I am writing my Master thesis atm and analyzed about 400 different GPS-Trajectories (paths consisting of a list of longitude/latitude points and an according timestamp) recorded with the MediaQ-App (probably not important) for Android (about 310 trajectories) and iOS (about 90).
When analyzing the time intervals between the timestamps, I was expecting the inaccuracies around the 1 second frequency, in which the timestamps were supposed to be recorded, since neither Android or iOs are real-Time-OS from apps point of view. Still, why are there, what appears to be local peaks in about 200ms steps? Be nice, I do not know a lot about mobile operating systems :-)
(x-axis: seconds, y-axis: the relative probability that a timestamp will be recorded at this point in time. Ignore the exact values of the y-axis...)
The usual behavior is that an App takes the timestamp direct from the location delivered by the system. Most probably this is the case in that App, otheriwse this would be a heavy programming bug. (The delay between nominal GPS time and receiving system time of about 200ms is plausible, I saw that in my app, and in ios Map app, which makes a correction in their map api to extrapolate the location into the future, to try to compensate that delay)
Under android (and ios) it is import to know whether the location are determined exclusively by GPS. On both plattforms (ios, android) an App can set whether GPS only or combined GPS + WLAN + Cell Locationing is used.
For high quality recording is is highly recomended to use GPS only.
A GPS chip once having a location usually outputs a location with a timestamp exactly at 000. Exception can happen before the location is valid.
Under ios if the location was obtained by GPS the millisecond are always 0.
I have no experience with android, but usually the GPS chip itself sets the value to millis = 0. (However, some android phones are known to use a crippled cheap GPS chips, that are not able to get an intial position without the help of an internet conection)
It is possible to determine whether the location was obtained by GPS by looking at the course (or called heading) and speed value, which are invalid for non GPS locations (cell Tower locationing)
To know whether this time variations come from the Application (not using the GPS only mode) or if it is caused by Android, you can test that with another application on the same phone. (E.g Motion-X GPS) (Or by comparing both apps on another android phone)

how to get Distance between wifi access point and Mobile Device

i am developing an android application which have module to search all nearest / detected wifi hotspot.
i can get all detail from searched wifi hotspot like,
SSID, BSSID, capabilities, frequency, level and timestamp
with these information, i also need Distance of wifi ( The distance between wifi accesspoint and Mobile Device )
i am using below lines to get Distance.
double exp = (27.55 - (20 * Math.log10(freqInMHz)) + Math.abs(levelInDb)) / 20.0;
double distanceM = Math.pow(10.0, exp);
this will return distance in meter.
i got these code by reserch on google from many pages.
but i think i am going wrong, this code is returning wrong distance. i also tried a lot on google search but not getting accurate output.
Please help me. how can i get Distance between Wifi AP and Mobile device?
This code:
double exp = (27.55 - (20 * Math.log10(freqInMHz)) + Math.abs(levelInDb)) / 20.0;
double distanceM = Math.pow(10.0, exp);
Works under the assumption of free space path attenuation between two isotropic antennas and the AP transmitting at a power of 20dBm (and the math is not even correct; the frequency dependence of free space path loss is different; not that is matters for the bands of W-LAN, uses, the correction is in the 27.55).
In reality you're dealing with anisotropic antennas, obstacles in your path, diffraction effects and the AP varying it's power output to save energy if no high bandwidth is required.
Or in other words: It's totally impractical to obtain a reliable distance figure just looking at the received power. It can give you a ballpark, order of magnitude, but not something that's remotely accurate. This is just basic physics.
The only reliable way of measuring distance is time-of-flight. For this you have to measure the roundtrip time between the device and the access point. Since we're dealing with the speed of light and distances in the order of meters up to 100m (top), this means measuring nanoseconds. Can be done but requires some work. See the link SatelliteSD gave you (it's in German but the diagrams and keywords should be understandable).
It is possible, you could use the Time-of-Flight approach. Keep in mind that you can't rely on the messages recieved, but on the overhead received (like ACK)
I can only come up with this reference (german language) measuring of signal runtimes
And from a quick read I think it is a very tedious thing to do.
No, it is not possible.
You'll not be able to find the hotspots distance from your current device location to the actual hotspot.
It seems that the hotspots don't report their coordinates.
Check the Link which has more detailed info.
There is a method called "triangulation" but for this case you have least 3 hotspot. You can answer with detail in this pdf.
http://www.see.ed.ac.uk/~slig/papers/ITM2010.pdf

unstable cellid coordinates with google/glm/mmap

I "play" with google/glm/mmap in order to find the coordinates of a cell. I note that the returned values can changed (queries on several days).
Any explanation ?
It appears that the coordinates returned are a weighted average of locations where cell phones reported connecting to that base station. That is, they are not the coordinate of the base station antenna. This is actually better for geolocation purposes since you want to know where the cell phone is, not where the base station is. One of the parameters returned with the coordinates is a measure of the "spread" of the reports --- which gives one some idea of how accurate the geo-location is likely to be. It appears that as reports continue to come in to mmap, the data base is updated and so changes are possible over time, usually rather minor.
Note that, in the case of CDMA at least, the true location of the base station antenna can be obtained using getBaseStationLatitude() and getBaseStationLongitude() methods on cellLocation in e.g. onCellLocationChanged() callback. This is not supported by all carriers. U.S. Cellular does provide this information, Verizon Wireless sadly does not. Femtocells do provide the information using their built in GPS. Again, depending on your application, knowing the base station location may not be what is required.

How to accuratly find other Android users within a radius of 200ft ( How did Color do it?)

I'm working on a app which requires that a device with this app installed will automatically find other users within a maximum radius of 200ft (worst case scenario 300ft, but that's pushing it) and/or a minimum radius of 40ft.
Ive tried the obvious solution of using GPS and a MYSQL query that query's our location table for other users within the 200ft radius, but as you probably would guess this is not incredibly accurate and if the device uploads coordinates that are off by over 200ft the server will return a list of users that are not within proximity. While I would prefer to just get the app to work the way it was meant to I'd rather the server return no users than false positives.
I know there's probably no simple way to do it accurately, but what other options do I have? And how did Color manage to do it? With all the tech in the avg smartphone and all the location based apps this has to be possible to do.
200ft (60m) is no Problem for GPS. Usually GPS is below 10m.
You even have a location.getAccuracy() method which you should evaluate
Just use GPS as your only location source. do not use cell tower location provider, when you want accuracy < 60m.
Of course inside a building, when you are sitting at your desktop GPS will not work, or is off by 60m.
GPS needs a view to open sky not obstructed (by dense materials).
Take a look at this question:
how to get the most accurate location using GPS and AGPS with given time in android?
Basically it depends on the phone's GPS and the current environment. Besides that, there's probably nothing you can do to further boost the location accuracy other than using GPS.

Categories

Resources