ElectricMotorcycleForum.com

Makes And Models => Zero Motorcycles Forum | 2013+ => Topic started by: bigmadf on October 18, 2019, 03:42:30 AM

Title: SR/F App (NextGen) - API
Post by: bigmadf 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 (https://openwb.de). 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 (https://openwb.de). Zero NextGen Support comes out-of-the box, just username and password needed to configure.

Hope this helps someone.


Title: Re: SR/F App (NextGen) - API
Post by: BrianTRice@gmail.com 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.
Title: Re: SR/F App (NextGen) - API
Post by: basketkase 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.
Title: Re: SR/F App (NextGen) - API
Post by: BrianTRice@gmail.com 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.
Title: Re: SR/F App (NextGen) - API
Post by: Crissa on October 31, 2019, 12:39:33 AM
Except, what if the spurious data was alot higher?  It would get stuck permanently.

-Crissa
Title: Re: SR/F App (NextGen) - API
Post by: BrianTRice@gmail.com 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.
Title: Re: SR/F App (NextGen) - API
Post by: Crissa 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
Title: Re: SR/F App (NextGen) - API
Post by: remmie 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/ (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)


Title: Re: SR/F App (NextGen) - API
Post by: remmie 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.

Title: Re: SR/F App (NextGen) - API
Post by: Hans2183 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.
Title: Re: SR/F App (NextGen) - API
Post by: Hans2183 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
Title: Re: SR/F App (NextGen) - API
Post by: BrianTRice@gmail.com 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
Title: Re: SR/F App (NextGen) - API
Post by: remmie 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?

Title: Re: SR/F App (NextGen) - API
Post by: Hans2183 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

(https://i.ibb.co/zRYVrLy/9-E24-BD64-F3-B8-4-C24-88-DD-13333790-AD1-B.png) (https://ibb.co/bBZ5PyS)
Title: Re: SR/F App (NextGen) - API
Post by: Hans2183 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
Title: Re: SR/F App (NextGen) - API
Post by: Hans2183 on November 05, 2019, 04:24:59 AM
Also found one more commands

Code: [Select]
get_userinfo
With response mostly blank for my account

Code: [Select]
[{"fullname":"my-email","phone":"","email":"my-email","country":"","utcdifference":0,"timezone":"","language":"en","speedunits":0,"distanceunits":0,"dateformat":0,"timeformat":0,"allowstatus":0,"allowcommands":false,"allowstop":0,"allowlogic":0,"allowclearfleet":0,"template":"Starcom Online","maptype":0,"allowhistoryreport":1,"addunitsbycode":0,"logourl":"https:\/\/mongol.brono.com\/mongol\/fiona\/templates\/logo_starcom.gif","logotag":"1"}]
Code: [Select]
get_commands
Is also a valid one but returns an empty set for my account. I know it's valid since others get clearly marked with an error like

Code: [Select]
{"error":"602 Command unknown (get_state)"}
Title: Re: SR/F App (NextGen) - API
Post by: BrianTRice@gmail.com on November 05, 2019, 01:35:47 PM
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.

Have you tried performing a POST with parameters as form data? There’s also GET with form data, which browsers won’t do but is valid.
Title: Re: SR/F App (NextGen) - API
Post by: stevenh on November 05, 2019, 09:06:32 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/ (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)

Interesting that my mileage does not match the mileage value returned by the call.  Not sure what's up there.  Does your's match?  Clearly a data set from a standard vehicle package (door, oil pressure :))...

My actual mileage is a little over 4K, and the request returned 5856.51.

Steve
Title: Re: SR/F App (NextGen) - API
Post by: remmie on November 05, 2019, 09:14:58 PM
I think it is not the bike mileage but the ‘mileage’ of the gps unit.

Did you (or the dealer) transport the bike on a trailer to get it home?
Title: Re: SR/F App (NextGen) - API
Post by: stevenh on November 05, 2019, 09:29:31 PM
I think it is not the bike mileage but the ‘mileage’ of the gps unit.

Did you (or the dealer) transport the bike on a trailer to get it home?

I did not, but it was a demo bike, so it may have moved around a bit.  1800 miles is a bit of travel though!

Steve
Title: Re: SR/F App (NextGen) - API
Post by: remmie on November 05, 2019, 11:22:22 PM
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

some more info from starcom systems and their Helios GPS tracker on the SR/F on their blog

https://www.starcomsystems.com/2019/03/28/the-first-smart-connected-motorcycle-effortless-connection/ (https://www.starcomsystems.com/2019/03/28/the-first-smart-connected-motorcycle-effortless-connection/)

this was posted back in March, I haven't seen it before.

Title: Re: SR/F App (NextGen) - API
Post by: gadgetgirl on November 06, 2019, 01:03:28 AM
It sounds like a fun side project to write a web app for this API. Every attempt I've made to hit those endpoints results in {"error":"601 Unauthorized user (MYUSER)"}, even though I'm able to use the NextGen app just fine (and I have the right password, since it came from my password manager). I'm hesitant to log out of the app to see if my account is borked somewhere, in case it won't let me back in, but I'll suck it up and try it soon. What I'd really like to attempt is to aggregate the data from the Helios tracker with a makeshift sentry mode (cameras, raspberry pi, something), like Tesla offers.
Title: Re: SR/F App (NextGen) - API
Post by: Hans2183 on November 06, 2019, 01:39:42 AM
If you have Android you can try with this implementation https://play.google.com/store/apps/details?id=be.hcpl.android.zeronextgen

Edit: For me mileage is close to actual mileage on the bike. Bike has around 4400 km, API shows around 200km less. I noticed once that the SoC was returning 0% while parked indoors. Not sure why, actual charge was 95%.

This is while not charging but plugged in with soc at 21%
(https://i.ibb.co/cy00SCK/Screenshot-1572987254.png) (https://ibb.co/cy00SCK)

This is while charging
(https://i.ibb.co/fSH2y17/Screenshot-1572987753.png) (https://ibb.co/fSH2y17)

I'll start on the iOS app first and then get back to this to get some data logging working.
Title: Re: SR/F App (NextGen) - API
Post by: Hans2183 on November 06, 2019, 03:08:23 PM
Found another command `get_history` but requires some more input (like start date) that I can't find the right format/parametername for.

From the zero nextgen app itself this is how the data is stored in a table with this structure

Code: [Select]
supportSQLiteDatabase.execSQL("CREATE TABLE IF NOT EXISTS `RideData` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `odometer` INTEGER NOT NULL, `totalEnergyUsed` INTEGER NOT NULL, `averageEfficiency` INTEGER NOT NULL, `speed` INTEGER NOT NULL, `leanAngle` INTEGER NOT NULL, `power` INTEGER NOT NULL, `torque` INTEGER NOT NULL, `coastRegen` INTEGER NOT NULL, `brakeRegen` INTEGER NOT NULL, `longitude` REAL NOT NULL, `latitude` REAL NOT NULL, `stateOfCharge` INTEGER NOT NULL, `timestamp` INTEGER NOT NULL)");
                supportSQLiteDatabase.execSQL(RoomMasterTable.CREATE_QUERY);
                supportSQLiteDatabase.execSQL("INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, \"2b8213d2b0f5caa844e59ff8c1081127\")");

And then several queries exist for useful data

Code: [Select]
@Query("SELECT avg(speed) FROM RideData")
    int getAverageSpeed();

    @Query("SELECT odometer FROM RideData ORDER BY timestamp DESC LIMIT 1")
    long getEndingOdometer();

    @Query("SELECT MAX(speed) FROM RideData")
    int getMaxSpeed();

    @Query("SELECT longitude, latitude FROM RideData")
    @NotNull
    List<Coordinates> getRideCoordinates();

    @Query("SELECT * FROM RideData")
    @NotNull
    List<RideData> getRideData();

    @Query("SELECT * FROM RideData ORDER BY brakeRegen ASC LIMIT 1")
    @NotNull
    RideData getRideDataWithMaxBrakeRegen();

    @Query("SELECT * FROM RideData ORDER BY coastRegen ASC LIMIT 1")
    @NotNull
    RideData getRideDataWithMaxCoastRegen();

    @Query("SELECT * FROM RideData ORDER BY leanAngle ASC LIMIT 1")
    @NotNull
    RideData getRideDataWithMaxLeanAngleLeft();

    @Query("SELECT * FROM RideData ORDER BY leanAngle DESC LIMIT 1")
    @NotNull
    RideData getRideDataWithMaxLeanAngleRight();

    @Query("SELECT * FROM RideData ORDER BY power DESC LIMIT 1")
    @NotNull
    RideData getRideDataWithMaxPower();

    @Query("SELECT * FROM RideData ORDER BY speed DESC LIMIT 1")
    @NotNull
    RideData getRideDataWithMaxSpeed();

    @Query("SELECT * FROM RideData ORDER BY torque DESC LIMIT 1")
    @NotNull
    RideData getRideDataWithMaxTorque();

    @Query("SELECT odometer FROM RideData ORDER BY timestamp ASC LIMIT 1")
    long getStartingOdometer();

    @Query("SELECT SUM(brakeRegen) FROM RideData")
    int getTotalBrakeRegen();

    @Query("SELECT SUM(coastRegen) FROM RideData")
    int getTotalCoastRegen();

    @Insert(onConflict = 1)
    void insertRideData(@NotNull RideData rideData);

    @Insert(onConflict = 1)
    void insertRideDataList(@NotNull List<RideData> list);

    @Query("DELETE FROM RideData")
    void nukeData();
Title: Re: SR/F App (NextGen) - API
Post by: remmie on November 06, 2019, 04:09:34 PM
Wow!! Excellent progress. Looks very very nice.
Title: Re: SR/F App (NextGen) - API
Post by: Hans2183 on November 06, 2019, 04:59:54 PM
allright, that `get_history` command works as follow

https://mongol.brono.com/mongol/api.php?commandname=get_history&format=json&user=your_username&pass=your_password&unitnumber=your_unit&start=20190821&end=20190824

with a max of 2 days span. The data I get seems identical to that from last_transmit (only analog2 field is new)
Title: Re: SR/F App (NextGen) - API
Post by: bigmadf on November 06, 2019, 05:32:00 PM
Awesome work guys!
This was exactly what I wanted to trigger.
Title: Re: SR/F App (NextGen) - API
Post by: BrianTRice@gmail.com on November 06, 2019, 10:08:21 PM
It’s possible that get_history can pull earlier data with a url parameter.

This is really great progress.

I’ve heard some indication that Zero isn’t jealous of or even greedy with this data, and clearly this is about users getting more power and access to their own data, so I wouldn’t expect too much trouble.

Plus if anyone at Zero makes a stink, we have data protection laws like GDPR that now apply in the EU which provide standing in court.
Title: Re: SR/F App (NextGen) - API
Post by: stevenh on November 06, 2019, 11:22:40 PM
It’s possible that get_history can pull earlier data with a url parameter.

This is really great progress.

I’ve heard some indication that Zero isn’t jealous of or even greedy with this data, and clearly this is about users getting more power and access to their own data, so I wouldn’t expect too much trouble.

Plus if anyone at Zero makes a stink, we have data protection laws like GDPR that now apply in the EU which provide standing in court.

Yep, it works.  I pulled all the data from before I got the bike to present and put the mileage, latitude and longitude into a CSV by date.  I was bummed to see there was no location data other than the bikes birth in california and the data since I got the bike in early July.  None of the data between those times seemed to exist.  I pulled the Lat/Long data into Google Maps, pretty cool.  Thanks for the reverse engineering!  I have a simple c# console app to query and parse data by date over a longer period of time and save it to a CSV if anyone is interested.

Steve
Title: Re: SR/F App (NextGen) - API
Post by: remmie on November 07, 2019, 03:58:09 AM
Definitely interested :)

I also pulled all the logs 2 days at a atime and got about the same info as you. A few locations in california and then the next is from my dealers location.
Would have been cool to have seen the travel across the ocean (to the NL)
But they disconnect the 12V lithium battery during transport so that means also no location updates during that time.

Very cool to see all the locations where the bike has been. I use GPS visualiser to generate maps from the csv data. (see attached)
Also elevation profiles can be made with this piece of SW
Title: Re: SR/F App (NextGen) - API
Post by: Hans2183 on November 07, 2019, 02:48:46 PM
Nice Remmie and Steven! I just realised my data didn't look right cause I picked the date it was delivered, ready at the dealer but I only picked it up a month later :-). Glad to see it working. 
Title: Re: SR/F App (NextGen) - API
Post by: stevenh on November 07, 2019, 09:02:18 PM
FYI, when I query for two days, I just get the first one.  I backed my app off to just doing one day at a time and it gets all the data.

Steve
Title: Re: SR/F App (NextGen) - API
Post by: remmie on November 07, 2019, 09:15:59 PM
I think that’s because you don’t specify a time and it assumes a time of 0:00 for both.

Then you ‘think’ you query 2 days but in reality you query just one. 20191101 and 20191102 would be interpreted as 0:00 on nov 1st up to 0:00 on nov 2nd which is exactly 1 day instead of 2

When I downloaded my logs I entered 20191101 as start and 20191103 as end date and got 2 days worth of data, for November 1st and November 2nd

By adding four digits for time (201911010800 for 8 am November 1st 2019) you can even specify timeframes per day
Title: Re: SR/F App (NextGen) - API
Post by: remmie on November 07, 2019, 09:17:30 PM
By the way, Hans, if you could incorporate Stevens query for dowloading logs into your app that would be a very nice addition to your app  ;D
Title: Re: SR/F App (NextGen) - API
Post by: stevenh on November 07, 2019, 10:44:56 PM
I think that’s because you don’t specify a time and it assumes a time of 0:00 for both.

Then you ‘think’ you query 2 days but in reality you query just one. 20191101 and 20191102 would be interpreted as 0:00 on nov 1st up to 0:00 on nov 2nd which is exactly 1 day instead of 2

When I downloaded my logs I entered 20191101 as start and 20191103 as end date and got 2 days worth of data, for November 1st and November 2nd

By adding four digits for time (201911010800 for 8 am November 1st 2019) you can even specify timeframes per day

Yes, I was using just the day as in 20191101 -> 20192203 and I just got data for 20191101 in my case.  If I queried 20191101->20191102, then 20191102->20191103 I got both days data...  Good stuff...

Steve
Title: Re: SR/F App (NextGen) - API
Post by: Hans2183 on November 15, 2019, 09:59:47 PM
iOS version is getting there, I have the requests but still have to make the proper layout

(https://i.ibb.co/kg0SH67/Screen-Shot-2019-11-15-at-16-10-25.png) (https://ibb.co/kg0SH67)
Title: Re: SR/F App (NextGen) - API
Post by: Hans2183 on November 19, 2019, 02:41:35 AM
Finally Apple approved my zero app, available from https://apps.apple.com/be/app/zerong/id1488172044

Again it's open source so feel free to contribute, even by just creating feature requests! Check project website here https://bitbucket.org/cappelleh/zeronextgen/src/master/

I already noticed some issues with dark mode so I'll be fixing those. I'm and Android developer but an iPhone user so I'll be using the iOS version myself.

Some things coming soon are history queries, reference manual, maybe a range estimator and customizable notifications.
Title: Re: SR/F App (NextGen) - API
Post by: BrianTRice@gmail.com on November 19, 2019, 03:34:44 AM
Nice work! I know what a hassle it is getting Apple's approval.

I'll see whether I can contribute, once I have an SR/F-ish bike to test with.
Title: Re: SR/F App (NextGen) - API
Post by: remmie on November 19, 2019, 04:16:47 AM
Excellent work Hans,

I can confirm it works when I fill in my userdata :)
Unfortunately I don't think I'm able to contribute to the coding itself.
The dark mode is indeed not quite dark LOL  (as you already explained)

Keep up the good work :)
Title: Re: SR/F App (NextGen) - API
Post by: Hans2183 on November 21, 2019, 02:25:53 AM
dark mode should be fixed now. I'm finishing up location and range estimator. Next I'll work on the custom notifications and then I can look into getting a history query on the map.
Title: Re: SR/F App (NextGen) - API
Post by: Hans2183 on November 23, 2019, 06:32:55 PM
And another update pending. This time location on map and range estimator are in place.

(https://i.ibb.co/PMJztyz/Screenshot-2019-11-23-12-39-03.png) (https://ibb.co/HCRpXyp)
Title: Re: SR/F App (NextGen) - API
Post by: remmie on November 23, 2019, 08:04:33 PM
Excellent addition Hans,

Maybe you could also show the range on the map by projecting a circle with the midpoint on the current location and the range radius projected around it. This would represent the maximum where you could go. And then you can instantly see whether you can make your destination or if you need to conserve power if it is right at the edge of the circle

something like this :
(https://i.imgur.com/fVeYwq2.png)

another improvement possibility : My street adress is cut off short while there is space to the left to show the entire adress :)
Title: Re: SR/F App (NextGen) - API
Post by: Hans2183 on November 23, 2019, 09:06:26 PM
The address issue is resolved, or at least improved in this pending update.

That range circle on map is a great idea! I'll implement that
Title: Re: SR/F App (NextGen) - API
Post by: Crissa on November 24, 2019, 06:34:03 AM
I'm not sure how good range circles would be, since because of roads things can be weird places.  Scotts Valley (about six miles from me) is a 20% round trip but Santa Cruz (more than ten miles from me) is a 25% round trip.

A circle is a start, I suppose.  I'd kinda want pins on the map telling me how far (how much juice I used) I really did go so I'd identify which towns are how much percent from me in total.

That's sorta what I'm doing now?  It takes me n% to go from waypoint one to to waypoint two.  So, 25% charge to make it from the bottom to the top of the hill (that's what we call going over the mountains from Santa Cruz to San Jose) but only 10% back down.  45% to get from home to anywhere I've gone in San Jose so far (I've gone as far as downtown).

A way to just have the app track that would be... Well, I don't have an SR/F, but knowing how much a mountain pass takes is kinda key to riding electric, right?

-Crissa
Title: Re: SR/F App (NextGen) - API
Post by: remmie on November 24, 2019, 11:03:57 PM
a range circle certainly isn't the "holy grail" of projecting what places you can reach. In fact, you would normally never reach the edge of the circle because roads by definition are not straight. Also the range is so dependent on road type, elevation but mainly on speed that it is impossible to have any accuracy in a range circle. Also, when you're on one side of a canyon and want to get to the other side (say 2 km away) it could take you more than 50 km of roads before you could get there.

But it gives you an IDEA of how far you could go at a single glance. And it's fairly easy to implement (I think) and I think it is a nice feature :)

The website below used to have a feature where you could give in a position on the map and a range and it would calculate the given range on all roads availlable in all directions. That was much more accurate in seeing where you could go with a certain range. Unfortunately google prices for such request were too high at a certain point and he had to stop the service. in a nutshell it was :  "Instead of a radius as the crow flies, can you do a radius as the car drives"

https://www.freemaptools.com/how-far-can-i-travel.htm (https://www.freemaptools.com/how-far-can-i-travel.htm)
Title: Re: SR/F App (NextGen) - API
Post by: Hans2183 on November 24, 2019, 11:46:32 PM
drawing the circle on map with a given radius based on current SOC and settings from the estimator tool was easy

(https://i.ibb.co/Q6srcCW/Simulator-Screen-Shot-i-Phone-11-Pro-Max-2019-11-23-at-23-45-49.png) (https://ibb.co/4jBPfYb)

But indeed that is a straight line. For more data on what you passed as a rider we can query on this api using time but not based on position. So it would require getting data for a day first and then filter within that data for positions. Something must be possible but we'll have to think it through.

For 2 points on a map I also can get the distance but again that distance is in a straight line. Not sure what APIs exist to get actual routes.
Title: Re: SR/F App (NextGen) - API
Post by: remmie on November 25, 2019, 12:16:22 AM
https://developer.tomtom.com/products/ev-route-planning-use-case (https://developer.tomtom.com/products/ev-route-planning-use-case)

this API from TomTom looks like it has a lot of nice features specially for EV's.
I have no idea wheter it is free or payed.

quote : POST GET Calculate Reachable Range
This service calculates a set of locations that can be reached from the origin point, subject to the available fuel or energy budget that is specified in the request.
Title: Re: SR/F App (NextGen) - API
Post by: remmie on November 25, 2019, 02:16:53 AM
I registered for an API key which was free and if i read it correctly you can do 2500 transactions per day for free.

i used an example request around my location and got a set of coordinates in JSON format, i then converted that to csv coordinates with an online converter (took some tries and deletion of some data of the JSON response) and then fed the data into GPSvisualizer. This got a nice looking boundary box of reachable range. (see picture). i reckon that a proper programmer should not have to take all these side steps, LOL

The request even contains a variable for energy consumed per 100 km which we should adapt to the SR/F.  It is in the form of
{"key":"constantSpeedConsumptionInkWhPerHundredkm","value":"50,8.2:130,21.3"}
which I read to be "at 50 kph the consumption is 8.2kWh per 100 km and at 130 kph 21.3 kwH per 100 km"
This would be a lot lower for the SR/F. Having the current Wh/km readout on the dash and going a constant 50 and 130 should be easy to do. Or maybe we can just enter the ranges Zero claims on their website

another parameter is the current available kwh : energyBudgetInkWh=12 which is easily determined by max kwh (12.6 for the SR/F) and the current SOC. So when the SOC is getting lower the boundary box would get smaller

the full command i used was (api key removed for obvious reasons :)
curl -X GET "https://api.tomtom.com/routing/1/calculateReachableRange/51.500000,4.700000/json?\
> energyBudgetInkWh=12&report=effectiveSettings\
> &routeType=eco&traffic=true&avoid=unpavedRoads&travelMode=car&vehicleMaxSpeed=120\
> &vehicleCommercial=false&vehicleEngineType=electric\
> &constantSpeedConsumptionInkWhPerHundredkm=50%2C8.2%3A130%2C21.3\
> &key=xxxxxxxxxxxxxxxxxxx" -H "accept: */*"

Title: Re: SR/F App (NextGen) - API
Post by: Hans2183 on November 25, 2019, 04:06:05 PM
nice find Remmie, looks promising. I'll look into adding that to the app.
Title: Re: SR/F App (NextGen) - API
Post by: ben.m on November 27, 2019, 02:28:51 PM
Just downloaded you app yesterday, and a major update this morning, on iPhone.

Great job ! Continue that way.
The only thing i noticed is you calculation is very very optimistic ! Your estimated range is twice the reality range.
Title: Re: SR/F App (NextGen) - API
Post by: Hans2183 on November 27, 2019, 02:51:52 PM
Thanks Ben

Did you play with the options that cause penalties on the range? Like riding style and temperature? There is a set of values I use as a baseline based on the road type. That then is adjusted based on charge and penalties given for dynamic riding style, hills in landscape and/or temperatures.

Code: [Select]
Fixed value for each scenario:

city = 287 km
road = 174 km
mixed city/road = 216 km
highway = 143 km
mixed city/highway = 193 km

Penalty (percentage off) based on:

riding style

conservative (as is)
agressive -10%

landscape

flat (as is)
hills -10%

weather

warm = as is
mild = -5%
cold = -5%

The initial numbers are based on the values in the Zero app. So it all seems to match up pretty wel. Just checked city scenario now. Always possible that I messed up a number.

I have all penalties on at the moment and it seems to match what I get in actual range. It is cold and hilly over here.

I could make those initial numbers configurable? Or have a custom road type where you pick what range you think it makes for your style of riding.

Do you use it in miles? Maybe I have an issue in conversion.

The circle on the map is for sure way too optimistic. It's using the parameters from the range estimator but it's just a straight line and in reality you have to follow roads. That's what remmie was looking into with the more realistic route calculations.
Title: Re: SR/F App (NextGen) - API
Post by: ben.m on November 27, 2019, 03:07:34 PM
Actually the circle is pretty good for me and the estimated range is way too optimistic.
Try to post attachments to show you.
It shows me 48 kms with agressive/hills/cold, in real life i can do less 40kms with very conservative driving, 20°C and almost flat road with these 31% left ;)
Title: Re: SR/F App (NextGen) - API
Post by: remmie on November 27, 2019, 03:22:02 PM
Then you are probably better off choosing road instead of road/city.
City is not constant 50 kph but way less (stop and go traffic) And a road city combination would in my book be 50% road 50% city.

Because range is so highly dependent on speed, it takes some learning to choose the right figures.

Btw Hans, is it possible to have the options for road/city/highway etc in a sort order that would be from highest range to lowest instead of alphabetical ?
Title: Re: SR/F App (NextGen) - API
Post by: ben.m on November 27, 2019, 03:35:53 PM
For sure i know that range is subject to a lot of things. But after almost 4000 kms on that bike i know it enough.
I tried a lot of combinations in the app, i can do only half the estimated range, whatever the combination.
Title: Re: SR/F App (NextGen) - API
Post by: Hans2183 on November 27, 2019, 06:14:38 PM
thanks for the feedback guys

@remmie: I'll change the order from highest to lowest range in the next update

@ben.m: I'll make you a "custom" option in that spinner where you can just give a max range number yourself and that will calculate with the current percentage.
Title: Re: SR/F App (NextGen) - API
Post by: ben.m on November 27, 2019, 07:13:01 PM
@ben.m: I'll make you a "custom" option in that spinner where you can just give a max range number yourself and that will calculate with the current percentage.

Don't waste your time for that, when you know your bike it's useless to have a tool to estimate the range  ;)
And we have to let our brains do a part of the job  8)
Title: Re: SR/F App (NextGen) - API
Post by: Hans2183 on December 13, 2019, 04:47:12 PM
Just pushed another update to the Google Play store (iOS will follow later this week) to add a date selection below map and then it shows the registered positions for that date as a polyline.

To keep it simple I've limited to single day selection and it will fetch for that date from 00:00:00 to 23:59:59. You can however select more dates in a row and the data will build upon the map. There is clear option to remove previous points.

Added screenshot is just demo data so not that useful.

(https://i.ibb.co/9ZwzSdx/Screenshot-1576229423.png) (https://ibb.co/km3kvPL)

For mine I noticed that it never registered in California. Instead the first valid points are from the center of the map (0,0) and then a straight line to the dealer where it probably got activated.

Didn't get to the notifications yet but that is a feature I could use myself to have custom notifications based on whatever property is available.



Title: Re: SR/F App (NextGen) - API
Post by: electrik on December 15, 2019, 10:28:07 PM
Guys,

I just bought an ex-demo SRF yesterday and trying to register on nextgen app but I'm getting an error saying that I need to be connected to motorcycle via bluetooth. I am already connected to the motorcycle but no matter what I do, the app won't let me register.

I'm 100% sure that my mobile device is connected to motorcycle via bluetooth. When not connected, it simply says I need to be connected but when connected, it says the same thing but in a longer version. My guess is someone at the dealership already tried to registered with my VIN. I dropped a message to Zero but just checking if anyone else had this issue.

Cheers
Title: Re: SR/F App (NextGen) - API
Post by: Hans2183 on December 15, 2019, 10:50:18 PM
Haven't tried out how to reset or change the password yet. And you have the added difficulty that the vin is probably already linked to an account. So once you know how I'm very interested.

I guess your beste chance is to call zero and ask them how to do this step by step.

Also congrats ot the bike!
Title: Re: SR/F App (NextGen) - API
Post by: ben.m on December 16, 2019, 02:22:29 PM
Yes they need to link your vin to you account.
I had the same trouble when received mine, i had to wait until zero did something, it's not something you can do on your own ;)
Title: Re: SR/F App (NextGen) - API
Post by: azymuth on December 16, 2019, 08:28:42 PM
Hi everyone,

I have exactly the same problem.
I had successfully registered an account for the first time. But since I changed my phone, it's impossible while I'm well connected to the bike in Bluetooth  >:(

However, my account works fine with this awesome ZeroNG app  ;)
Title: Re: SR/F App (NextGen) - API
Post by: Hans2183 on December 16, 2019, 08:33:41 PM
Changing phone shouldn't be an issue. I've swapped devices for testing. All you need is to remember your username and password and use these to log on to the app. That will work.

It's strange that the app doesn't have a "change password" option whatsoever. All you can do is register or login and if you're not connected it will prompt you to connect to the bike first. I had no clue what the next steps are if you don't have credentials and a used bike but from what I understand here you have to contact Zero directly.
Title: Re: SR/F App (NextGen) - API
Post by: azymuth on December 16, 2019, 08:51:07 PM
My username and password are Ok since all is good with your app "ZeroNG" ;) And I'm connected to my bike, the "blue" Bluetooth icon is ON ! (my bike is a new one)

Thank you Hans2183 for your app ;)
Title: Re: SR/F App (NextGen) - API
Post by: Hans2183 on December 16, 2019, 08:57:42 PM
my pleasure, this community discovered it was possible to begin with.

But now I struggle to understand your situation. So you have a new bike? with your previous phone you could register for an account using that bike? And now with a new phone you can't log in to the app connecting it to that same bike? Or did the bike also change? 

edit: Can't really test it right now since my bike is back at Zero to get it fixed. But I'm pretty sure I had both my Android and an iOS test device connected to the same bike without issues. Login and out is possible from my same iOS daily device without connection but that's probably just because it already has all the preferences required.

Make sure you have the login view and not the register view. For Android you can toggle that in the top right corner. 

Title: Re: SR/F App (NextGen) - API
Post by: azymuth on December 16, 2019, 09:29:50 PM
I never noticed that you could toggle "login" and "register" in the top right corner  :-[

I have just managed to connect  :) I was probably in "register" mode !

Thank you so much Hans !
Title: Re: SR/F App (NextGen) - API
Post by: Hans2183 on December 16, 2019, 09:31:34 PM
Glad it worked out  8). The app has some strange logic here and there.

