vovagorodok / ArduinoBleOTA

Upload firmware over Bluetooth
MIT License
19 stars 7 forks source link

Uploader doesn't see service #17

Closed sdetweil closed 1 year ago

sdetweil commented 1 year ago

so I have swapped in your service, and I can scan and find it, and connect and I can use the hw/sw chars to read from the service so it is active

disconnect and I still see it in multiple scanners with your service id

but the uploader cannot see it I added a print after the scan

dbus.Array([dbus.String('21010001-27b9-42f0-82aa-2e951747bbf9')], signature=dbus.Signature('s'), variant_level=1) -- second device
dbus.Array([dbus.String('11050001-27b9-42f0-82aa-2e951747bbf9')], signature=dbus.Signature('s'), variant_level=1)  -- original uuid
dbus.Array([dbus.String('0000fe50-0000-1000-8000-00805f9b34fb')], signature=dbus.Signature('s'), variant_level=1)
dbus.Array([], signature=dbus.Signature('s'), variant_level=1)
dbus.Array([dbus.String('0000fe9a-0000-1000-8000-00805f9b34fb')], signature=dbus.Signature('s'), variant_level=1)

dbus.Array([dbus.String('00000000-27b9-42f0-82aa-2e951747bbf9')], signature=dbus.Signature('s'), variant_level=1)--- this is the app

dbus.Array([], signature=dbus.Signature('s'), variant_level=1)
dbus.Array([], signature=dbus.Signature('s'), variant_level=1)
dbus.Array([dbus.String('0000fe50-0000-1000-8000-00805f9b34fb')], signature=dbus.Signature('s'), variant_level=1)
dbus.Array([dbus.String('2e938fd0-6a61-11ed-a1eb-0242ac120002')], signature=dbus.Signature('s'), variant_level=1)
dbus.Array([], signature=dbus.Signature('s'), variant_level=1)
dbus.Array([dbus.String('0000110a-0000-1000-8000-00805f9b34fb'), dbus.String('0000110c-0000-1000-8000-00805f9b34fb'), dbus.String('0000110e-0000-1000-8000-00805f9b34fb'), dbus.String('00001200-0000-1000-8000-00805f9b34fb')], signature=dbus.Signature('s'), variant_level=1)
dbus.Array([], signature=dbus.Signature('s'), variant_level=1)
sdetweil commented 1 year ago
drawing
vovagorodok commented 1 year ago

Not sure, but NimBle by default serve only one connected device at the same time. And if someone (some phone) is connected than no advertising at all. Try disconnect from all devices, maybe reboot device and try again. Remember that phone can try to reconnect automatically

sdetweil commented 1 year ago

yes. once connected. cannot be seen by others. I was just showing you the service description, which is good. and I can use the read only chars just fine.

so my server is advertising and the service is good

so must be Linux BLE scanner...

the screenshot is from an Android

vovagorodok commented 1 year ago

Try to scan bluetooth devices from your OS directly instead uploader.py

sdetweil commented 1 year ago

i see the same problem on bluetoothctl..

