ElectricMotorcycleForum.com

  • April 24, 2024, 02:32:45 AM
  • Welcome, Guest
Please login or register.

Login with username, password and session length
Advanced search  

News:

Electric Motorcycle Forum is live!

Pages: [1] 2 3 ... 8

Author Topic: SR/F App (NextGen) - API  (Read 9355 times)

bigmadf

  • Newbie
  • *
  • Posts: 7
    • View Profile
SR/F App (NextGen) - API
« on: October 18, 2019, 03:42:30 AM »

Sometimes the need arises to access the data that is available for en EV with an online connection from outside the app of the manufacturer. I have seen a lot of solutions for getting the SoC or other data from the Zero bikes.
Since the SR/F comes with its own connectivity and companion app I needed to get access to the data in the Zero cloud from outside the Zero NextGen App.
I have a smart Wallbox solution which supports smart charging modes depended on the EVs SoC. So I wrote a plugin for the smart Wallbox solution OpenWB. In order to accomplish this I had to reverse engineer the Webservice calls from the Zero NextGen app to the cloud backend.

Now here it comes. Code examples are for experienced users using Terminal on Linux or Mac.

In order to gain access to the cloud data you have to identify the service specific unitnumber for your vehicle. This can be accomplished by the following simple call to the Zero NextGen Backend:
Code: [Select]
curl -s --http2 -G https://mongol.brono.com/mongol/api.php?commandname=get_units -d format=json -d pass=<ZERONEXTGENPASSWORDFROMAPP> -d user=<ZERONEXTGENUSERNAMEFROMAPP>
You can pass this JSON output to jq to make it readable. Or you just note the value of unitnumber for the actual call for the relevant values.

Code: [Select]
curl -s --http2 -G https://mongol.brono.com/mongol/api.php?commandname=get_last_transmit -d format=json -d user=<ZERONEXTGENUSERNAMEFROMAPP> -d pass=<ZERONEXTGENPASSWORDFROMAPP> -d unitnumber=<ZERONNEXTGENUNITNUMBERFROMABOVE>
Same here: Pass the output to jq in order to have a formatted JSON output.
There are some relevant values and some not so relevant values. Relevant values include: VIN, mileage, software_version (do not know how reliable though), longitude, latitude, altitude, velocity, heading, main_voltage, address, soc.

If you are interested in a very smart Wallbox and living in Europe I strongly suggest to look at OpenWB. Zero NextGen Support comes out-of-the box, just username and password needed to configure.

Hope this helps someone.


Logged
Zero SR/F Premium
Buell XB9R
Tesla Model X 100D
--Switzerland--

BrianTRice@gmail.com

  • Unofficial Zero Manual Editor
  • Hero Member
  • *****
  • Posts: 4014
  • Nerdy Adventurer
    • View Profile
    • Personal site
Re: SR/F App (NextGen) - API
« Reply #1 on: October 23, 2019, 10:53:34 AM »

That is interesting, and thanks for taking the time to reverse engineer and document this.

I'll add this to my unfortunately long queue for the unofficial manual, at least.

Speculatively, it does seem as though one could replicate this web service pretty easily, which might come in handy some day.
Logged
Current: 2020 DSR, 2012 Suzuki V-Strom
Former: 2016 DSR, 2013 DS

basketkase

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: SR/F App (NextGen) - API
« Reply #2 on: October 30, 2019, 06:21:34 PM »

That's super cool!

I replicated those requests and it worked for my sr/f.
Interesting to see that the incorrect mileage number in the app is being returned from the api.
Logged

BrianTRice@gmail.com

  • Unofficial Zero Manual Editor
  • Hero Member
  • *****
  • Posts: 4014
  • Nerdy Adventurer
    • View Profile
    • Personal site
Re: SR/F App (NextGen) - API
« Reply #3 on: October 30, 2019, 10:35:54 PM »

An out of date odometer reading seems like a trivial code fix - the app odometer indicator would only show the highest of any reported or last-bike-recorded odometer readings.

Sigh, if I have time to analyze what this web service does, I can probably come up with off the cuff recommendations to make it better that will never be implemented.
Logged
Current: 2020 DSR, 2012 Suzuki V-Strom
Former: 2016 DSR, 2013 DS

Crissa

  • Hero Member
  • *****
  • Posts: 3144
  • Centauress
    • View Profile
Re: SR/F App (NextGen) - API
« Reply #4 on: October 31, 2019, 12:39:33 AM »