The others have a real issue I think since they have a bike (VIN) that was linked to another account before. For that I can understand Zero has to do this manually to prevent theft.
Title: Re: SR/F App (NextGen) - API
Post by: electrik on December 16, 2019, 09:38:01 PM
Thanks guys. I suspected the same. Waiting for zero's response.
They could do better with the app though. The error messages don't give much information plus login should be default, not register.
Title: Re: SR/F App (NextGen) - API
Post by: ben.m on December 16, 2019, 10:59:45 PM
Just updated the app, i went to the history thing in location tab. (iOS)
I can't have something working with more than a few days, is it normal ?
If i put a few months away to see all history, not working...
For the last days it's great !

EDIT :
I was wrong, i just realize that every day you select add the daily trace to the map.
I found that the activation on my bike tracking system was done a few days after i had it, that's why i couldn't sync the zero app with the bike.
I had the bike on August 3 and the first point in the middle of nowhere is on August 10
Title: Re: SR/F App (NextGen) - API
Post by: Hans2183 on December 17, 2019, 01:22:28 PM
Indeed this first implementation just allows selection for a single day and then it will fetch that information and plot it on the map. When you change date the previously plotted route remains so you could select multiple days to combine information.

In future updates I'll probably work on some options like having it select a full month at once. But I want to get the notifications implemented first since those in the official app are... nuts.
Title: Re: SR/F App (NextGen) - API
Post by: electrik on December 18, 2019, 03:55:23 AM
Called Zero EU support this morning quoting my VIN number and he confirmed that it was already registered to another account. He put a request to delete from the database.
I tried registering again after 4-5 hours and I could register and check status remotely.

