Alvipe / Open-Myo

Python module to get data from a Myo armband using a generic BLE interface
GNU General Public License v3.0
24 stars 14 forks source link

Autoconnect to myo doesn't work #6

Open raquena opened 5 years ago

raquena commented 5 years ago

Hello Alvipe,

A couple of days ago I've cloned the Open-Myo repo, annd tried to run the example in a RPi 3B with the internal bluetooth. Running the example seemed to leave the execution stuck somewhere, so I've decided to dig a little into the code to see if I could understand what I was doing wrong. After placing some flags here and there, I've found out that I can't connect to the myo, and that's why the execution doesn't go further. To be sure that was the problem, I've just assigned the fixed MAC address of my Myo-Band as follows:

(file open_myo.py --> line 162) def get_myo(mac=None): mac = "xx:xx:xx:xx:xx:xx" # use fixed mac, scan doesn't work if mac is not None: while True: for i in btle.Scanner(0).scan(1): if i.addr == mac: return str(mac).upper()

Now it works, but I can only manually assign the MAC of the myo I'm using. I've been trying to debug the connection, but I wasn't successful.

Any ideas/suggestions/hints about what's going on and how to fix it?

Thanks!

Alvipe commented 5 years ago

Hi @raquena I've never had any issues regarding auto-scanning the MAC address of the Myo. I've tested this code with at least three different devices and it has always worked. The only thing that comes to my mind is that they have updated the firmware and something has changed with respect to the version that I use (which right now I can not confirm which is because I do not have a Myo at my disposal).

Elfbert commented 5 years ago

Hello, i found the same trouble too, luckly i solved it, i dont know if it is similar to yours :) In my condition, when i run main.py at the first time, the program stuck in the function"get_myo",so the first time i confirmed the current MYO MAC via command:

sudo buletoothctl
scan on

then i printed the j[0]and j[2],i found that the string is different from the original, it may because of the version, so i changed some of the codes as follows. By the way i found j also contain the name of MYO,which is named when i initialized the MYO through official software( i use the Windows version),so you can input your MYO name,it may also works.

def get_myo(mac=None,id=None):
     if mac is not None:
         while True:
             for i in btle.Scanner(0).scan(1):
                 if i.addr == mac:
                     return str(mac).upper()

    while True:
        for i in btle.Scanner(0).scan(1):
            for j in i.getScanData():
                #print(str(i.addr).upper(), j[0], j[2])
                if j[0] == 6 and j[2] == 'd5060001-a904-deb9-4748-2c7f4a124842':
                    return str(i.addr).upper()
                if j[0] == 8 and j[2] == id:  # '4248124a7f2c4847b9de04a9010006d5':
                    return str(i.addr).upper()