840922704 / BLE_DMM_Client

Bluetooth Multimeter Client
GNU General Public License v3.0
10 stars 3 forks source link

Get no data from Aneng AN9002 on Linux #6

Open pillarama opened 1 year ago

pillarama commented 1 year ago

Hi, thanks for the great looking software. Unfortunately I wasn't able to get it working with my Aneng AN9002 on Linux (KDE Neon - based on Ubuntu 22.0) install. The DMM can be found OK from the search, but when trying to connect to it the connection just gets immediately closed. Here is the log (note that I anonymized the MAC addresses):

python3 main.py [MainWindow] Change to English Searching Bluetooth devices 4B:32:61:49:xx:xx: 4B-32-61-49-XX-XX FC:58:FA:4C:xx:xx: Bluetooth DMM 14:BB:6E:DA:xx:xx: 14-BB-6E-DA-XX-XX FC:58:FA:4C:xx:xx Daemon thread starts Start listening to Bluetooth FC:58:FA:4C:xx:xx Connected: True Start get data Connection Closed Stop the thread...

Is there anything you can suggest I do to diagnose this issue?

Thanks

840922704 commented 1 year ago

Can it (released package) work properly in win10/11 with your AN9002?

840922704 commented 1 year ago

Or active the line 132 and 133 in main.py to see what the real value is

pillarama commented 1 year ago

I just checked and yes the Windows portable package works with my DMM in Windows 11 on my Laptop. I enabled lines 132 and 133 of main.py but the output is no different - I don't think the code ever reaches those lines.

Also I tested this other client software here: https://github.com/riktw/AN9002_info which also uses Bleak and this one actually works fine in Linux my laptop with my DMM (but it's a more basic client):

I compared the code from both programs a little but I couldn't figure out what was different that makes that one work. I'm not that good at programming or debugging Python and have no experience programming for Bluetooth.

pillarama commented 1 year ago

Oh another clue might be that with this program in Linux the Bluetooth symbol on the DMM doesn't stop flashing and go solid like it should when the connection is made - it just keeps flashing like the connection is not successful. In Windows with this program and also with the other program by riktw in Linux the Bluetooth logo on the DMM screen goes from flashing to solid when the connect button is pressed.

840922704 commented 1 year ago

@pillarama Thanks for your feedback! It's a bit strange. I'll check it later

840922704 commented 1 year ago

Maybe that problem caused by lacking of backend? I'm only now aware of this.🤣

Bleak Features: Supports Windows 10, version 16299 (Fall Creators Update) or greater Supports Linux distributions with BlueZ >= 5.43

Making BlueZ ready may resolve this problem.

840922704 commented 1 year ago

V3.2 released. Maybe you can try it when you have time. But I think there may still be many bugs here on Linux since I haven't specially tested it in Linux yet.

webspiderteam commented 1 year ago

Also I tested this other client software here: https://github.com/riktw/AN9002_info which also uses Bleak and this one actually works fine in Linux my laptop with my DMM (but it's a more basic client):

this app uses notify function and uses client.connect() function to connect device and get data with this code

async def run(address):
    client = BleakClient(address)

    try:
        await client.connect()
        await client.start_notify(CHARACTERISTIC_UUID, notification_handler)

        while(1):
            if keyboard.is_pressed("q"):
                print("Shutting down!");
                break;
            else:
                plt.plot(dataGraph, color='b')
                plt.draw()
                plt.pause(0.1)
                await asyncio.sleep(0.5)       

    except Exception as e:
        print(e)
    finally:
        await client.stop_notify(CHARACTERISTIC_UUID)
        await client.disconnect()

but your app does not using connect function but checks client.is_connected without connect() I don't reallly know bleak can work like this but that take my attention. also you are getting data manually and notify is not activated this could alsa can be an issue.

            async with BleakClient(ADDRESS_dialog) as client:
                self.logger.info(f"Connected: {client.is_connected}")
                try:
840922704 commented 1 year ago

@webspiderteam Thanks for providing new ideas. That seems to be a more elegant method~😎 I referred the code from bleak_examples. And it seems that the notify function is not an important method to get data. I am still confused why its behavior is different between Win and Linux.😂 (In addition, I need to rant about WSL2 not being able to use Bluetooth😑)

webspiderteam commented 1 year ago

I am still confused why its behavior is different between Win and Linux.

I saw some issues that in bleak pages, there are some issues that could be happening with your code. you may wanna look https://github.com/hbldh/bleak/issues/1385 https://github.com/hbldh/bleak/issues/1358

I need to rant about WSL2 not being able to use Bluetooth

you can use oracle vm. I was used it and I was able to add my bluetooth adapter with embed wifi adapter and bluetooth. I had to add wifi adapter to use it. I don't know your machine has bluetooth like that. but if u use bluetooth seperated you could use it more easy. Also wsl has ability to usb devices to vm but its little complicated.

StefJar commented 12 months ago

different bt stacks different behaviour

on linux you can activate the btmon logger sudo btmon that will give you a good idea, if bluez fails to run the gatt service discovery. Only a successful discovery will create the dbus objects(on which the bleak linux backend works). If you know your characteristics and services uuids/handles, you can use the HCI interface. Other modules like bluepy3 are based on that. Although each solution has its own trade-off. For example in bluepy3 you can't run async/parallel a GATT write/read + enabled GATT notifications.

I have a very similar problem with the BM64 SOC from Microchip. The ble interface works well everywhere except Linux. The bluez guys are quite helpful.