I was expecting to have a longer call but <5 mins with CS is a big ++

Secondly, I noticed the "deregister" option in the account section. I guess that will deregister VIN from account, if anyone is looking. I haven't tried it myself.
Title: Re: SR/F App (NextGen) - API
Post by: BrianTRice@gmail.com on December 22, 2019, 06:50:17 AM
This is now referenced in a stub article on the unofficial manual: https://zeromanual.com/wiki/Gen3/Cloud_Data_Service
Title: Re: SR/F App (NextGen) - API
Post by: Hans2183 on January 06, 2020, 04:09:19 PM
This is an OS project for Tesla, just for inspiration https://github.com/adriankumpf/teslamate
Title: Re: SR/F App (NextGen) - API
Post by: BrianTRice@gmail.com on January 07, 2020, 03:40:23 AM
This is an OS project for Tesla, just for inspiration https://github.com/adriankumpf/teslamate

Oh, that is inspiring, thank you. Grafana is an interesting choice for driving dashboard displays; I'll look into it to see whether I can put something sensible together for a Zero.
Title: Re: SR/F App (NextGen) - API
Post by: i550 on April 07, 2020, 06:45:25 AM
I’ve been trying to utilize the quarantine time for more than sitting around and decided to start a web app project for the cloud data on my zero bike, by building on the api discovery from this thread.  I’ve been working on both the code and the drawings off and on, over the last couple weeks.  Besides having to finish the images (please don’t judge the draft SRF image, still a work in progress),

