Raspberry Pi + Python API: Connection unreliable

Python, Java, Android OS, etc.
TEL
Posts: 8
Joined: Thu Apr 13, 2017 8:04 am

Raspberry Pi + Python API: Connection unreliable

Postby TEL » Mon Sep 18, 2017 2:21 pm

Dear community,

i am using a Raspberry Pi 3 to receive data via Bluetooth classic from a Bitalino (R)evolution Plugged Kit. The connection is implemented using the python API. I am facing the following issue:

After 1-20 minutes (it is around 4-5 minutes most of the time) the connection to the Bitalino Kit (1000 Hz, 1000 samples per read) gets lost. I am getting the following error message:

Code: Select all

data = device.read(nSamples)
File "/usr/local/lib/python2.7/dist-packages/bitalino.py", line 451, in read
raise Exception(ExceptionCode.CONTACTING_DEVICE)


The received data is published via ZeroMessageQueue and visualized by the subscriber. When I turn off all visualizations, it seems that it needs more time until the error message occurs (26 and 60 mins) but due to the high amount of time for investigation I could not perform more tests than 2.

Also it seems that this error can occur, when electrodes are (dis-/)connected.

I tried the internal Bluetooth Chip of the RPi as well as the Bitalino BT Dongle. No difference could be observed. Is this a known issue?

BITalino
Site Admin
Posts: 567
Joined: Tue Aug 27, 2013 3:47 pm

Re: Raspberry Pi + Python API: Connection unreliable

Postby BITalino » Mon Sep 18, 2017 2:55 pm

Hi there,

Are the calls to the read method done in a separate thread? Given that the acquisition is time critical, if you have operations in-between calls to the read method that take much time, it may happen that the connection is dropped due to a buffer overflow on the device. Would this be the case?

Best regards,
The BITalino Team

TEL
Posts: 8
Joined: Thu Apr 13, 2017 8:04 am

Re: Raspberry Pi + Python API: Connection unreliable

Postby TEL » Tue Sep 19, 2017 12:43 pm

Currently the read operation is not in separate thread. The relevant information (ECG and EDA sensor samples) needs to be extracted to be sent via ZMQ. As far as I can see there is no option in the python API to reduce the sent data to only these values, am I wrong here?

This project is aimed at providing a live visualization (just like OpenSignals does) embedded in a software.

The only idea to isolate read into a separate thread would be to use some shared memory to write the data into and having another thread reading from it to visualize it. But this design would need lots of memory as deleting the already visualized would cause concurrency issues.

I just had it running for 1,5 hours with no errors. Then this happened four times in a row with only a few minutes in between. Is it maybe a problem that I use the python API on the raspberry (as a C++ library is mentioned for the RPi explicitly)?

BITalino
Site Admin
Posts: 567
Joined: Tue Aug 27, 2013 3:47 pm

Re: Raspberry Pi + Python API: Connection unreliable

Postby BITalino » Tue Sep 19, 2017 12:52 pm

The Python API usually works well on the Raspberry Pi also. You can configure the sampling rate, number of channels and amount of sampled read from the device.

Distance between the device and the receiver is also an important factor, but we'd suggest you try modifying these parameters and see if it helps. Note that for the sampling rate only 1000, 100, 10 or 1 can be chosen... 100 Hz would be the minimum recommended.

Sampling rate and channel list are input parameters to the start(...) method:
https://github.com/BITalinoWorld/revolution-python-api/blob/master/bitalino.py#L107

The number of read samples is the input parameter of the read(...) method:
https://github.com/BITalinoWorld/revolu ... no.py#L377

As you for sure know, the samples that you read together with the sampling rate will affect the latency of the visualiser, so you should make some calculations based on this.

TEL
Posts: 8
Joined: Thu Apr 13, 2017 8:04 am

Re: Raspberry Pi + Python API: Connection unreliable

Postby TEL » Tue Sep 19, 2017 1:10 pm

Okay, I was trying with 1000 Hz and 1000 samples at once. The sample rate is mandatory, the amount of samples read is not. I will try whether modifying the parameters of start will make a difference. The distance between the two devices is about 25 cm and the battery is fully charged.

Sidenote: I just tried the Bitalino ServerBIT (https://github.com/BITalinoWorld/revolution-python-serverbit) and the time until the connection got lost was even shorter (from 10 seconds to two minutes).

The latency of the visualization is not too important. Focus is on a stable connection and high data resolution.

I will keep you updated whether changing the start-parameters did the job.

TEL
Posts: 8
Joined: Thu Apr 13, 2017 8:04 am

Re: Raspberry Pi + Python API: Connection unreliable

Postby TEL » Tue Sep 19, 2017 4:00 pm

I tried many different setups and all of them resulted in the same error message:

File "/usr/local/lib/python2.7/dist-packages/bitalino.py", line 451, in read
raise Exception(ExceptionCode.CONTACTING_DEVICE)

There seems to be none to very little latency so I am curious, how many samples would cause a buffer overflow in the Bitalino?

When I ignore the Exception (meaning I continue to read from the device) it seems to work. The frame might be lost but the device sends again. But then at some point I get the same error message continuously and the device doesn't reconnect again. Did you ever face this issue?


Return to “Programming APIs”




cron