laberning / openrowingmonitor

A free and open source performance monitor for rowing machines
https://laberning.github.io/openrowingmonitor
GNU General Public License v3.0
98 stars 19 forks source link

Using openrowingmonitor for BLE app testing #93

Open mydeveloperday opened 1 year ago

mydeveloperday commented 1 year ago

I was wondering if it might be possible to use the OpenRowingMonitor running on a Raspberry PI as a BLE source for developing PM5-compatible apps. (effectively emulating the PM5 BLE interface, which I think you already do).

I was thinking about if it might be possible to add "simulation mode" that would allow the monitor to broadcast "fake/sample" rowing data over BLE as if someone was rowing a C2 (without actually having to rower attached) - to be honest constant stroke count +/- small random amount would probably be enough to start with.

However, to test OpenRowingMonitor suitability as a PM5 source, I thought I would test against existing apps.

I'm trying to connect to it from a iphone/ipad using the latest version of ErgData and Erg Studio, in both cases, they seem to fail to connect, (although it does advertise the service),

image

and Erg Studio gets as far as the "Sync PM Clock" phase.

image

image

Chrome version of Ergo Studio also suffering form the same issue (https://app.erg.studio/)

image

What I do notice is that pm5-base (https://github.com/ergarcade/pm5-base) image

and pm5-detail (https://github.com/ergarcade/pm5-detail) do seem to work well (both use the same pm5.js code I think)

image

Any thoughts on the concept and why it might be failing, (or pointers so I can begin to investigate)?

Many thank, awesome project BTW, what an incredible job you've done..

MyDeveloperDay

mydeveloperday commented 1 year ago

After further investigation I found that if I uncomment the following at the bottom of the app/server.js this does pretty much what I needed:

/*
replayRowingSession(handleRotationImpulse, {
  filename: 'recordings/WRX700_2magnets.csv',
  realtime: true,
  loop: true
})
*/

Brilliant thank you.. would be excellent if a "Simulate" button could be added to the UI.

laberning commented 1 year ago

Hi MyDeveloperDay,

yes, that code should work as a "simulator" for a real rowing session. It can replay any recording of real rowing data and the rest of the system will behave accordingly. It's the rowing trigger that is used while developing the application since coding while rowing would be a tough job πŸ˜„

It's probably nothing that would go into the UI, since recordings are very specific to the configured rower. But at some point I plan to extract this 'hack', so it can be started and configured via command line parameters.

The PM5-BLE implementation of Open Rowing Monitor is not perfect yet. So I wouldn't call it a PM5 BLE Simulator. For simple experinents it should be ok, but don't assume that a real C2 Rower would behave exactly the same πŸ˜„

We are currently working on a new engine that will also add some more values for the PM5 BLE.

Good luck with with your project, let us know how it goes (if you want).

mydeveloperday commented 1 year ago

I have noticed that ErgData and Erg Studio are very picky about something.. (sometimes I can get the ErgData app to crash during connection)

I started down this road trying to make a Windows BLE server, then without luck I moved to an arduino board using sketch but it wasn't powerful enough. (I think you may have done the same in the past)

As I had a RaspberryPI 4 Model B kicking around this was a perfect project. I know enough nodejs to be dangerous but I'm not an expert.

Having found this project, I now have at least something I can code the BLE client against. If I can work out what those other tools are doing that means they won't connect I'll try and let you know.. I've been reading the concept 2 BLE pdf and from what I can tell you've have implemented a lot of things (although there are 2 new characteristics 0x0017 and 0x0018 which I think you might be missing)

This is a great project, the installation was completely seamless (that almost never happens), I'm definitely interested to see how you get on, and what might come next. Great job.

for ErgStudio, I think I'm getting as far as a CSAFE command, I was going to take a look, my assumption is that you perhaps don't handle all the commands, and maybe that is a possible cause for the other apps not working.

JaapvanEkris commented 1 year ago

I have a PM5 and OpenRowingMonitor running side-by-side, I could do some experiments. There are some "hidden" elements here, like the name of the rower (it should end in Row, for to be recognized by ErgData, something I noticed in EXR). THere are some checks, like the hardware and firmware version. I've updated some of these elements in the new version, but we aren't there yet: there is some interaction and checking going on that seems to fail.

The tools you've shown are extremely intersting, as they might provide a way to detect what is missing in the interface.

carlito1979 commented 1 year ago

I’d be super interested in this too, but I assume Concept2 are quite protective of the full spec because cheating the online leaderboards is a real issue for them. I’d love to eventually have openrowingmonitor fully integrate with the ergzone app

JaapvanEkris commented 1 year ago

C2 is extremely open about the BT specifications, see https://www.concept2.com/files/pdf/us/monitors/PM5_BluetoothSmartInterfaceDefinition.pdf

Verified rows are based on a hash-code that the PM5 generates and the site checks. As long as nobody can imitate the hash-code, cheating is extremely difficult. And above that, for world records and the like, you need to provide additional video footage, etc..

mydeveloperday commented 1 year ago

I tried to look some more into this... ErgoStudio is about the closest to getting connected, its trying to send a ControlRecieve command when it gets stuck and the UI is suggesting it was trying to send a "sync clock"

ValueReadRequest: serial ValueReadRequest: hardwareRevision ValueReadRequest: firmwareRevision ControlReceive command: <Buffer f1 76 09 22 07 00 1f 01 0b 0b 07 e6 a5 f2>

There is some information about the BLE and CSAFE commands here (as pointed out above)

https://www.concept2.co.uk/files/pdf/us/monitors/PM5_BluetoothSmartInterfaceDefinition.pdf https://www.concept2.com/files/pdf/us/monitors/PM5_CSAFECommunicationDefinition.pdf

Looking at the buffer

<Buffer f1 76 09 22 07 00 1f 01 0b 0b 07 e6 a5 f2>

frame start = f1 frame end = f2 frame stuff byte = f3

there is no "frame stuffing" going on for this command, so it looks like this

// frame start f1 // frame contents 76 09 22 07 00 1f 01 0b 0b 07 e6 a5 // frame end f2

a5 = checksum which is calculated with

checksum=0
for(i = 0;i<len-1;i++)
{
    checksum ^= buffer[i]
}

0x76 = CSAFE_SETPMCFG_CMD (Proprietary commands) cmd = 76 (this seems to be a special command)

09 = data length data = 22 07 00 1f 01 0b 0b 07 e6

I think this is...

0x22 = CSAFE_PM_SET_DATETIME

Byte 0: Time Hours (1 – 12) Byte 1: Time Minutes (0 – 59) Byte 2: Time Meridiem (0 – AM, 1 – PM) Byte 3: Date Month (1 – 12) Byte 4: Date Day (1 – 31) Byte 5: Date Year (MSB) Byte 6: Date Year (LSB)

7:00 01 = PM Date Day = 31 Date Month = 1 0b 0b = 11/11 07e6 = 2022

I'm not sure if I'm supposed to reply on the ControlTransmit following this..(or if this is just a ipad->c2 command),

maybe the interface has moved onto doing something else.. my C2/PM5 should arrive next week and I can begin to get a better idea of what its needing.

Likely it might take someone from the ErgData or ErgStudio dev teams to help us understand what they are expecting next.. (or if they have any debug capability).