I’m running into dead ends finding any documentation on the api.  As well as issues with contacting the servers in modern restful manner.  I was shocked to see that passwords are sent in the clear. Then, also surprised that the site has a poorly defined server configuration for access to data, that restricts async calls from the browser, due to CORS being setup in an old fashioned manner.   Which means I won’t be able to make standard fetch calls, but will have to hack a script to download the JSON file locally periodically until they change their servers permissions.

It would also be great to have access to the rest of the data on the bike that is also available via the app over bluetooth.  Like ride mode and other things.  For now I’ve gotten the data that is available mostly parsed and converted to imperial, except for the fields in yellow. 

Does anyone have an idea what these are and the potential values for them could be?

Title: Re: SR/F App (NextGen) - API
Post by: remmie on April 07, 2020, 01:16:05 PM
Nice work i550 !

As for the yellow items.
* Unit type is 5 with me as well, dont know what it means though, it could be related to the bike (SR/F) or to the GPS/GSM unit or maybe even to the use of KM or Miles. Mine is in km and the milage figure is correct for km which would imply that unit type is not for km/miles
* Unit model is 6 with me as well, if it would relate to the bike : mine's a SR/F
* Response is also 0 with mine. no idea what it means
* Reason is also 2 with mine. no idea
* Logic state is 2 with mine instead of 1 in yours. Mine is keyed off?
* Analog has been 0.09 with mine always. It think it is an unused analog input. It is named analog1 instead of analog
* Color is 6 with mine instead of 5 in yours. I have a boardwalk red SR/F


