From 8f9b130eccc1fe1a1c214d3ee0850358dc40ec81 Mon Sep 17 00:00:00 2001 From: "K. Shankari" Date: Thu, 28 Mar 2024 18:23:47 -0700 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20=20Use=20a=20static=20iden?= =?UTF-8?q?tifier=20and=20make=20the=20major=20and=20minor=20values=20opti?= =?UTF-8?q?onal?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://github.com/e-mission/e-mission-docs/issues/1062#issuecomment-2026422960 Testing done: - Added values with and without a major and minor value https://github.com/e-mission/e-mission-docs/issues/1062#issuecomment-2026438347 --- www/js/bluetooth/BluetoothScanPage.tsx | 39 +++++++++++--------------- 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/www/js/bluetooth/BluetoothScanPage.tsx b/www/js/bluetooth/BluetoothScanPage.tsx index bdb352946..ea209804e 100644 --- a/www/js/bluetooth/BluetoothScanPage.tsx +++ b/www/js/bluetooth/BluetoothScanPage.tsx @@ -21,17 +21,19 @@ import { */ const BluetoothScanPage = ({ ...props }: any) => { + const STATIC_ID = "edu.berkeley.eecs.emission"; + const { t } = useTranslation(); const [bluetoothClassicList, setBluetoothClassicList] = useState([]); const [sampleBLEDevices, setSampleBLEDevices] = useState({ '426C7565-4368-6172-6D42-6561636F6E74': { - identifier: 'Katie_BLEBeacon', + identifier: STATIC_ID, minor: 4949, major: 3838, in_range: false, }, '426C7565-4368-6172-6D42-6561636F6E73': { - identifier: 'Louis-Beacon', + identifier: STATIC_ID, minor: 4949, major: 3838, in_range: false, @@ -41,9 +43,8 @@ const BluetoothScanPage = ({ ...props }: any) => { const [isScanningBLE, setIsScanningBLE] = useState(false); const [isClassic, setIsClassic] = useState(false); const [newUUID, setNewUUID] = useState(null); - const [newIdentifier, setNewIdentifier] = useState(null); - const [newMajor, setNewMajor] = useState(0); - const [newMinor, setNewMinor] = useState(0); + const [newMajor, setNewMajor] = useState(undefined); + const [newMinor, setNewMinor] = useState(undefined); const { colors } = useTheme(); // Flattens the `sampleBeacons` into an array of BLEBeaconDevices @@ -135,7 +136,7 @@ const BluetoothScanPage = ({ ...props }: any) => { // Need UUID value on iOS only, not Android (2nd parameter) // https://stackoverflow.com/questions/38580410/how-to-scan-all-nearby-ibeacons-using-coordova-based-hybrid-application const beaconRegion = new window['cordova'].plugins.locationManager.BeaconRegion( - sampleBeacon.identifier, + STATIC_ID, sampleBeacon.uuid, sampleBeacon.major, sampleBeacon.minor, @@ -155,7 +156,7 @@ const BluetoothScanPage = ({ ...props }: any) => { beaconsToArray().forEach((sampleBeacon: BLEBeaconDevice) => { setRangeStatus(sampleBeacon.uuid, false); // "zero out" the beacons const beaconRegion = new window['cordova'].plugins.locationManager.BeaconRegion( - sampleBeacon.identifier, + STATIC_ID, sampleBeacon.uuid, sampleBeacon.major, sampleBeacon.minor, @@ -174,20 +175,19 @@ const BluetoothScanPage = ({ ...props }: any) => { }; // Add a beacon with the new UUID to the list of BLE devices to scan - function addNewUUID(newUUID: string, newIdentifier: string, newMajor: number, newMinor: number) { + function addNewUUID(newUUID: string, newMajor: number, newMinor: number) { console.log("Before adding UUID "+newUUID+" entries = "+sampleBLEDevices); const devicesWithAddition = {...sampleBLEDevices}; devicesWithAddition[newUUID] = { - identifier: newIdentifier, + identifier: STATIC_ID, minor: newMajor, major: newMinor, in_range: false, } setSampleBLEDevices(devicesWithAddition); setNewUUID(null); - setNewIdentifier(null); - setNewMajor(null); - setNewMinor(null); + setNewMajor(undefined); + setNewMinor(undefined); } const BluetoothCardList = ({ devices }) => { @@ -285,27 +285,22 @@ const BluetoothScanPage = ({ ...props }: any) => { setNewUUID(t)} /> setNewIdentifier(t)} - /> - setNewMajor(t)} /> setNewMinor(t)} /> -