Except, what if the spurious data was alot higher?  It would get stuck permanently.

-Crissa
Logged
2014 Zero S ZF8.5

BrianTRice@gmail.com

  • Unofficial Zero Manual Editor
  • Hero Member
  • *****
  • Posts: 4014
  • Nerdy Adventurer
    • View Profile
    • Personal site
Re: SR/F App (NextGen) - API
« Reply #5 on: October 31, 2019, 01:07:07 AM »

Except, what if the spurious data was alot higher?  It would get stuck permanently.

Spurious odometer readings are a bigger problem than what an app does. I'm not going to get into API and software design on a damn forum - total waste of both our time. We don't need to resolve what the right code is right here in public by sending messages back and forth. We just need to make enough noise that someone at Zero notices and makes a bug-fix task.
Logged
Current: 2020 DSR, 2012 Suzuki V-Strom
Former: 2016 DSR, 2013 DS

Crissa

  • Hero Member
  • *****
  • Posts: 3144
  • Centauress
    • View Profile
Re: SR/F App (NextGen) - API
« Reply #6 on: October 31, 2019, 02:46:41 AM »

Just pointing out that it's not really as simple a problem as it sounds ^-^

I just wish the old app would include a timer so that I wouldn't have to set one when I plug it in and walk away.  I don't stand around in Bluetooth range and often not where there's clear network at all.

-Crissa
Logged
2014 Zero S ZF8.5

remmie

  • Sr. Member
  • ****
  • Posts: 318
    • View Profile
Re: SR/F App (NextGen) - API
« Reply #7 on: November 02, 2019, 06:55:15 PM »

Nice Find on the API Settings :

These are the values i get with my bike (some numbers altered for obvious reasons)

[
{"unitnumber":"123456",
"name":"538ZFAZ76LCK00000",
"unittype":"5",
"unitmodel":"6",
"mileage":"4382.46",
"software_version":"190430",
"logic_state":"2"
,"reason":"2",
"response":"0",
"driver":"0",
"longitude":"4.5000",
"latitude":"51.5000",
"altitude":"0",
"gps_valid":"0",
"gps_connected":"1",
"satellites":"0",
"velocity":"1",
"heading":"344",
"emergency":"0",
"shock":"",
"ignition":"0",
"door":"0",
"hood":"0",
"volume":"0",
"water_temp":"",
"oil_pressure":"0",
"main_voltage":13.08,
"analog1":"0.09",
"siren":"0",
"lock":"0",
"int_lights":"0",
"datetime_utc":"20191030162309",
"datetime_actual":"20191102113548"
,"address":"YourCity, YourStreet",
"perimeter":"",
"color":2,
"soc":91,
"tipover":0,
"charging":1,
"chargecomplete":0,
"pluggedin":1,
"chargingtimeleft":0}
]

So I guess this info could be used to wite either an app or a webpage where this info is presented in a more clear way. I'm ok with arduino programming but website and Json is not my expertise.
Maybe someone could have a quick go at this and write some (HTML???) code so everyone can enter their data (unitnumber, username and password) and get all the data from the API.

By the way. The Api calls the starcomsystems.com website and if you go to home and then products and then the page for vehicle tracking you see the following page  :

https://www.starcomsystems.com/helios/

And the Helios TT or advanced device looks a lot like the device that I saw when i had my tank plastics off. It is mounted just behind the ignition key on top of the DCDC converter and has the same rubber cover as shown on the webpage. On the attached picture you can just about spot it.The picture is from when i had my rapid charger installed (seperate topic)


« Last Edit: November 02, 2019, 07:28:44 PM by remmie »
Logged
Current : Red Premium Zero SR/F (ordered May 25, delivered August 23 2019) with Rapid charger for 12kW charging
Former : White Zero SR 2018 ZF14.4 kWh (17.500 km)
Former : Black Zero SR 2014 ZF11.4 kWh (25.000 km)
SR's outfitted with Homemade "Supercharger" 6x eltek Flatpack S (12 kW)

remmie

  • Sr. Member
  • ****
  • Posts: 318
    • View Profile
Re: SR/F App (NextGen) - API
« Reply #8 on: November 03, 2019, 12:47:36 AM »

Turns out you can also use a plain URL in your browser :

https://mongol.brono.com/mongol/api.php?commandname=get_units&format=json&user=yourusername&pass=yourpass