There are also a couple of items in the JSON response that are not visible in your webpage (maybe on purpose?)
* driver, 0 in my case
* gps_valid, 0 in my case (sitting in the garage with a reinforced concrete ceiling
* shock, 0 in my case (which is a good thing :) )
* ignition, 0 in my case keyed off in the garage
* door, 0 in my case (figures, because it has no doors, LOL. Or is does the storage compartment have a door, or is that a lid, ;) )
* hood, 0 in my case
* volume, 0 in my case
* water_temp, "" in my case which makes sense
* oil_pressure, 0 in my case which also makes sense
* siren, 0 in my case (it has none)
* lock, 0 in my case
* int_lights, 0 in my case
* datetime_utc, 20200405201257
* datetime_actual, 20200407061530
* perimeter, "" in my case
* tipover, 0 in my case (which is good !)

Of those last batch I think only gps_valid, ignition, shock and tipover would be helpfull for your page, maybe make a fourth page with the all the unknown/unused values, just for info if someone sees a use for it.

Other than that : Great work

As far as accessing the data that Nextgen App has like riding modes etc, that information is only available via bluetooth, not through the web.

Title: Re: SR/F App (NextGen) - API
Post by: i550 on April 07, 2020, 10:38:52 PM
Thanks Remmie! 

I've enjoyed the iOS app as well. 

My plan for this project is to run it off a raspberry pi in my home office on a wall mounted display as a dashboard for my bike.  Maybe also package it in an electron app, like slack, so it can run on my laptop and desktop.

I may work on adding gpx stored paths in a local db. to store rides in the future as well.

As for the unused data in the json file, I did ignore the things that seemed like template fields from cars or trucks, such as door, hood, water and oil_pressure.  Do you know if field such as siren, driver, shock, ignition, volume, lock, int_lights, perimeter are useful from the file?

Comments inline below:

Nice work i550 !

As for the yellow items.
* Unit type is 5 with me as well, dont know what it means though, it could be related to the bike (SR/F) or to the GPS/GSM unit or maybe even to the use of KM or Miles. Mine is in km and the milage figure is correct for km which would imply that unit type is not for km/miles

[i550]  Agree, everything seems to be in metric, which makes conversion math easy.  I assumed that unit type had to do with the gps unit setting or model.  Leaves the question, is the unit being referenced the GPS receiver or the bike itself?

* Unit model is 6 with me as well, if it would relate to the bike : mine's a SR/F

[i550]  Mine is 6 and a SR/F as well.  Makes me wonder if 0-5 are the previous models, such as the fx.

