Connection problems with python in Ubuntu


I have modified some example to try to reconnect (a while True and a try/catch block) if there is an exception (e.g. timeout). 
I am using Ubuntu 16.04 with the latest library and sometimes I get this warning. 

No handlers could be found for logger "pygatt.backends.gatttool.gatttool"

What can it be due to?


    • What python version are you using?
    • Do you see a simliar "no handlers" warning if using pybluez?
    • Please post the full code that I can run as is on my Linux machine
  • Python 2.7.12 on Ubuntu 16.04

    The code I am using is the example. I have only modified the connection part by wrapping in a while True and a try/catch block, so I keep trying to connect if a timeout exception is raised.

    If using pybluez, I can connect but I cannot set up sensor fusion (error is "Can't set data processor!"). 
    Sometimes I get a segmentation fault when setting up sensor fusion when I use pygatt.
  • You will need to either reset the board or call "mbl_mw_metawearboard_tear_down" if you cannot create the data processor.  Ideally this should be done after the script is finished collecting data.

    You can also remove the "set_sample_delay" calls and only stream one sensor fusion output which will remove the need to teardown the board.
  • I am already calling the disconnect method (python api) which calls the mbl_mw_metawearboard_tear_down, so I guess that is ok.

    How do you execute issue a soft reset in code? I guess that the process should be: detect wrong behaviour -> issue soft reset -> wait X seconds (how long should X be?) -> reconnect.

    I don't quite understand your last sentence, the "remove set_sample_delay calls" one. 
  • Call mbl_mw_debug_reset to reboot the board.  It could take 10+ seconds for the bluez stack to detect that connection has been lost but the actual number can vary from platform to platform.

    What i mean is don't make calls to "set_sample_delay"
  • I am using pygatt, because with pybluez I get the "cannot create data processor" error message, no matter that I reconnect or reset the board (from metawear app).
  • I think resetting the board should not be needed, because if I terminate the app and start again right after that, then I can connect again. 
    So it seems something related to python having some library internal state which is interfering, as is the only thing that changes when I ctrl-c the app and start again.
  • I tried to call init_libmetawear if I get 5 timeouts in a row, but it doesn't work. Sometimes, after 2-3 timeouts, it connects to the board, but other times the program gets stuck in endless timeouts, and the only solution is ctrl-c the app and run again.

    Any ideas on how could I avoid doing that? 
  • edited September 2017
    Serialize the API state after a successful initialization.  Then, if the same board is detected in the script, deserialize the state before initializing the API.

  • I don't quite understand what you mean by serializing the API state. 
    I see that the mbl_mw_metawearboard_initialize is called in the connect() function (python API). When does the deserialization occur? Before or after connecting to the board? 
    Should I save a state per board as a cache and use that before connecting?
  • See commits 544c758 and fcb1d61 on the pymetawear develop branch.
  • In the C++ documentation the function "libmetawear.mbl_mw_metawearboard_initialize" has three parameters and in the has two parameters.
    When I'm trying to execute the example (using Python SDK), I'm getting error message below:

    root@debian:/home/user/Downloads/MetaWear-SDK-Python# python XX:XX:XX:XX:XX:XX
    error 1537656591.703993: Error on line: 296 (src/ Operation now in progress
    Traceback (most recent call last):
      File "", line 17, in <module>
        libmetawear.mbl_mw_metawearboard_initialize(device.board, init_handler)
    TypeError: this function takes at least 3 arguments (2 given)

    Why the function has only two parameters here?


  • Your post has nothing to do with the thread topic. Post your unrelated question(s) in their own threads, do not hijack existing threads.

This discussion has been closed.