to get your unitnumber you have to use in the URL below

https://mongol.brono.com/mongol/api.php?commandname=get_last_transmit&format=json&user=yourusername&pass=yourpass&unitnumber=0000000

obviously you would have to alter :
yourusername to the username you have entered in the NextGen app
yourpass to the password you ised in the nextgen app

you can change the format=json to format is CSV for CSV response, or to format=XML for XML respone, or to format=HTTP for also comma seperated values. And possibly there are more formats you can use.

Logged
Current : Red Premium Zero SR/F (ordered May 25, delivered August 23 2019) with Rapid charger for 12kW charging
Former : White Zero SR 2018 ZF14.4 kWh (17.500 km)
Former : Black Zero SR 2014 ZF11.4 kWh (25.000 km)
SR's outfitted with Homemade "Supercharger" 6x eltek Flatpack S (12 kW)

Hans2183

  • Sr. Member
  • ****
  • Posts: 468
    • View Profile
Re: SR/F App (NextGen) - API
« Reply #9 on: November 03, 2019, 08:20:45 PM »

Awesome information! Contains more than what the app shows in remote connection mode. I have a quick app ready that I'll share later today. I'll make it an open source project so anyone can build upon it. Just be careful using it on public WiFi since that password is plain text.
Logged
2021 Energica SS9+ 21.5kWh
--- Belgium ---

Hans2183

  • Sr. Member
  • ****
  • Posts: 468
    • View Profile
Re: SR/F App (NextGen) - API
« Reply #10 on: November 04, 2019, 01:27:39 AM »

Basic project for Android using retrofit and gson converter. There is an apk file in the downloads section of the project

 https://bitbucket.org/cappelleh/zeronextgen
Logged
2021 Energica SS9+ 21.5kWh
--- Belgium ---

BrianTRice@gmail.com

  • Unofficial Zero Manual Editor
  • Hero Member
  • *****
  • Posts: 4014
  • Nerdy Adventurer
    • View Profile
    • Personal site
Re: SR/F App (NextGen) - API
« Reply #11 on: November 04, 2019, 03:08:24 AM »

Basic project for Android using retrofit and gson converter. There is an apk file in the downloads section of the project

 https://bitbucket.org/cappelleh/zeronextgen

Nice! Now I need to check whether I can mirror that on Github without a maintenance issue. We have a group for that:
https://github.com/zero-motorcycle-community
Logged
Current: 2020 DSR, 2012 Suzuki V-Strom
Former: 2016 DSR, 2013 DS

remmie

  • Sr. Member
  • ****
  • Posts: 318
    • View Profile
Re: SR/F App (NextGen) - API
« Reply #12 on: November 04, 2019, 05:09:12 AM »

Thanks Hans !

Unfortunately i have no andriod devices ;) just iphones. But do you have a screenshot of your app?

Logged
Current : Red Premium Zero SR/F (ordered May 25, delivered August 23 2019) with Rapid charger for 12kW charging
Former : White Zero SR 2018 ZF14.4 kWh (17.500 km)
Former : Black Zero SR 2014 ZF11.4 kWh (25.000 km)
SR's outfitted with Homemade "Supercharger" 6x eltek Flatpack S (12 kW)

Hans2183

  • Sr. Member
  • ****
  • Posts: 468
    • View Profile
Re: SR/F App (NextGen) - API
« Reply #13 on: November 04, 2019, 03:50:23 PM »

I'll finish layout later today. In the current version you still have to enter login again every time you use the app. I’ll use the fingerprint protected storage to keep that on the device in a secure way.

@BrianTrice Project Should be public. Let me know if you need help.

@remmie There will be an iOS version later on but since I have more experience with Android it’s just faster for me to start with that.

This is a screenshot


Logged
2021 Energica SS9+ 21.5kWh
--- Belgium ---

Hans2183

  • Sr. Member
  • ****
  • Posts: 468
    • View Profile
Re: SR/F App (NextGen) - API
« Reply #14 on: November 05, 2019, 03:12:50 AM »

The version in the repo now has fingerprint configured to safely store that password. Still plain text over the network though... not my fault, thats the API.

Btw @remmie you're right about the helios resemblance, check this pdf https://www.starcomsystems.com/wp-content/uploads/2019/05/The-Worlds-First-Connected-Motorcycle.pdf
Logged
2021 Energica SS9+ 21.5kWh
--- Belgium ---
Pages: [1] 2 3 ... 8