* Response is also 0 with mine. no idea what it means
* Reason is also 2 with mine. no idea
* Logic state is 2 with mine instead of 1 in yours. Mine is keyed off?
[i550] Hmmm, weird, wouldn't 0 be off?  Could it be a error status or logic board status?

* Analog has been 0.09 with mine always. It think it is an unused analog input. It is named analog1 instead of analog
[i550]  These are the fields (response, reason, logic) I assumed would be the hardest to make sense of without proper api documentation, such a shame, I assume this would be good information for owners to have to be proactive on bike maintenance.

* Color is 6 with mine instead of 5 in yours. I have a boardwalk red SR/F
[i550]  That is odd about the color, I have a red SR/F as well, and my color field is 5, can other collaborate that discrepancy as well?


There are also a couple of items in the JSON response that are not visible in your webpage (maybe on purpose?)
* driver, 0 in my case
[i550]  Same for me, I was really curious what this field could possibly mean.

* gps_valid, 0 in my case (sitting in the garage with a reinforced concrete ceiling
* shock, 0 in my case (which is a good thing :) )

* ignition, 0 in my case keyed off in the garage
[i550]  Have you seen this go to 1?

* door, 0 in my case (figures, because it has no doors, LOL. Or is does the storage compartment have a door, or is that a lid, ;) )
[i550]  lol, I laughed when I saw this field and others like it, as well.  I shrugged it off as the zero guys working off some template that they were forced into by the gps manufacturer.

* hood, 0 in my case
* volume, 0 in my case
* water_temp, "" in my case which makes sense
* oil_pressure, 0 in my case which also makes sense
[i550]  All the same for me.

* siren, 0 in my case (it has none)
[i550]  I was wondering if the SR/F alarm would trigger this one.

* lock, 0 in my case
* int_lights, 0 in my case
* datetime_utc, 20200405201257
* datetime_actual, 20200407061530
* perimeter, "" in my case
* tipover, 0 in my case (which is good !)
[i550]  Very good. :)

Of those last batch I think only gps_valid, ignition, shock and tipover would be helpfull for your page, maybe make a fourth page with the all the unknown/unused values, just for info if someone sees a use for it.
[i550]  Hmmm, good point, I'll add them, I wanted to build in more conditional logic to convert the data into layman's terms for as much as possible.  Seems I'll have to guess for the rest.


Other than that : Great work
[i550]  Thanks!  Love the iOS app too.

As far as accessing the data that Nextgen App has like riding modes etc, that information is only available via bluetooth, not through the web.
[i550]  That does suck, so much of this data and cloud experience could be improved and become interactive for owners with not only the bike but zero motorcycles themselves. If they updated their approach they could start the process of building a vendor/owner community that rivals Harley. 

That being said, please don't get me wrong, I love the bike and what abilities this provides. Huge leap forward in tech and tinkering.  :)


Thanks for the help.


Title: Re: SR/F App (NextGen) - API
Post by: Hans2183 on April 09, 2020, 12:51:50 PM
Nice looking dashboard @i550

I also have the red one as Remmie does and I get color 2 :o . My output looks like this (mostly, altered some values like position, unit and VIN).

Edit: The mileage on mine is always around 200-400km behind of the actual value. And often it takes a while for this response to pick up the charging state. I've seen logic state and reason change over multiple requests but never bothered thinking it through. Don't think I ever saw another value for analog1.

Some values are obviously just not present, like door and hood.

It would be interesting to see the result of someone with an SR/S just to know if that changes anything.

Code: [Select]
{
  "unitnumber": "123456",
  "name": "538ZFAZ74LCK00000",
  "unittype": "5",
  "unitmodel": "6",
  "mileage": "4875.26",
  "software_version": "190430",
  "logic_state": "2",
  "reason": "2",
  "response": "0",
  "driver": "0",
  "longitude": "2.349014",
  "latitude": "48.864716",
  "altitude": "52",
  "gps_valid": "0",
  "gps_connected": "0",
  "satellites": "0",
  "velocity": "0",
  "heading": "168",
  "emergency": "0",
  "shock": "",
  "ignition": "0",
  "door": "0",
  "hood": "0",
  "volume": "0",
  "water_temp": "",
  "oil_pressure": "0",
  "main_voltage": 13.18,
  "analog1": "0.09",
  "siren": "0",
  "lock": "0",
  "int_lights": "0",
  "datetime_utc": "20191116090806",
  "datetime_actual": "20191116210319",
  "address": "Paris",
  "perimeter": "",
  "color": 2,
  "soc": 64,
  "tipover": 0,
  "charging": 1,
  "chargecomplete": 0,
  "pluggedin": 1,
  "chargingtimeleft": 120
}

Title: Re: SR/F App (NextGen) - API
Post by: i550 on April 09, 2020, 09:45:56 PM
Thanks Hans2183

Oddly, I just noticed that the color field on mine changed today and now says 2 as well.  Seems they may be updating the api.

It would be good to see what an SRS looks like, as well as a blue SRF.

The mileage in the json file is also behind the real odometer on my bike too, by about 50ish miles or so.
Title: Re: SR/F App (NextGen) - API
Post by: i550 on April 30, 2020, 11:28:13 PM
I'm still looking for details on the other fields.  Or others with different colors and hopefully some SR/S's too.

Here's the most recent dashboard I have, I drew half the icons and the bike, but also used font awesome for other icons.  I kept everything a SVG to make sure scaling of screen size wouldn't impact the clarity of the images and cause them to get grainy.

I also tried to make the GPS Information more visual by including a circular satellite and heading imagery.  The arrow points the actual heading angle and the satellites in the circle will update to match the number connected from the json file.

I was hoping to find a way to get the ride data (power and lean) from the app as well. 

So was wondering since they oddly won't share the raw data in the app, if it can at least be seen over the Bluetooth connection as well?  Have anyone been able to see a trace from the Bluetooth connection?
Title: Re: SR/F App (NextGen) - API
Post by: BrianTRice@gmail.com on May 01, 2020, 12:39:30 AM
I wish I had a bike to test this with, but what I've heard from an SR/S owner is that the app doesn't work for them. I think there's an authentication issue still present that makes this less useful than it might be.
Title: Re: SR/F App (NextGen) - API
Post by: gadgetgirl on May 01, 2020, 10:49:44 PM
Thanks Hans2183

Oddly, I just noticed that the color field on mine changed today and now says 2 as well.  Seems they may be updating the api.

It would be good to see what an SRS looks like, as well as a blue SRF.

The mileage in the json file is also behind the real odometer on my bike too, by about 50ish miles or so.

I have a blue SR/F, and I get 2 for the color too.
Title: Re: SR/F App (NextGen) - API
Post by: Hans2183 on May 05, 2020, 02:09:55 AM
they probably didn't bother implementing the colors then, just like many of the other params.
Title: Re: SR/F App (NextGen) - API
Post by: mcvl on June 05, 2020, 02:53:15 AM
HI,good job,i give you report from SR/S blue in europe for your projet:
[{"unitnumber":"xxxxxxx",
"name":"538ZFxxxxxxxxxxxx",
"unittype":"5",
"unitmodel":"6",
"analog1":"0.09",
"mileage":"10.24",
"software_version":"190905",
"logic_state":"1",
"reason":"5",
"response":"0",
"driver":"0",
"longitude":"2.0335",
"latitude":"42.7859",
"altitude":"83",
"gps_valid":"1",
"gps_connected":"1",
"satellites":"6",
"velocity":"0",
"heading":"36",
"emergency":"0",
"shock":"",
"ignition":"0",
"door":"0",
"hood":"0",
"volume":"0",
"water_temp":"",
"oil_pressure":"0",
"main_voltage":13.18,
"siren":"0",
"lock":"0",
"int_lights":"0",
"datetime_utc":"20200604152748",
"datetime_actual":"20200604152745",
"address":"Le Barcarès,
 Rue xxxxxx",
"perimeter":"",
"color":2,
"soc":75,
"tipover":0,
"charging":0,
"chargecomplete":0,
"pluggedin":0,
"chargingtimeleft":0}]
Title: Re: SR/F App (NextGen) - API
Post by: Hans2183 on June 08, 2020, 11:55:25 AM
Congrats on the SR/S and thanks for reporting your output. Seems like you have the same color and even same model numbers. So that would indicate they didn't implement that part.

The only way to extract that information would be from the Serial number then. What are the next 2 digits in yours? For SRF we have the below sequence:

538 = Zero
Z = Z4 - FST platform
FA = 20 MY SR/F
Title: Re: SR/F App (NextGen) - API
Post by: oli on June 09, 2020, 03:54:06 AM
Thank You for this Work. Now i can integrate my Zero in Home Assistant  8)
Title: Re: SR/F App (NextGen) - API
Post by: markearth on June 21, 2020, 01:21:10 AM
Now i can integrate my Zero in Home Assistant  8)
Hi. Can you post your Home Assistant sensor config? I've tried to get this going with the following, but not working yet:

- platform: rest
    name: Zero
    resource: https://mongol.brono.com/mongol/api.php\?commandname\=get_last_transmit
    device_class: battery
    scan_interval: 60
    timeout: 30
    authentication: digest
    username: !secret zero_username
    password: !secret zero_password
    headers:
      User-Agent: Home Assistant
      Content-Type: application/json
      Accept: application/json
      unitnumber: !secret zero_unitnumber
    unit_of_measurement: %
    value_template: >-
      {% if value_json.zero[0].soc is defined %}
        {{ value_json.zero[0].soc }}
      {% else %}
        0
      {% endif %}
    json_attributes_path: '$.zero[0]'
    json_attributes:
      - address           
      - altitude           
      - analog1           
      - chargecomplete
      - charging           
      - chargingtimeleft
      - color               
      - datetime_actual
      - datetime_utc   
      - door               
      - driver             
      - emergency       
      - gps_connected 
      - gps_valid         
      - heading           
      - hood               
      - ignition           
      - int_lights         
      - latitude           
      - lock               
      - logic_state     
      - longitude       
      - main_voltage 
      - mileage         
      - name             
      - oil_pressure   
      - perimeter       
      - pluggedin       
      - reason           
      - response       
      - satellites       
      - shock           
      - siren             
      - soc               
      - software_version
      - tipover       
      - unitmodel   
      - unitnumber 
      - unittype       
      - velocity       
      - volume         
      - water_temp 
Title: Re: SR/F App (NextGen) - API
Post by: mcvl on June 26, 2020, 05:54:32 PM
with some delay last Vin number for SR/S blue 2020 :538ZFBZ71
Title: Re: SR/F App (NextGen) - API
Post by: Hans2183 on June 26, 2020, 06:02:30 PM
with some delay last Vin number for SR/S blue 2020 :538ZFBZ71

Thanks for posting this information. So breakdown would be:

538 = zero
Z = Z4 - FST platform
FB = 20 MY SR/S
Z7 = 40 kW
1 = check digit

while my SR/F starts with 538ZFAZ74

538 = zero
Z = Z4 - FST platform
FA = 20 MY SR/F
Z7 = 40 kW
4 = check digit
Title: Re: SR/F App (NextGen) - API
Post by: remmie on July 03, 2020, 04:28:31 PM
Hi Hans,

I don't know if you still have some time to develop your awesome ZeroNG app but I would have 2 (fairly simple?)  feature requests.

1) In the location tab when you have selected a date (or multiple dates) an indication of the total amount of km (or miles), based on the data points provided by the API. I know this is not the real actual driven distance as the points are a few minutes apart and are straight lines rather than following the road but still would be nice :)

2) place a distinctive dot (maybe red?) at the start and end of each day. So if you have a multiday trip you can clearly see each daytrip.

an example of both on the 2 attached pictures. first is your current app on the iPad, second is an example of how it could look with the 2 features included.  The trip is a 12 day trip through Europe featuring 12 days and almost 3900 km. and that leads to a third feature request :)

3) selecting multiple days to download from the server by setting a start date and end date and a download button. I know it can only be downloaded per day so it may require a timer which downloads a day per 1 or 2 seconds to not overload the server. Maybe also keeping the start and end date inside a single month could help to prevent server overload.
Title: Re: SR/F App (NextGen) - API
Post by: Hans2183 on July 03, 2020, 06:36:45 PM
Sure we can add some features. Always happy to get input.

1) Seems easy enough, just need to figure out how to display that information

2) That I would like myself since when you select multiple dates you quickly get lost in all the plotted tracks. The dots are a good start in case you're going round, never crossing the same point again. An alternative is to color each day/route in a slightly different (generated) color. Or well I could just combine the 2. I'll play with it and report back.

3) Download to a gpx format then? I"ll have to look into that but should indeed be possible.
Title: Re: SR/F App (NextGen) - API
Post by: remmie on July 03, 2020, 07:04:17 PM
Hans,

1) for iOs I think you can use this function, because you already have location points for the poly line points. :
https://developer.apple.com/documentation/corelocation/cllocation/1423689-distance

when you iterate through all the location points when generating the poly line, you can add the length of each segment into a global variable "total distance". When you select a new day it would just add that day's distance to the total, making a grand total of all the selected days.

2) yeah, both are good.

3) not what I originally meant but still a nice feature :) what I meant was, selecting a start and end date (so 2 date selectors) and displaying the route of all the days from start to end. But to get the data from the server you would have to do that day per day.
that was more because now I had to select 12 days in a row which was a real hassle (hahaha NOT). It would just make it a little bit easier. And also in my case you would see the start date and the end date of the vacation trip. Would make a nice Header picture of the photo album :)
Title: Re: SR/F App (NextGen) - API
Post by: Hans2183 on July 03, 2020, 07:24:02 PM
ok so 3) is for display on the map also but not having to select all dates in between. Got it.
Title: Re: SR/F App (NextGen) - API
Post by: Hans2183 on July 08, 2020, 11:37:24 PM
Android App has been updated with the colored routes and distance calculation. Haven't done the range selection just yet since I need to verify what times would work. Up next is updating the iOS app first.

(https://i.ibb.co/JpgGNc7/Screenshot-1594229559.png) (https://ibb.co/T0d7Zw8)

both Android and iOS app have 22 active users atm
Title: Re: SR/F App (NextGen) - API
Post by: BrianTRice@gmail.com on July 09, 2020, 12:03:26 AM
Nice work with the map plot!

I updated https://zeromanual.com/wiki/VIN_Guide with the SR/S codes (which were already available in Zero's English SR/S Owner's Manual).
Title: Re: SR/F App (NextGen) - API
Post by: Hans2183 on July 09, 2020, 12:28:00 AM
Ha good point about that owners manual. Didn't think of that. I'll keep that in mind when they announce the SR/X  8)

This update was surprisingly simple by the way. Great input from remmie giving these nice feature requests. And then code was just a random color instead of the fixed one to color the line. For distance there was a function to calculate the difference (in meters) between two points.

