cdump / radiacode

Library for RadiaCode-101
MIT License
101 stars 18 forks source link

BLE client command error #30

Closed davidcarlsonSEE closed 4 months ago

davidcarlsonSEE commented 5 months ago

As I loop and request the real-time data, about every four seconds. I started seeing this error: "ERROR: S2 Command Corrupted! cmd=0x92000826" This causes an incomplete real-time data read which causes the parsing to fail. Then a BLE client disconnect.

Any thoughts?

cdump commented 5 months ago

Show full code of minimal reproducible example in python and full output of $ python3 yourcode.py

ckuethe commented 5 months ago

Can you reproduce this over USB? I've found that even with the official apps the Bluetooth link can be a little bit unreliable.

Polling every 4 seconds shouldn't be a problem. I was experimenting with high rate polling over USB and got nearly 200Hz. Of course, the device only updates measurements at 2Hz.

davidcarlsonSEE commented 5 months ago

@cdump , I coding java in android studio making an Android-RadiaCode device BLE connection.

I perform the init, deviceName, getConfigurations, serialnumber and version. If these calls are successful then I start a polling loop to get readings and periodically the current spectrum.

The polling loop sleeps for about 4 seconds and I have a "working" flag so I don't poll until I'm finished decoding.

To catch this issue I installed the windows radiacode software and I'm running it and connecting with USB. And this error showed up in the log console window of the windows radiacode app.

I "believe" that this might be an issue of requesting data from the windows radiacode usb app while i'm testing my android java ble app.

I'm testing that way because I'm comparing my android app data with the windows radiacode usb data to check my work as best I can.

So I'll show my java code where I set the characteristic value.


int reqSeqNo    = 0x80 + this.seq;
this.seq        = (this.seq + 1) % 32;
String seqhex2  = String.format("%02X", reqSeqNo);
byte [] writeMe = hexStringToByteArray("08000000260800"+seqhex2+"00010000");//reading
sc.setValue       (writeMe);    //request the reading
boolean tf       = mBluetoothGatt.writeCharacteristic(sc);
try
{
    waitForCharacteristicChange(3,TimeUnit.SECONDS);
} 
catch (InterruptedException e)
{
    e.printStackTrace();
}
//this triggers onCharacteristicChanged ble callback.
ckuethe commented 5 months ago

I "believe" that this might be an issue of requesting data from the windows radiacode usb app while i'm testing my android java ble app.

Good bet. The windows app complains when it tries to connect while my phone is already connected.

davidcarlsonSEE commented 4 months ago

This was because I was comparing the live windows USB data with the readings the BLE at the same time. When using only one interface at a time this behavior stopped.