user133052
Member since Aug 2021 • Last active Sep 2021Most recent activity
-
- 3 comments
- 858 views
-
Hi Gordon! my OS is Window10, and programming language is Javascript.
I refer to this example, my frontend framework is Vue.js. I share some of codes of page.bangleCode: `Bangle.setLCDPower(1); Bangle.setLCDTimeout(0); Bangle.setHRMPower(1); var hrmInfo, hrmOffset = 0; var hrmInterval; var btm = g.getHeight()-1; function onHRM(h) { if (counter!==undefined) { // the first time we're called remove // the countdown counter = undefined; g.clear(); } hrmInfo = h; /* On 2v09 and earlier firmwares the only solution for realtime HRM was to look at the 'raw' array that got reported. If you timed it right you could grab the data pretty much as soon as it was written. In new firmwares, '.raw' is not available. */ if (hrmInterval) clearInterval(hrmInterval); hrmInterval = undefined; if (hrmInfo.raw) { hrmOffset = 0; setTimeout(function() { hrmInterval = setInterval(readHRM,41); }, 40); } var px = g.getWidth()/2; g.setFontAlign(0,0); g.clearRect(0,24,239,80); g.setFont("6x8").drawString("Confidence "+hrmInfo.confidence+"%", px, 75); var str = hrmInfo.bpm; g.setFontVector(40).drawString(str,px,45); px += g.stringWidth(str)/2; g.setFont("6x8"); g.drawString("BPM",px+15,45); } Bangle.on('HRM', onHRM); /* On newer (2v10) firmwares we can subscribe to get HRM events as they happen */ Bangle.on('HRM-raw', function(v) { hrmOffset++; if (hrmOffset>g.getWidth()) { hrmOffset=0; g.clearRect(0,80,239,239); g.moveTo(-100,0); } y = E.clip(btm-v.filt/4,btm-10,btm); g.setColor(1,0,0).fillRect(hrmOffset,btm, hrmOffset, y); y = E.clip(170 - (v.raw/2),80,btm); g.setColor(g.theme.fg).lineTo(hrmOffset, y); if (counter !==undefined) { counter = undefined; g.clear(); } }); // It takes 5 secs for us to get the first HRM event var counter = 5; function countDown() { if (counter) { g.drawString(counter--,g.getWidth()/2,g.getHeight()/2, true); setTimeout(countDown, 1000); } } g.clear().setFont("6x8",2).setFontAlign(0,0); g.drawString("Please wait...",g.getWidth()/2,g.getHeight()/2 - 16); countDown(); var wasHigh = 0, wasLow = 0; var lastHigh = getTime(); var hrmList = []; var hrmInfo; function readHRM() { if (!hrmInfo) return; if (hrmOffset==0) { g.clearRect(0,100,239,239); g.moveTo(-100,0); } for (var i=0;i<2;i++) { var hrmData = hrmInfo.raw[hrmOffset]; hrmOffset++; y = E.clip(170 - (hrmData*2),100,230); g.setColor(g.theme.fg).lineTo(hrmOffset, y); var print = ["HRM", hrmData ]; Bluetooth.println( print.join(",") ); } } Bangle.on('accel',function(a) { var d = [ "ACC", Math.round(a.x*100), Math.round(a.y*100), Math.round(a.z*100) ]; Bluetooth.println(d.join(",")); }) `, connectWatch1(state) { let connection1; // disconnect if connected already if (connection1) { connection1.close(); connection1 = undefined; state.watch1.connect = false } // Connect Puck.connect(function(c) { if (!c) { // alert("Couldn't connect!"); // return; state.watch1.connect = false this.connectWatch1() } connection1 = c; state.watch1.connect = true // console.log(connection) // Handle the data we get back, and call 'onLine' // whenever we get a line var buf = ""; connection1.on("data", function(d) { buf += d; var l = buf.split("\n"); buf = l.pop(); l.forEach( (line) => { var d = line.split(',') if (d[0] == 'ACC') { // we have an accelerometer reading state.watch1.accelX = parseInt(d[1]) / 100 state.watch1.accelY = parseInt(d[2]) / 100 state.watch1.accelZ = parseInt(d[3]) / 100 } else if (d[0] == 'HRM') { // we have an accelerometer reading state.watch1.hrm = parseInt(d[1]) } // console.log("RECEIVED:" + state.watch1); } // console.log('RECEIVED:' + line) ); }); // First, reset the Bangle connection1.write("reset();\n", function() { // Wait for it to reset itself setTimeout(function() { // Now upload our code to it connection1.write( "\x03\x10if(1){" + state.bangleCode + "}\n", function() { console.log("Ready..."); } ); }, 1500); }); }); },
thank you for your good source of reconnect!😀
-
Bangle is so interesting, and I using it to get realtime emotional data(from HRM Sensor). but have some problems for stable connection. commonly after 3-5 minutes, bangles connection disconnected.
so I wanna make a code automatically reconnect with no popup window of BLE connection when it disconnected. can you help me? -
you are right, after chrome://flags/#enable-experimental-web-Âplatform-features , check enable, "Argh! TypeError: navigator.bluetooth.requestLEScan is not a function" is disappeared! and andriod chrome recieved all advertisement imformation well, but window 10 chrome not 😂 anyway, your help is so helpful for me, and please share if it possible on window10 environment next time. thank you very much!!
-
- 7 comments
- 1,334 views
-
Dear Gordon, really thank you for your kind.
I try by Windows 10, android(Galaxy10, Chrome), but just see same result
"Argh! TypeError: navigator.bluetooth.requestLEScan is not a function"
I am searching the reason of this alert, just find this kind of answer.
linkIf possible, please show detail of your process by chrome? I want to using it on the chrome web browser 😄
-
-
Hi! I already searching some discussion about this topic,
http://forum.espruino.com/conversations/309175/#comment14957191
Would you please tell me any Idea of data upload to AWS server from Bangle.js?
I just considering web client(REST API) for Bangle raw data sending to AWS,
is it best way?