MG have an api for accessing car data
but it has not been made public
so if you want to use it, you have to hack it!
You can, of course, access your MG car data using their official App: iSmartBut where is the fun in that? Especially as you must use Google Play Store if you want to use this app on Android. And as you may remember from a few previous posts: I have a de-google phone running on LineageOS.
With a bit of help from ChatGPT and the usual mixed bag of information & misinformation from the internet, I did some testing using an api from Github: saic-python-client-ng
ChatGPT is funny, it picks up lots of stuff and (unfortunately) frequently mixes it up. You often get information from different models & software versions mixed up in its answers, so have to keep intervening and steering it in the right direction.
Many of the methods & properties that ChatGPT came up with, seemed to relate to different cars, but once I'd got it to a bit of iteration, I ended up with a useful piece of Python code that was able to 'discover' what I needed to know.
Here is a short extract from my discovery dump file:-
![]() |
From this dump it seems that the proper colour name is 'Soul Blue', while the
regional name (i.e. from UK sales brochure) is Piccadilly Blue! |
Armed with this information I was able to make good progress with a python program which saves data in an html file...
Most of this data is just pulled from the car via the api and 'tarted-up' a bit.
I wanted to include some measure of driving 'efficiency' and initially tried comparing the current range with the manufacturers published range or the 'Battery Range (BMS ideal)'. But as their figures are so hopelessly optimistic, I have now tried using the figures published by Electric Vehicle Database.
These make it look like we are at least trying to drive the car economically (...or maybe not).
why am I doing this?
The original goal was to be able to view the SoC & predicted mileage (or Primary Range) from anywhere, rather than use iSmart.
We do use iSmart to defrost the car & turn on the heated seats, before we step outside into the cold. But iSmart doesn't always load and read current car data.
So I wanted something simple that we could access while drinking coffee as the car sits there, charging. It just needs to be a monitor, with no control over the car and no need to log in.
Ultimately I'm looking to run this python program continuously on a Raspberry Pi at home, then use WireGuard to allow safe, browser access via any device (google or otherwise) via VPN.
However, I embark on many projects where the journey is more interesting than the final destination ...this could be another one!


No comments:
Post a Comment