From 8262498b2a76968d78ff7ac44ce9ee3cd59d0e81 Mon Sep 17 00:00:00 2001 From: Alain Saas Date: Mon, 27 Dec 2021 06:22:30 +0900 Subject: [PATCH] Update awair_to_bangle.html --- apps/awairmonitor/awair_to_bangle.html | 367 ++++++++++++------------- 1 file changed, 179 insertions(+), 188 deletions(-) diff --git a/apps/awairmonitor/awair_to_bangle.html b/apps/awairmonitor/awair_to_bangle.html index 8624d01f6..69c52499f 100644 --- a/apps/awairmonitor/awair_to_bangle.html +++ b/apps/awairmonitor/awair_to_bangle.html @@ -1,124 +1,204 @@ - - - - + + + + + - function checkIfSupported() { - // Hack for windows - if (navigator.platform.indexOf("Win")>=0 && - (navigator.userAgent.indexOf("Chrome/54")>=0 || - navigator.userAgent.indexOf("Chrome/55")>=0 || - navigator.userAgent.indexOf("Chrome/56")>=0) - ) { - console.warn("Chrome <56 in Windows has navigator.bluetooth but it's not implemented properly"); - if (confirm("Web Bluetooth on Windows is not yet available.\nPlease click Ok to see other options for using Web Bluetooth")) - window.location = "https://www.espruino.com/Puck.js+Quick+Start"; - return false; - } - if (navigator.bluetooth) return true; - console.warn("No Web Bluetooth on this platform"); - var iOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream; - if (iOS) { - if (confirm("To use Web Bluetooth on iOS you'll need the WebBLE App.\nPlease click Ok to go to the App Store and download it.")) - window.location = "https://itunes.apple.com/us/app/webble/id1193531073"; - } else { - if (confirm("This Web Browser doesn't support Web Bluetooth.\nPlease click Ok to see instructions for enabling it.")) - window.location = "https://www.espruino.com/Quick+Start+BLE#with-web-bluetooth"; - } - return false; - } +

+How to use +

+Step 1: Enable the Local API on your Awair: https://support.getawair.com/hc/en-us/articles/360049221014-Awair-Local-API-Feature +

+Step 2: Launch the Awair Monitor app on your BangleJS +

+Step 3: Input your Awair IP address and click the Connect button: + + +

+Step 4: Optionally, open the web inspector's console (Right click > Inspector > Console) to read the Bluetooth logs +

+Step 5: Once you are done, click the Disconnect button to properly close the Blutooth connection +

+

- var NORDIC_SERVICE = "6e400001-b5a3-f393-e0a9-e50e24dcca9e"; - var NORDIC_TX = "6e400002-b5a3-f393-e0a9-e50e24dcca9e"; - var NORDIC_RX = "6e400003-b5a3-f393-e0a9-e50e24dcca9e"; - var DEFAULT_CHUNKSIZE = 20; +

- function log(level, s) { - if (puck.log) puck.log(level, s); - } - - function ab2str(buf) { - return String.fromCharCode.apply(null, new Uint8Array(buf)); +
+
+
+
+
+ +(buf)); } function str2ab(str) { @@ -590,93 +670,4 @@ function initChart() { let last_update = dataPoints_1['temp'].length-1; if (is_connected && bt_connection && bt_connection.isOpen) { - bt_connection.write('\x10bt_current_co2='+current_co2+';bt_current_voc='+current_voc+';bt_current_pm25='+current_pm25+';bt_current_humi='+current_humi+';bt_current_temp='+current_temp+';bt_last_update='+last_update+';\n'); - - console.log("Sent data through Bluetooth"); - } else if (is_connected && bt_connection && !bt_connection.isOpen) { - console.log("Disconnected - Next attempt to reconnect in " + reconnect_counter); - reconnect_counter--; - - if (reconnect_counter <= 0) { - reconnect_counter = 10 * reconnect_attempt_counter; - reconnect_attempt_counter++; - - console.log("Trying to reconnect"); - bt_connection.reconnect(function(c) { - console.log("Reconnect callback"); - if (!c) { - console.log("Couldn't reconnect"); - return; - } - bt_connection = c; - is_connected = true; - reconnect_attempt_counter = 1; - }); - } - } - - setTimeout(function(){updateChart()}, 1000); - }); - } -} - -function connectBT() { - console.log("Connect BT"); - Puck.connect(function(c) { - console.log("Connect callback"); - if (!c) { - console.log("Couldn't connect"); - return; - } - bt_connection = c; - is_connected = true; - reconnect_attempt_counter = 1; - if (!is_chart_started) { - initChart(); - is_chart_started = true; - } - }); -} - -function disconnectBT() { - console.log("Disconnect Bluetooth button pressed. bt_connection value below.") - console.log(bt_connection); - if (is_connected && bt_connection) { - bt_connection.close(); - is_connected = false; - console.log("Closed Bluetooth connection"); - } -} - - - - - - - -

-How to use -

-Step 1: Enable the Local API on your Awair: https://support.getawair.com/hc/en-us/articles/360049221014-Awair-Local-API-Feature -

-Step 2: Launch the Awair Monitor app on your BangleJS -

-Step 3: Input your Awair IP address and click the Connect button: - - -

-Step 4: Optionally, open the web inspector's console (Right click > Inspector > Console) to read the Bluetooth logs -

-Step 5: Once you are done, click the Disconnect button to properly close the Blutooth connection -

-

- -

- -
-
-
-
-
- - + bt_connection.write('\x10bt_current_co2='+current_co2+';bt_current_voc='+current_voc+';bt_current_pm25='+current_pm25+';bt_current_humi='+current_humi+';bt_current_temp='+current_temp+';bt_