maybe.. my app is connected, status=1 I write a characteristic value set a future time for switch to upload service (can't switch while IN the characteristic write callback) after time switch to upload service


    BLEDevice::stopAdvertising();
    Sprintln("stopping scanner");
    pBLEScanner->stop();
    Sprintln("stopping service");
    activeService[status]->stop();
    Sprintln("deleting service");
    delete activeService[status];
    Sprintln("deleting server");
    delete pServer;
    // remove reference
    pServer = NULL;
    // create a new server object
    pServer = BLEDevice::createServer();
    Sprintln("ble server");
    pServer->setCallbacks(new MyServerCallbacks());

    BLEService *OTAService = ArduinoBleOTA.begin(pServer, InternalStorage, 
                 HW_NAME.c_str(), HW_VER, SW_NAME.c_str(), SW_VER);
    activeService[status] = OTAService;
    Sprintln("restart advertising after resetup");
    pAdvertising->addServiceUUID(OTAService->getUUID());
    pAdvertising->start();

the app did NOT disconnect til eons later the ESP code did NOT get a disconnect notice but the server was destroyed and recreated

sdetweil commented 1 year ago

I used bleak to scan and while the android scanner app sees your service and characteristics, the bleak scanner sees , the prior UUID service

c8:f0:9e:75:1a:26
C8:F0:9E:75:1A:26
{'path': '/org/bluez/hci0/dev_C8_F0_9E_75_1A_26', 'props': {'Address': 'C8:F0:9E:75:1A:26', 'AddressType': 'public', 'Name': 'c8:f0:9e:75:1a:26', 'Alias': 'c8:f0:9e:75:1a:26', 'Paired': False, 'Trusted': False, 'Blocked': False, 'LegacyPairing': False, 'RSSI': -47, 'Connected': False, 'UUIDs': ['11050001-27b9-42f0-82aa-2e951747bbf9'], 'Adapter': '/org/bluez/hci0', 'TxPower': 9, 'ServicesResolved': False}}
{'uuids': ['11050001-27b9-42f0-82aa-2e951747bbf9'], 'manufacturer_data': {}}
-46
ConfigApp

the app

import asyncio
from bleak import BleakScanner

async def main():
        devices = await BleakScanner.discover()
        for device in devices:
                print(device.name)
                print(device.address)
                print(device.details)
                print(device.metadata)
                print(device.rssi)

asyncio.run(main())
vovagorodok commented 1 year ago

Can you show advertising data (not visible services after connect) in android nRF Connect application?

vovagorodok commented 1 year ago

Here what I have:

drawing
sdetweil commented 1 year ago
drawing

but connect and you see something different

drawing
vovagorodok commented 1 year ago

In BLE is difference what services device have and what services device advertise. Device can have unlimited number of services. But advertising block is limited and you should chose what to advertise: https://github.com/vovagorodok/ArduinoBleOTA/issues/10#issuecomment-1534745203 If device doesn't advertise ota service than script will not find him.

You can remove this filter if you want: https://github.com/vovagorodok/ArduinoBleOTA/blob/2e2a6857d72c1101b42b82a648cd13d142d74b26/tools/uploader.py#L76

sdetweil commented 1 year ago

thx, i thought I handled that on the change. I don't see explicit remove (using BLE, see it in Nimble path)

am away til monday

sdetweil commented 1 year ago

actually, that distinction might make this whole thing easier. setup the three services, and just decide which one to advertise. my app discover handler just needs to know the found advertised service's characteristics to use.(which it currently 'assumes').

vovagorodok commented 1 year ago

But remember that it's not safety from security reason. Someone can connect and see that OTA services are available and flash other software. You can additionally disable uploads and enable only when needed: https://github.com/vovagorodok/ArduinoBleOTA/blob/main/doc/SECURITY.md#disable-uploads

sdetweil commented 1 year ago

would only be available when my app says upload. not all the time.

then the box reboots and the service goes away til next time it's needed

I would probably change the UUIDs too

sdetweil commented 1 year ago

so I couldn't wait til Sunday and had some time. bought another esp32, and redid the code.

works as you said. what's advertised vs services drawing drawing

sdetweil commented 1 year ago

successful connect and upload!!!

non-nimble!

sdetweil commented 1 year ago

only 764b/s, 24 min 17 sec for 1113712 bytes

doesn't reboot? I have to do that?

sdetweil commented 1 year ago

so I think I should close this as it was my fault, and fixed. and move to another topic about the finish up. apply/reboot...

vovagorodok commented 1 year ago

so I think I should close this as it was my fault, and fixed. and move to another topic about the finish up. apply/reboot...

Perhaps you forgot ArduinoBleOTA.pull(); in loop()

ArduinoBleOTA.pull() is created in order to perform reboot only when nothing in loop and not incidentally reboot when esp32 do something

sdetweil commented 1 year ago

well, now my system has cached (across boots) the device uuids and the upload service is not visible. I redid the startup to only have ONE service, and the scan data still has both.

sdetweil commented 1 year ago

ok, figured out how to clear the cache, now get an upload failure using NimBLE

connected  -- my app
lld_pdu_get_tx_flush_nb HCI packet count mismatch (0, 1)
on disconnect start advertising= 15c155ca-36c5-11ed-adc0-9741d6a72f04 -- my app
disconnected -- my app 
sdetweil commented 1 year ago

using non-nimble ESP32 BLE.

Installing. Upload time: 0:05:07.499808 Success! (base) sam@sams:~/ArduinoBleOTA/tools$ rexx rexxtry say "1138176/((5*60)+07)" 3707.41368

sdetweil commented 1 year ago

to clear cache stop bluetooth service delete the cache files (on linux/var/lib/bluetooth) under local device entry/folder) restart bluetooth service then can scan have to do this all the time.

will provide the script (bash) code for this.. (need to test on mac)

sdetweil commented 1 year ago

got nimble working, Uploaded: 1139200/1139200 Installing. Upload time: 0:01:23.745954

"(1139200/(1*60+23))"

13725/bytes sec

the Nimble author said not to server->addService()

sdetweil commented 1 year ago

I think I can close this now