Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getAllDevices() results in null #65

Open
mhr opened this issue Jun 6, 2020 · 2 comments
Open

getAllDevices() results in null #65

mhr opened this issue Jun 6, 2020 · 2 comments

Comments

@mhr
Copy link

mhr commented Jun 6, 2020

Hi,

I tried to create a sample app (below). I tried to write the minimal thing that wouldn't result in exceptions and might work. Unfortunately, when I load my code on two devices with both Location and Bluetooth permissions enabled, neither device picks up on the presence of the other device. There are no exceptions from this code initially, but after a few minutes, the app crashes for no apparent reason.

import React, { useState, useEffect } from "react";
import { Text } from "react-native";
import SpecialBle, { requestLocationPermission, checktLocationPermission } from "rn-contact-tracing";

const SERVICE_UUID = "00000000-0000-1000-8000-00805F9B34FB";

/*
const ScanMatchMode = [
    {value: 1, label: 'MATCH_MODE_AGGRESSIVE'},
    {value: 2, label: 'SCAN_MODE_LOW_LATENCY'},
];

const AdvertiseMode = [
    {value: 0, label: 'ADVERTISE_MODE_LOW_POWER'},
    {value: 1, label: 'ADVERTISE_MODE_BALANCED'},
    {value: 2, label: 'ADVERTISE_MODE_LOW_LATENCY'},
];

const AdvertiseTXPower = [
    {value: 0, label: 'ADVERTISE_TX_POWER_ULTRA_LOW'},
    {value: 1, label: 'ADVERTISE_TX_POWER_LOW'},
    {value: 2, label: 'ADVERTISE_TX_POWER_MEDIUM'},
    {value: 3, label: 'ADVERTISE_TX_POWER_HIGH'},
];
*/

const BluetoothScreen = () => {
    const [permissions, setPermissions] = useState({location: false, ignoreBatteryOpt: false});
    const [config, setConfig] = useState({
        serviceUUID: SERVICE_UUID,
        scanDuration: 10000,
        scanInterval: 10000,
        advertiseInterval: 10000,
        advertiseDuration: 10000,
        scanMatchMode: 1,
        advertiseMode: 2,
        advertiseTXPowerLevel: 1,
        notificationTitle: "Bluetooth",
        notificationContent: "Bluetooth",
        notificationLargeIconPath: "",
        notificationSmallIconPath: "",
        token: "default_token"
    });

    async function checkPermissions() {
        let isGranted = await checktLocationPermission();
        let ignoreBatteryOpt = await SpecialBle.isBatteryOptimizationDeactivated();
        setPermissions({...permissions, ...{location: isGranted, ignoreBatteryOpt: ignoreBatteryOpt}});
    }

    useEffect(() => {
        (async () => {
            console.log("module:", SpecialBle);

            console.log("permissions");
            await checkPermissions();

            console.log("database");
            await SpecialBle.writeContactsToDB(null);

            console.log("set config");
            await SpecialBle.setConfig(config);

            console.log("start ble service");
            await SpecialBle.startBLEService();

            console.log("advertise");
            await SpecialBle.advertise();

            console.log("start scan");
            await SpecialBle.startBLEScan();

            console.log("get all devices");
            await SpecialBle.getAllDevices(devices => {
                console.log(devices);
            });
        })();
    }, []);

    return (<Text>Bluetooth</Text>);
};

export default BluetoothScreen;
 LOG  module: {"advertise": [Function fn], "cleanDevicesDB": [Function fn], "cleanScansDB": [Function fn], "deleteDatabase": [Function fn], "exportAdvertiseAsCSV": [Function fn], "exportAllContactsAsCsv": [Function fn], "exportAllDevicesCsv": [Function fn], "exportAllScansCsv": [Function fn], "exportScansByKeyAsCSV": [Function fn], "exportScansDataAsCSV": [Function fn], "fetchInfectionDataByConsent": [Function fn], "getAllDevices": [Function fn], "getAllScans": [Function fn], "getConfig": [Function fn], "getConstants": [Function anonymous], "getScansByKey": [Function fn], "isBatteryOptimizationDeactivated": [Function fn], "match": [Function fn], "requestToDisableBatteryOptimization": [Function fn], "setConfig": [Function fn], "setPublicKeys": [Function fn], "startBLEScan": [Function fn], "startBLEService": [Function fn], "stopAdvertise": [Function fn], "stopBLEScan": [Function fn], "stopBLEService": [Function fn], "writeContactsToDB": [Function fn]}
 LOG  permissions
 LOG  database
 LOG  set config
 LOG  start ble service
 LOG  advertise
 LOG  start scan
 LOG  get all devices
 LOG  null
@Xeceryn
Copy link

Xeceryn commented Aug 9, 2020

is there a solution for the "null" getDevice () function?

@Xeceryn
Copy link

Xeceryn commented Aug 9, 2020

Change to this.

SpecialBle.getAllDevices((err, devices) => {
       setDevices(devices)
})

it work for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants