ElectricMotorcycleForum.com
Makes And Models => Zero Motorcycles Forum | 2013+ => Topic started by: I973 on June 06, 2019, 02:05:56 AM
-
Hi everybody!
I'm new to this forum and to the Zero world, so let me do a quick introduction: End of 2018 I bought a new Zero SR 2018. I use it mainly for commuting and of course for some nice after-work tours. I very much enjoy this bike and until now everything works fine 8)
In my free time, I like to program Android apps, so I thought it would be a great idea to create an app for my Zero. What is the app about? It's about monitoring the charging state (remotely) and raise some triggers at some state of charge to carry out some kind of actions.
The name of the app is ZeroSpy and you can find a beta version here:
https://play.google.com/store/apps/details?id=com.bsc101.zerospy (https://play.google.com/store/apps/details?id=com.bsc101.zerospy)
How to use:
- Install the app on an Android mobile, open the app and connect it to your Zero (not SR/F) via Bluetooth. This device should already be paired with your bike. You should now see some values like state of charge and so on.
- Remember the AppID of this first installation, see screenshots.
- Install the app on a second device, navigate to the remote page and enter the AppID of your first installation. You are now able to remotely monitor the charging state of your Zero. The first installation sends the data to a cloud database from where the second installation reads.
- Triggers: You can define triggers (on the device connected to your bike) which execute when a specified SoC is reached. You can specify some URL which will be called. I use it this way: While charging, my Zero is plugged into a switchable power outlet, so I defined a trigger which turns off this power outlet at some SoC, for example 80% or whatever. So I can load to some level and automatically switch off the Zero. A second trigger calls a IFTTT webhook and this results in some notifications on my remote device. So while my Zero is charging in the garage, I do get notifications on another mobile phone.
Please note: This app is still beta, so there are probably still some bugs.
I would be glad if some of you would give it a try and provide some feedback! Thank you!
Boris
-
Wouldn't this require the bike to be connected to a android device at all times to make it work?
meaning.. if i want to have access to check status of the bike whenever/wherever i would need 2 android units with a internet connection as well as one of them having a constant BT link to the bike..
-
Exactly. As long as you want to use the remote feature, you'll have to connect one device to your bike and one device to check the charging status. When you don't need remote access anymore, just disconnect.
This is my use case:
I have an old Android mobile (which I do not need anymore for anything else) connected to my bike while it is charging in the garage. Then I use my 'everyday life mobile' to check the charging status from somewhere in the house or whereever. After charging, I just disconnect the old mobile.
-
Interesting. Now here is a challenge : can you change the max speed to a lower level than what the official app proposes ? Super bonus : can you increase max torque higher ?
-
Good idea ;) I will have a look, but I would assume that these values are limited by the bike and not by the app...
-
Nice work.
There are definitely caps that the MBB implements through the settings, but the official bluetooth interface might have further limitations. Or not!
Can you speak to how you worked out how to talk to the bike? I'm hopeful that some basic documentation can be had for the protocol - efforts in past apps have often used some shorthand to get their work done.
-
Thanks for creating this, Boris. I look forward to trying it out.
Can it run on Android tablets as well? I have an old Nexus 7 with GSM slot...
-
Thanks for creating this, Boris. I look forward to trying it out.
Can it run on Android tablets as well? I have an old Nexus 7 with GSM slot...
Hi togo,
It should also run on tablets, but I'm not sure if it is available for tablets in the PlayStore, I will check!
-
Can you speak to how you worked out how to talk to the bike? I'm hopeful that some basic documentation can be had for the protocol - efforts in past apps have often used some shorthand to get their work done.
Hi Brian,
I had a look at the original Zero app (the apk file), luckily it is not obfuscated, so it is quite 'readable'. The protocol itself is very easy, there are some magic bytes at the head and tail of a packet, there is a checksum and a body. The body contains a tag, that describes what is in the packet like 'version' or 'batterystatus', and what data in which order is in the body can be found in the disassembled apk file.
So, it was easier then expected ;)
-
Got it. I have performed similar inspection on the APK, but am not fluent in Android and short on time so I didn’t get far.
-
I see. There was one more thing: The Zero app includes some native C libraries with functions like 'GetBatteryPaket' which return the byte array one has to send via bluetooth. I used these native libraries in an own app, so I could call those functions to get the byte arrays I have to send to the bike to get the information I want.
-
Thanks for creating this, Boris. I look forward to trying it out.
Can it run on Android tablets as well? I have an old Nexus 7 with GSM slot...
Should be available for tablets in the PlayStore, please give it a try.Thanks!
-
Do I need a wifi or bluetooth plug-switch?
Thanks,
Giacomo
-
Do I need a wifi or bluetooth plug-switch?
No. It's using Zero's official Bluetooth interface that its own app uses.
I see. There was one more thing: The Zero app includes some native C libraries with functions like 'GetBatteryPaket' which return the byte array one has to send via bluetooth. I used these native libraries in an own app, so I could call those functions to get the byte arrays I have to send to the bike to get the information I want.
Got it; that's what I was wondering. No one seems to have reverse-engineered that part, and, honestly, it seems like a grey area to re-use that library. I don't think they'll mind as long as your app behaves well (for example, try not to poll for data too frequently).
-
Wow, thank you so much for your efforts! This is so useful to make sure that charging hasn't randomly stopped (wasting valuable time)!
I have wanted an app for quite some time that could roll everything (my favorite features) into one, but more simplified. It has been frustrating needing to go between a dozen apps just to access all the information I need when doing research. I may yet try my hand at writing it myself but I am also not *extremely* well-versed in communication protocols or android programming (but have worked with both in the past).
For my 2016 SR and my android devices:
-"Zero Voltage" does not retrieve balance and has been the only app to display Ah capacity for me
-"Zero Official" does not show anything but temperatures while riding, and was the only app to show SoC and battery temperature
-"Metrics for Zero" is sometimes unscrollable for in-app viewing of data and can crash if ran too long (no adjustment for sample rate)
Not bashing any of these, I am very grateful that I have access to the unique benefits each of these provide. But to recap, I'd love a single app that can show voltage, battery temperature, balance, estimated SoC, capacity, and the low-hanging fruit measurements of current and battery amperage WHILE the bike is armed. Just saw the screen shot, if the library supports this while armed I'll be a happy camper. Even your balance is more useful than the official app! For clarity I would not read or analyze these while riding it would just be for when I can safely do so or for screen recording it. Well done.
On second thought, after reading the CANBUS thread a few below this one I will wait for this to be vetted and safely exit beta before riding and using this. I realize with other third-party apps there is still inherent risk and I have accepted that and try to mitigate as much as possible. Personal choice.
-
Thanks @talon
Got it; that's what I was wondering. No one seems to have reverse-engineered that part, and, honestly, it seems like a grey area to re-use that library. I don't think they'll mind as long as your app behaves well (for example, try not to poll for data too frequently).
Just to clearify: those libraries are not part of my app now. I just needed to call them once to get the packets including the checksum, I did not try to find out which algorithm they use for the checksum. Probably crc32 or so...
-
Thanks @talon
Got it; that's what I was wondering. No one seems to have reverse-engineered that part, and, honestly, it seems like a grey area to re-use that library. I don't think they'll mind as long as your app behaves well (for example, try not to poll for data too frequently).
Just to clearify: those libraries are not part of my app now. I just needed to call them once to get the packets including the checksum, I did not try to find out which algorithm they use for the checksum. Probably crc32 or so...
Got it. How many bikes have you tested it with?
The function signatures might reveal how messages vary, or not at all, by model or configuration.
-
Got it. How many bikes have you tested it with?
I have tested it with my SR 2018, same protocol version as 2017 and 2019. And I know one guy with an SR 2015, there was one problem I could fix. No other negative feedback until now...
-
Got it. How many bikes have you tested it with?
I have tested it with my SR 2018, same protocol version as 2017 and 2019. And I know one guy with an SR 2015, there was one problem I could fix. No other negative feedback until now...
Okay so it seems you’re the fourth person to my knowledge to try solving this problem. I hope you’ll get further and clear it but it’d be nice at some point if we just had one good working shared codebase if the app idea doesn’t work out.
Several infeasible apps would be a shame.
-
Brian,
would do you mean exactly? Things are solved enough I think. I know how the communication and protocols work. The app works fine so far. And if there are some model dependent issues, this should be solvable too. I'm quite happy with the state of the app until now ;)
Have a nice weekend!
-
I don’t reveal what I’ve learned from others. I think you’ll be fine but make sure to solicit feedback from users so you don’t miss cases.
What I’m trying to obtain is more public knowledge in the statistically likely case that you lose interest or that we find we need more than you’re interested in developing. Zero themselves fall into his category.
-
Hi everybody!
I'm new to this forum and to the Zero world, so let me do a quick introduction: End of 2018 I bought a new Zero SR 2018. I use it mainly for commuting and of course for some nice after-work tours. I very much enjoy this bike and until now everything works fine 8)
In my free time, I like to program Android apps, so I thought it would be a great idea to create an app for my Zero. What is the app about? It's about monitoring the charging state (remotely) and raise some triggers at some state of charge to carry out some kind of actions.
The name of the app is ZeroSpy and you can find a beta version here:
https://play.google.com/store/apps/details?id=com.bsc101.zerospy (https://play.google.com/store/apps/details?id=com.bsc101.zerospy)
How to use:
- Install the app on an Android mobile, open the app and connect it to your Zero (not SR/F) via Bluetooth. This device should already be paired with your bike. You should now see some values like state of charge and so on.
- Remember the AppID of this first installation, see screenshots.
- Install the app on a second device, navigate to the remote page and enter the AppID of your first installation. You are now able to remotely monitor the charging state of your Zero. The first installation sends the data to a cloud database from where the second installation reads.
- Triggers: You can define triggers (on the device connected to your bike) which execute when a specified SoC is reached. You can specify some URL which will be called. I use it this way: While charging, my Zero is plugged into a switchable power outlet, so I defined a trigger which turns off this power outlet at some SoC, for example 80% or whatever. So I can load to some level and automatically switch off the Zero. A second trigger calls a IFTTT webhook and this results in some notifications on my remote device. So while my Zero is charging in the garage, I do get notifications on another mobile phone.
Please note: This app is still beta, so there are probably still some bugs.
I would be glad if some of you would give it a try and provide some feedback! Thank you!
Boris
Hello Boris,
I was able to connect your app with my Zero SR '15 :). I have a Bluetooth switch and WIFI switch. I am not sure how to use the trigger. Can you give me some quick "How to" example?
Thanks,
Giacomo
-
Hello Boris,
I was able to connect your app with my Zero SR '15 :). I have a Bluetooth switch and WIFI switch. I am not sure how to use the trigger. Can you give me some quick "How to" example?
Thanks,
Giacomo
Hi Giacomo,
Which network switch do you have?
What you can do with these triggers currently is basically calling some URL you could also enter in the address line of a browser. I have a simple switch which I can turn on or off by calling this URL: 'http://192.168.1.83/control.html?STATE=1' or 'http://192.168.1.83/control.html?STATE=0'. The URL to call depends of course on what you want to do or on what switch you have.
I attached a screenshot of my trigger definition, please have a look. What happens is:
- Wait until 75% SoC
- Then wait 3 minutes
- Then call the specified URL
- Then disable the trigger
Hope this helps. Let me know if you need more assistance!
Regards,
Boris
-
Thank you Boris,
this help a lot :).
I have a D-Link wifi switch and a Plugable Bluetooth switch(https://plugable.com/products/ps-btaps1/). I definitely can use the wifi switch as you did.
For the Bluetooth one, I may need to write some code, the manufacturer provides python library to control it :).
Thanks,
Giacomo
-
This is what I use: https://www.cl-control.de/shop/product_info.php?language=de&info=p47_wlan-schaltsteckdose-cl-sda1.html (https://www.cl-control.de/shop/product_info.php?language=de&info=p47_wlan-schaltsteckdose-cl-sda1.html)
Just works :)
-
@I973: Did you publish your code somewhere, like GitHub ? I would be very much interested.
There's a free IoT platform called Thingspeak where you can send you data to (250k packets per year for free i think), and a bunch of free mobile apps with widgets that can display it.
-
@I973: Did you publish your code somewhere, like GitHub ? I would be very much interested.
Hi tabarnakos,
No, the code is not published. Which part are you interested in? Probably the communication with the bike, I guess!?
-
There's a free IoT platform called Thingspeak where you can send you data to (250k packets per year for free i think), and a bunch of free mobile apps with widgets that can display it.
Thanks for this recommendation! I played a little bit with ThingSpeak and you can already use it with my current app version: I added a trigger which sends the SoC every percent. I made this channel public (I am currently charging, startet at 50%): https://thingspeak.com/channels/808822 (https://thingspeak.com/channels/808822)
So I will probably add some more trigger features:
- make more data available for sending (charging rate, current, temp, and so on...)
- more events that raise a trigger
Nice 8)
-
ThingSpeak does look interesting, but I'm unable to sign up right now and will check again later. Matlab is the tool underneath it which I've used often enough.
-
I would be very much interested in the communication part. I would like to develop a solution for a esp32 which could expose the data through MQTT to my domotica (controlling charging) or through Lora... That would be appreciated!
-
Thank you! This is exactly what I wanted to do with a raspberry pi or arduino, but gave up trying to reverse engineer the rfcomm communication over bluetooth. I was able to install zerospy on an old cell phone, and created a little webhook for it to call at 1% SoC changes to interface to Home Assistant. Now my home automation can monitor the SoC of my bike:
(http://e2r4.com/emf/ha.png)
The next step for me is to install a z-wave outlet to plug the bike into so I can toggle it based on the SoC through home automation.
-
Very nice! Looks good 8)
-
Thank you! This is exactly what I wanted to do with a raspberry pi or arduino, but gave up trying to reverse engineer the rfcomm communication over bluetooth. I was able to install zerospy on an old cell phone, and created a little webhook for it to call at 1% SoC changes to interface to Home Assistant. Now my home automation can monitor the SoC of my bike:
(http://e2r4.com/emf/ha.png)
The next step for me is to install a z-wave outlet to plug the bike into so I can toggle it based on the SoC through home automation.
How's your z-wave controller working out? I'm using a Wemo Insight myself, with python API ouimeaux.
-
I've got home assistant (https://www.home-assistant.io/) controlling my Aeotec z-stick with a bunch of linear switches and stuff. It works pretty well. I've had some issues with bluetooth connectivity to the bike not working, and misc issues with home assistant, but overall am happy with the setup. Some of my bluetooth issues might be related to my failing charger, but that's another thread. The other thing that makes my setup slightly complicated is that I don't want to use any cloud services.
My next step will be figuring out how to set up the Zero approved winterization in my automation. Every month check if SoC < 40%, charge to 60%, stop. It sounds simple, but in home assistant it might be tough. Maybe I just make something external control it through HA.
-
@I973 what kind of infrastructure is required for zerospy? I imagine it as a lambda backed API gateway with Dynamo table for the user/device data (in AWS speak). I'm just kind of curious what this app is run on.
Sent from my Pixel 2 using Tapatalk
-
Boris,
Thanks for writing this application. It looks promising. Unfortunately, I cannot get it to connect to my 2016 Zero SR.
I have no problem connecting to the official Zero app through bluetooth; however, I cannot get the bluetooth connection to work with ZeroSpy.
The bluetooth is turned on by switching the motorcycle on then pressing the mode button until the bluetooth symbol is blinking. Am I missing something?
Thanks
Sent from my SM-N950U1 using Tapatalk
-
@I973 what kind of infrastructure is required for zerospy? I imagine it as a lambda backed API gateway with Dynamo table for the user/device data (in AWS speak). I'm just kind of curious what this app is run on.
Hi staples,
sorry for the late answer, I didn't get any notifications about new entries here... strange...
I use Google techniques: Firebase Messaging, Firebase Database and Cloud Functions.
Boris
-
Boris,
Thanks for writing this application. It looks promising. Unfortunately, I cannot get it to connect to my 2016 Zero SR.
I have no problem connecting to the official Zero app through bluetooth; however, I cannot get the bluetooth connection to work with ZeroSpy.
The bluetooth is turned on by switching the motorcycle on then pressing the mode button until the bluetooth symbol is blinking. Am I missing something?
Thanks
Hi dmyers2k,
Could you please send a debug log? Reproduce your problem, then select 'Send Debug Log' from the menu. You will find my email address in the app's about dialog.
Thanks!
-
It sounds like you are trying to re-pair it. That should not be necessary, if I am remembering correctly.
-
It sounds like you are trying to re-pair it. That should not be necessary, if I am remembering correctly.
Correct, the blinking bluetooth symbol is only necessary for pairing. Once paired, connect should work without pairing mode...
-
So I have your app up and running, one on an ancient android Nexus 5 that sits next to where my bike charges at home, then again on my day to day phone. The app is working perfectly letting me see my bike status when not even home or just across the house out of bluetooth range. I was wondering is there a way to get your app working with IFTTT? I have a wifi smart switch (the WYZE Outdoor Smart Switch) with IFTTT support and was hoping to be able to get this connected so I could shut my bike charger off around 80% charge.
Otherwise, great work nonetheless as your app is way more reliable and detailed than the standard Zero app.
-
I was wondering is there a way to get your app working with IFTTT?
Hi herculeesjr,
you can define triggers, that means, you can configure HTTP GET or POST requests. This should work with IFTTT. You have to define them on your Nexus 5, "Bike" page, bike icon at the top of the app. Let me know if you need more help on this.
Boris
-
Thanks for the reply! I'm not really grasping how it's supposed to be setup honestly. Is there a direction you can point me in or would you be able to walk me through it? I don't know what trigger I would have to setup on IFTTT for me to "connect" it with your ZeroSpy app.
-
I use a very similar app (EUC World) for my electric unicycles, it's fantastic and does way more than I'd ever need. I have a wheel right now that has an 80 mile range so these things are no joke, for city commuting that is...
-
I don't know what trigger I would have to setup on IFTTT for me to "connect" it with your ZeroSpy app.
You can use the "Webhooks" service as the "if" part. You can then find the URL to call when you navigate to "My services -> Webhooks -> Documentation". You will find something like this: https://maker.ifttt.com/trigger/{event}/with/key/abcdefghijklmnopqrstuvwxyz. This is the URL you should setup in ZeroSpy.
Hope this helps :)
Cheers
-
I don't know what trigger I would have to setup on IFTTT for me to "connect" it with your ZeroSpy app.
You can use the "Webhooks" service as the "if" part. You can then find the URL to call when you navigate to "My services -> Webhooks -> Documentation". You will find something like this: https://maker.ifttt.com/trigger/{event}/with/key/abcdefghijklmnopqrstuvwxyz. This is the URL you should setup in ZeroSpy.
Hope this helps :)
Cheers
Sadly after a day the phone that connects to my bike can't manage to keep a connection. I've tried re-pairing the bluetooth, restarting the app, restarting the phone, etc. and sometimes it'll work again, but usually only for like six hours then it goes back to the constant "Reconnecting..." loop.
-
Hello Boris,
Thanks a lot for developing and sharing ZeroSpy.
I do not plan at the moment to use it in order to remotely control my bike.
But on the other way, I have some problems with my bike (FXS MY2016, 11kW), which gives me completely crazy SOC values.
A very nice feature of ZeroSpy is that it can record data every second. These data can be exported and analyzed.
From what I see on the app, it seems that the Pack Capacity (Ah) is decreasing regularly while riding, unlike the SOC. It means that the Pack Capacity could help to predict the range better than the estimated SOC, particularly on the bikes where the SOC gives crazy values.
I would like to compare the curves of the SOC and of the Pack Capacity.
But unfortunately, even if ZeroSpy shows the Pack Capacity on its screen, ZeroSpy does not record the Pack Capacity values.
Could it be possible to add the Pack Capacity to the recorded values?
Thanks,
Gerard
-
Gerard, if I understand you right, you trust the FXS' output to show the correct battery capacity in Ah, but you don't trust the calculated SoC.
Question is, how is the capacity in Ah measured or calculated; ie could other data give you a better reference against the SoC like for example battery voltage?
ETA link to SoC estimation https://zeromanual.com/wiki/BMS/SoC_Estimation
-
What is certain is that the SOC does not work on my bike anymore. And we are a lot in this case.
Clearly, the way the SOC is estimated has changed due to a firmware update, and perhaps some reprogramming from the Zero dealer.
Battery voltage is a bad way to estimate the SOC.
Using the remaining Pack Capacity could be an alternative in order to estimate the SOC and the range.
I have studied my bike's logs, and it seems that (but it has to be confirmed):
In the BMS logs, I get 8 different values related to the capacity and the SOC. They appear in lines of this form :
01469 01/09/2023 13:08:58 Discharge level 002 AH, SOC: 70%, I:034A, L:3756, l:3971, H:3807, B:051, PT:022C, BT:026C, PV:106014, M:Bike On
01470 01/09/2023 13:08:58 SOC:2341,7632,2672,26000,90,85,70,53
In the 8 numbers that follow SOC, it seems that the third one, 2672, is the amount of mAh that the pack has delivered. I guess that this measure is obtained by Coulomb counting (or integration of the intensity). This value is rounded to 2 Ah in the line just before.
26000 is the nominal capacity of the pack in mAh. It has been stored in the BMS by the Zero dealer.
It seems that 90,85,70 are 3 different estimations of the SOC calculated from different ways.
The one that is used is the third (70%).
In my bike, I have two packs, one BMS in each pack, one log for each BMS.
And it seems that the MBB makes a mix of the information retrieved from the 2 BMS (average of their SOC).
From the line above, I have a pack with 26000 mAh and it has delivered 2672 mAh, i.e. taking only these numbers into account, its SOC should be 89.7%. Note that it is equal to the first of the 3 SOC estimations (90,85,70). But the BMS uses the third estimation of 70% ! It means that instead of telling me that I have used 10% of the capacity, the dash tells me that I have used 30% !!!
Note that lines of this kind did not appear in the logs when I had the original firmware (and good SOC estimates):
01470 01/09/2023 13:08:58 SOC:2341,7632,2672,26000,90,85,70,53
The study of these data is quite difficult by extracting them from the log. And they are sampled every minute in the logs.
If ZeroSpy could help to extract some of these values (and with a sampling interval of 1 second), it could
- help to investigate what happens
- and with very little programming, it could be possible to make ZeroSpy display a range estimate based on the remaining Pack Capacity
-
What is certain is that the SOC does not work on my bike anymore. And we are a lot in this case.
Clearly, the way the SOC is estimated has changed due to a firmware update, and perhaps some reprogramming from the Zero dealer.
...
What MBB and BMS firmware versions did you use when the SoC display was working as expected, and which ones give you a non-working SoC display?
-
@Bodo
We are digressing from the original topic. Please see this other thread: https://www.electricmotorcycleforum.com/boards/index.php?topic=11638.0