Search code examples
pexpect

Pexpect and Bluetooth Low Energy notifications


I am trying to automate the command line tool gatttool on a Raspberry Pi 3.

I am able to continually receive bluetooth notifications while using the tool manually: keying in the commands line by line using interactive mode.

However, with pexpect I am only able to receive several lines of notifications.

After setting up the correct write sequences to the bluetooth server, the Python script is as shown below:

while True:
    self.con.expect('\n')

This was done to flush to the logfile (sys.stdout)

Are there any buffer settings that might have tripped me up?

Any guidance will be very much appreciated.


Solution

  • Turns out that the default setting for "delaybeforesend" was too fast for the bluetooth device.

    Slowing it down to 1 second before sending each command helped to resolve the issue.