From d96af8762909a028314805b396139f092f481506 Mon Sep 17 00:00:00 2001 From: Stepan Usatiuk Date: Mon, 18 Apr 2022 16:39:29 +0200 Subject: [PATCH] prettify a bit --- door-thing-app/src/App.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/door-thing-app/src/App.tsx b/door-thing-app/src/App.tsx index e9c67bf..ce04981 100644 --- a/door-thing-app/src/App.tsx +++ b/door-thing-app/src/App.tsx @@ -25,13 +25,13 @@ export function App() { }); console.log("Found device:"); console.log(foundDevice); + await foundDevice.gatt.connect(); foundDevice.ongattserverdisconnected = onDisconnect; const doorService = await foundDevice.gatt.getPrimaryService( doorServiceUUID, ); - const doorSwitch = await doorService.getCharacteristic(doorSwitchUUID); setDevice({ device: foundDevice, @@ -40,11 +40,10 @@ export function App() { }); const data = await (await doorSwitch.readValue()).getUint8(0); + setDoorOpen(Boolean(data)); doorSwitch.oncharacteristicvaluechanged = onDoorUpdate; doorSwitch.startNotifications(); - - setDoorOpen(Boolean(data)); } catch (error) { console.log("Error connecting:"); console.log(error); @@ -62,6 +61,7 @@ export function App() { const onDisconnect = async () => { setDevice(null); + setDoorOpen(null); }; const onDisconnectClick = async () => {