lab11 / summon

Browser for the Local Web of Things
18 stars 7 forks source link

Application Error #10

Open bradjc opened 9 years ago

bradjc commented 9 years ago

Summon gets in a bad state when i try to open the polypoint app.

http://nuclear.eecs.umich.edu/public/ble/tritag/index.html

Looking at logcat has so far proven to be unhelpful.

2015-10-08 20 33 57

bradjc commented 9 years ago

It appears things grind to a halt because the connectFailure callback is getting called repeatedly.

https://github.com/don/cordova-plugin-ble-central#connect

Did the plugin version change? Should I update something?

bradjc commented 9 years ago

Can you tell I'm splitting time between demos and paper? Anywho, it occurred to me that my error handler immediately tries to call connect again, which then of course fails, calling the error handler, and we get a nice cycle.

So the issue is the ble.connect() function is now failing right out of the gate.

bradjc commented 9 years ago

This is what I have so far:

I get this error when I try to connect to my TriTag device:

"Peripheral C0:98:E5:45:00:0D not found."

I've verified that the device ID has not changed between version 0.0.6 and 0.0.7.

Looking through the megster source, that error only occurs on this check:

Peripheral peripheral = peripherals.get(macAddress);

if (peripheral == null) {
    callbackContext.error("Peripheral " + macAddress + " not found.");
    return;
}

Which means I'm trying to connect to a device that megster doesn't know about.

Now, the only place that the peripherals hash map appears to be cleared is here:

private void findLowEnergyDevices(CallbackContext callbackContext, UUID[] serviceUUIDs, int scanSeconds) {

    // TODO skip if currently scanning

    // clear non-connected cached peripherals
    for(Iterator<Map.Entry<String, Peripheral>> iterator = peripherals.entrySet().iterator(); iterator.hasNext(); ) {
        Map.Entry<String, Peripheral> entry = iterator.next();
        if(!entry.getValue().isConnected()) {
            iterator.remove();
        }
    }

and the only place that findLowEnergyDevices appears to be called is here:

    if (action.equals(SCAN)) {

        UUID[] serviceUUIDs = parseServiceUUIDList(args.getJSONArray(0));
        int scanSeconds = args.getInt(1);
        findLowEnergyDevices(callbackContext, serviceUUIDs, scanSeconds);

    } else if (action.equals(START_SCAN)) {

        UUID[] serviceUUIDs = parseServiceUUIDList(args.getJSONArray(0));
        findLowEnergyDevices(callbackContext, serviceUUIDs, -1);

so my best guess so far is that ble.scan is getting called again before my code runs, which clears the megster cache, which causes my connect() to fail.

bradjc commented 9 years ago

I've addressed my later issue, but now I don't know if this actually had anything to do with my original error.