Getting more than one point at once I'll have to experiment a bit what time should be between requests and so on.
Title: Re: SR/F App (NextGen) - API
Post by: remmie on July 09, 2020, 01:03:10 AM
thanks Hans,

I have no android but this is exactly what i had in mind :)
The selecting of multiple days was the least "important" feature for me.
Title: Re: SR/F App (NextGen) - API
Post by: Hans2183 on July 09, 2020, 11:54:20 PM
just submitted iOS version to appstore. Users that have the test flight builds should already be able to update. The others will follow in a day or so. Typically doesn't take that long for apple since it's a fairly small app.

https://bitbucket.org/cappelleh/zeronextgen/pull-requests/10/ios-release-24/diff

(https://i.ibb.co/mHKwFmb/4-AD78-F9-A-BF49-46-F6-AE7-B-8-C4636-CBDAFE.jpg) (https://ibb.co/VvGZpdJ)

edit: @Remmie that screenshot was from an iPad right? I can see how it's easier to show routes on bigger screens. To be honest the iPad feature only is in the app because I forgot to delete it before publishing for the first time. And once uploaded with iPad features you can't remove it afterwards :D. Never tested it on iPad, probably should start doing that also.
Title: Re: SR/F App (NextGen) - API
Post by: remmie on July 13, 2020, 02:08:42 AM
Yes, correct Hans. My picture was made using an iPad. Your update with the colors and the distance works perfect (also on the iPhone). The trip op 3900 km was registered as 3100 km but that was to be expected as the points are each a (few) minutes apart and the distance calculation does that as the crow flies.

Still, great job :)
Title: Re: SR/F App (NextGen) - API
Post by: gb on October 14, 2020, 01:57:20 PM
Here's a working sensor config for home assistant :
Code: [Select]

- platform: rest
  name: zero srs
  json_attributes:
    - address
    - altitude
    - analog1
    - chargecomplete
    - charging
    - chargingtimeleft
    - color
    - datetime_actual
    - datetime_utc
    - door
    - driver
    - emergency
    - gps_connected
    - gps_valid
    - heading
    - hood
    - ignition
    - int_lights
    - latitude
    - lock
    - logic_state
    - longitude
    - main_voltage
    - mileage
    - name
    - oil_pressure
    - perimeter
    - pluggedin
    - reason
    - response
    - satellites
    - shock
    - siren
    - soc
    - software_version
    - tipover
    - unitmodel
    - unitnumber
    - unittype
    - velocity
    - volume
    - water_temp
  resource: https://mongol.brono.com/mongol/api.php?commandname=get_last_transmit
  headers:
    User-Agent: Home Assistant
    Content-Type: application/x-www-form-urlencoded
  payload: 'format=json&pass=xxxxxxxx&user=xxxxxxxx&unitnumber=xxxxxxxxx'
  method: POST
  value_template: '{{ value_json[0].soc }}'
  unit_of_measurement: "%"
  scan_interval: 300
Title: Re: SR/F App (NextGen) - API
Post by: jonblow on October 18, 2020, 05:12:29 PM
Sorry if this question has been posted before but I can no longer get my soc info on either app now, the official one in remote connection or the lovely ZeroNG app that I use a lot as a handy check to see if my bike charged overnight.
I think this functionality broke when I updated my srf to version 18.
Anyone else have this?
Title: Re: SR/F App (NextGen) - API
Post by: Hans2183 on October 18, 2020, 05:22:20 PM
Could be that they decided to break API since it was known here (and elsewhere). But then I would expect the official app to have an update also so theirs keeps working. Did you check if there is an update for the Official Zero app?

You could also try and execute the HTTP commands at the beginning of this thread manually in a browser to make sure the API remains.

I would try it myself but the OTA update to 18 failed on my bike and it doesn't work from the app either for the moment. If I get it updated I'll report back.
Title: Re: SR/F App (NextGen) - API
Post by: gadgetgirl on October 26, 2020, 12:46:03 AM
Does the app fail to show charging state with remote query too? I had this issue on my SR/F where I got responses in the API and app, but they weren’t updating. After reinstalling the app, unpairing/pairing with no fix, Zero support had me pull the fuse. That resolved it.

Just in case you need that: with the bike keyed off and key out, remove the CCM fuse (Fuse1) and reinstall the fuse. It’s on page 6.34 in the owner’s manual. It’s a bit of a pain to get to.
Title: Re: SR/F App (NextGen) - API
Post by: ms_smart on October 29, 2020, 12:31:09 AM
I have the same problem with V18. A HTTPS query returns soc=0. I don't think the API changed. It clearly says SOC=0. This is only true if in park state. If active, the API returns correct SOC. The problem immediately popped up after installing V18.

I have opened a ticket with Zero support.
Title: Re: SR/F App (NextGen) - API
Post by: gb on November 24, 2020, 03:57:21 PM
I see the same. Soc is 0 when bike is off, in the API response and in the ios app (which is consistent).
It started occuring since v18 update.
Title: Re: SR/F App (NextGen) - API
Post by: PaulZero on February 20, 2021, 11:15:00 PM
Anyone get any luck with Zero support on the SOC freezing or sitting at 0 since the v18 update?
Title: Re: SR/F App (NextGen) - API
Post by: Hans2183 on February 21, 2021, 01:01:20 AM
You can always try contacting them but I wouldn't expect anything useful from them on this. With done luck they fix it over a few months with another firmware release.
Title: Re: SR/F App (NextGen) - API
Post by: remmie on April 09, 2021, 02:52:50 AM
Hans, i see some requests on the ABRP (a better route planner) forum for support for Zero motorcycles.
I'm now discovering the ABRP a little better and it seems a very nice planner for electric vehicles. They even have a "live data" api where a secondary app (ZeroNG :) ) can upload SOC (and power and more) data to the ABRP servers so it shows in the app and it can dynamically update the calculated SOC on arrival.

I have really no idea what is involved in sending that data (and which data) to the ABRP planner but on a high level it works by generating a "token" in the ABRP app, that token is then used by to identify the vehicle. the ABRP already has a profile for Zero (in alpha development)

In order to use ZeroNG with ABRP it would require ZeroNG to update the SOC periodically in the background.
Consider this a feature request for the ZeroNG app :)


BTW i'm still on V17 firmware and SOC updating is still available and accurate. I've had a few prompts to update the firmware but i just dismiss them until Zero sorts out the mess they made with the remote function, they call it "effortless connection" LOL. effortless from Zero it seams. I REALLY cannot understand that it takes months and months for even a small company to revert firmwares to a previous correct working firmware. V18 and V19 both break the cellular connection.
Title: Re: SR/F App (NextGen) - API
Post by: Hans2183 on April 09, 2021, 05:08:44 AM
Hi Remmie I haven't used a better route planner so I'll have to check what and how. Should be doable to have just that token entered optionally by users and if in place push that information from a service in the background. Or even just on command depending on what works best. I'll look into it.

Yeah I wish mine was still on version 17. I kept it at that myself but then a dealer did the update for me to 19. He probably was just trying to be helpful. But since then the only working part of the remote Connect functions has been those gps points. All the other info is broken.

Zero will have a look at my bike next time it's at a dealer. I don't expect much from it since its clearly firmware related. Some are talking about a config field on ccm level that has to be updated to REG but mine is still on REG. I've seen other bikes with PEND but those don't even get GPS points logged.
Title: Re: SR/F App (NextGen) - API
Post by: Zelidar on April 09, 2021, 03:21:36 PM
... V18 and V19 both break the cellular connection.
Darn! I didn't know that, and I am now sorry to confirm, with V19.