I working on an app that I need to calculate distance travelled from point A to point B (by car).
I asked Elm Electronics (chipset manufacturer), and they said there isn’t any standard OBD-II PID to return mileage from the odometer, although car manufacturers might provide a PID. Since this way is not standard, I found another way.
PID 0131 (Distance traveled since codes cleared), is returning something that I think might be helpful. If I'm able to clear it at point A and read its value at point B, then I'm done :)
I thought a lot to guess what does "codes cleared" mean, but I couldn't realize: What does it mean? And my another important question, how can I clear the code or reset this PID?
I just tested on two cars.
My library can be used for anyone who is looking for a OBD-II library from here.
So, I plan to, since I'm able to get the speed (v), then I'm able to calculate the distance based on the d = v * t formula.
Elm Electronics are right. The resetting trouble codes solution is a possible, but maybe unwanted, workaround though.
Mode 04 is for resetting the codes. Sending 04 will reset the MIL (Malfunction Indicator Light) and reset the codes you want to reset.
In the comments, Chris suggested to use the value, and then keep track of this value yourself. That way, you don't need to misuse the Mode 04.
Th 0131 value overflows at 65535 km. But when you bring you car in for maintenance, they could reset this value, depending on who is maintaining your car of course.
Source: Mode 04 - Wikipedia