Feeding data from Android phone to Bangle.js continuously? #5719
Replies: 1 comment
-
Posted at 2020-11-30 by @gfwilliams Hi! This is something that's been a frustration for me for a while. Basically Gadgetbridge is big on privacy, so much so that they will never add any internet connectivity to it (although you could build it in yourself). Since Gadgetbridge has the Bluetooth connection open you're also a bit stuck for Bluetooth comms. My personal wish would be have a WebView running in Gadgetbridge that has access to send/receive from Bangle.js - but given the lack of internet access that's not an option. I'd been talking to Andreas (one of the lead developers) about this and he is willing to try and add something, but it seems that inter-process comms in Android can also be a bit insecure so it's actually a bit tricky. So right now I think you have a few options - ordered by how hard they are :)
Posted at 2020-11-30 by epw Thank you, this is really good detail! Interesting to hear about Gadgetbridge's reasoning. I can definitely respect it. I'll keep an eye out for updates, but won't wait on them. You're right that a notification would be easiest, but I do hope to avoid it, because I get notifications when the number I care about goes out of bounds (too high or too low), and so also having them for ordinary values (which I want to check idly from time to time) would become too busy. I didn't realize that the phone could advertise the data and the Bangle.js could pick it up. That sounds very promising. I don't actually care about privacy for this case. Even though it's technically medical information, I honestly am perfectly fine with someone else (someone would would have to be near me, even) knowing it. I mean, I actually publish the data to a website, I just don't share that URL too much. Convenience way outweighs privacy for me for this particular case. I'll take a look at this route. I assume that I'll need a (tiny) Android app to advertise the data. Oh, and if I ever decide I really do care about security, I'll set up a one-time pad or something to encrypt the data. I'm constantly surprised by Bluetooth semantics. The Bangle.js connecting to the phone is definitely interesting. I agree it's a pain, but, assuming it doesn't cost too much for either of their batteries, I might look at that long-term. If I could make it work then I could have a general pipe for data between them and that sounds fantastic. Thanks again! I don't know if any of this will become an app that would make sense to publish, but I'll at least update this thread with my findings in case anyone else comes looking. Posted at 2020-12-01 by @gfwilliams
Yes, I think so... You might be able to use DroidScript but I'm not sure how much Bluetooth support it has - probably using Android directly will be easier in this case. In terms of power usage, it'd use less power to have a connection - the most power consuming part of Bluetooth is receiving data, and when there's a connection the devices arrange that they're only listening for data at certain times. When you're listening for Advertising data you can't be sure when it'll be, so you have to listen all the time which takes a bunch of power. However it's less of a deal on the Bangle - realistically you could listen for Bluetooth data for a full 24 hours before the battery ran out. In reality I imagine you'll end up listening maybe every 30 seconds for just enough time to get advertising data (~0.5 sec?) so the impact to battery will go right down. All you need is something like:
That would be great! Getting data onto the Bangle is something a lot of people would be interested in. Posted at 2020-12-01 by Abhigkar This conversation brings me an idea. What if we create a small Android app made in MIT App Inventor for BangleJS? But yes there is a caveat is MIT app inventor apps does not supports background services or task out of the box for web the app will be in background no notifications will be sent to BangleJs. But this can be fixed via adding some extension. Few are paid but those are more then hack. Posted at 2020-12-01 by @gfwilliams Do you think using App Inventor really helps? I'd have thought just a basic Android app would probably be more use for most people? The problem is really the interaction with Gadgetbridge (if you're using that). If you're not, and you don't care about background apps, then Web Bluetooth apps work great Posted at 2020-12-01 by @gfwilliams Just to add, the advertising works well. I:
It might be hard to filter by device mac address as modern phones change their address to stop tracking, so using manufacturerdata works pretty well. I believe this is what you need to do it directly from an Android app: https://developer.android.com/reference/android/bluetooth/le/BluetoothLeAdvertiser Note: I have the Covid contact tracing enabled on my phone, and that stops nRF connect from advertising any data - so you'll either need to disable the app, or use a different phone to be able to use advertising correctly. Hopefully once the vaccine is widespread the contact tracing will be a thing of the past though. Posted at 2020-12-01 by Abhigkar Yes, not sure I am following you, but I think MIT app is more capable of doing lots of custom things. And BangleJs needs it’s very own app to interact with. Basic use case of app where you can push latest news, announcement and update. Very own way to send notifications to BangleJs. Web Ble App Store works grate for installing and updating apps but it is not practical to do everyday “smartwatch” stuff from mobile browser as a use needs a lot user actions to perform a simple task. A dedicated app would make more sense to me. Posted at 2020-12-01 by Abhigkar Let’s start collate an Idea and user of BangleJs design and develop it. “Form the community, For the community” model. Posted at 2020-12-01 by @gfwilliams
Maybe you could do that as a separate thread to avoid pulling @epw's off-topic? Posted at 2020-12-01 by Abhigkar Sure @gfwilliams. Sorry @epw, my intention was not to hijack your thread :). Posted at 2020-12-02 by epw No problem @abhigkar, and in fact that's just where I was going next! So please do start that thread, and I'll be there. Gordon, thank you for the continued direction! I had been hoping to test it out before writing a little app, but didn't know about nRF Connect, only nRF Toolbox. I haven't had a chance to try and follow your steps yet but I'm about to start. Posted at 2020-12-02 by epw Working great so far! My current plan has 3 steps:
I'll link the Android app here when I have it. It will be open source, of course. Posted at 2020-12-02 by @gfwilliams Sounds great! I had a little try last night with something that'd grab a URL, pull data out of it and broadcast it. The BLE code you need is:
Posted at 2020-12-02 by @gfwilliams App is here: https://github.com/espruino/AndroidBLEAdvertiser Every 15 minutes it'll fetch the webpage given and set your phone's Bluetooth advertising to Espruino's 0x0590 manufacturer data with the value from the RegEx's first match group. By default it'll show you roughly how many people have been rickrolled to date. Not quite what @epw needs but hopefully it's a good start, and makes it super easy for everyone else to script common tasks (eg grab data from a website, get it on your wrist). Hopefully it's pretty energy efficient too. It's just a shame the Android API appears to stop an app from executing background tasks more often than every 15 minutes Posted at 2020-12-02 by epw That app is great! You're much faster than me. It could even do what I want, since xDrip can run a local Web server, so it could just be pointed to that. And I love the idea in general! However, the 15 minute limitation probably does stop this method from working for me. Updates coming every 5 minutes are about as slow as I can handle for this. xDrip is already running constantly (persistent notification and everything), so I'm investigating having it advertise the data in its broadcast method. It doesn't help the Bangle.js ecosystem as much, but will still teach me things. Thanks for the continued attention! If a Bangle.js "companion app" for Android starts being developed, I'll still definitely want to help with that if I can. Posted at 2020-12-02 by Abhigkar @epw! interestingly PineTime also have a companion app built on top of flutter_blue library and same code can be compile in to Android or iOS app. Unfortunately java/DART are not my skill set. So not able to understand much!! Posted at 2020-12-18 by Prommy This thread is exceptional, as it's tackling a problem I was encountering. What are thoughts on feasibility of these ideas:
My thought is to build a "universal" standard for pushing data to the Bangle, allowing homebrew apps to flexibly acquire it without much user configuration on a phone-based middleman app. Posted at 2020-12-20 by Prommy I'm going to give this a shot. Going to start with creating a list of queries for the app to run: a dictionary of URLs, query frequencies, and methods to process the query result. Push to espruino/Bangle.js. I've a decade of programming experience, but I'm new to Java/Mobile development, so if there's any advice I'm in the market. Posted at 2020-12-21 by @gfwilliams Hi, That'd be great! The poll and report idea is quite interesting and would work great with the advertiser app I posted up. However if you're going to keep a two-way connection to the watch itself open, I'd say it is probably better to actually respond directly to queries from the Bangle.js app. For instance the Bangle.js app might send the text Posted at 2020-12-30 by bchr73 Just ordered my Bangle a few short hours ago, now dizzy with anticipation. I second this thread is exceptional. Personally I'm hoping to have health check status for various web services I maintain displayed as a widget. @epw I think you're use case trumps mine though, quite literally a health check, very worthwhile to be sure.
@gfwilliams my understanding is that is a limitation of the WorkManager API (I have yet to try it out), yes? I believe you make reference to this in your comments (see MIN_PERIODIC_INTERVAL_MILLIS). It seems some people work around this by scheduling a OneTimeWorkRequest instead, with a set delay to control the execution frequency, and ending by calling another OneTimeWorkRequest. Hard not to wrinkle my nose a little bit at this, but Android does seem to have collected an awful lot of scheduling APIs by now, and if you simply want to run your task every 5 minutes... well.. Posted at 2020-12-31 by @gfwilliams
Thanks - yes, that sounds like it could work great (or as you say there seem to be other options as well). If someone wanted to make a PR to add it to https://github.com/espruino/AndroidBLEAdvertiser I'd be more than happy to pull it in :) Posted at 2021-01-02 by bchr73 Happy to! I may need to figure out how to mimic the Bangle in Python or something first though for testing. Does anyone have any recomendations for Bluetooth (LE) libraries? Posted at 2021-01-04 by @gfwilliams
This might help: https://www.espruino.com/Interfacing However trying to emulate a Bangle first (if you're doing connections) might end up sucking up a bunch of time. If you want to debug a Bluetooth LE UART connection I'd suggest getting another Espruino device that you can connect a non-bluetooth UART to - then you can connect over serial and see what's happening on Bluetooth. Official MDBT42 and Pixl.js boards are easy to add a USB-TTL converter to but don't work out of the box, or the cheapest/easiest option is to just get a micro:bit 2, which there are Espruino builds for Posted at 2021-09-15 by nienno Dear @epw, Posted at 2021-09-15 by epw Sadly I have let this languish (in part because I finally got ControlIQ for my insulin pump which has made knowing the moment-to-moment number a bit less pressing). But, I do want to do it, and in fact hearing that there's someone else who could directly use it helps reinvigorate me! It will still take some time but hopefully not another 8 months. Posted at 2021-09-16 by nienno @epw Thanks for your answer.
I'd like to do the same thing but with a PineTime . I am trying to use the wasp-os for that platform using micropython but I believe a miss a companion app that accepts web request via BLE and returns the blood glucose data from xDrip. Posted at 2021-09-16 by epw I'm glad to hear you got something to work, @nienno! I think you're right about missing a companion app that accepts a Web request over BLE. The Android app on this thread might be able to do it, by making a Web request itself to http://127.0.0.1:17580, and then publishing that. While I don't think I can give many details on that, I can get you started with https://developer.android.com/training/volley/simple It also might might sense to do this as a "push" action rather than a "pull" one. As in, maybe it would be too slow to make a Web request in order to respond to a BLE request and then give the answer. You can tell xDrip to send a "Broadcast Intent" every time it receives a new reading. The BLE app could then pick up those broadcast intents, and use them to publish the value. Again, I can only get you started, but you enable the broadcast intents by going to Settings -> Other Settings -> Inter-app settings -> Broadcast locally. There's some documentation at https://developer.android.com/guide/components/broadcasts, and it starts with probably-confusing overview, then gets to showing you actual code at the "Receiving broadcasts" heading. Let me know if you'd like me to try to expand on any of this! Posted at 2022-12-15 by phrogg Hello guys, finally got my banglejs! I'm currently working on a solution myself. I found this topic before but wanted to try a head on approach without getting too many hints from you guys... My setup right now is as follows: I have the gadgetbridge banglejs version installed and created a 90% finished widget for my blood sugar, this is nearly finished. I'm currently working on an companion which receives the intents from xdrip and pass it through to the bangle. I was already able to pass through test data, but unfortunately I wasn't able to get the intents from xdrip yet (I have never developed in-depth with intents before especially with external ones). But I just started working on this today, so I guess I hopefully will be finished by the weekend. Is anyone else still working on this? Posted at 2022-12-15 by nienno Hi progg, Posted at 2022-12-15 by phrogg Hello @nienno, Posted at 2022-12-16 by @gfwilliams That sounds great, thanks! And you're able to make it work by sending the Posted at 2022-12-16 by phrogg Exactly, I used that. After work today, I will probably have time to finish everything. Posted at 2022-12-19 by phrogg I've got it! It's alive! Attachments: Posted at 2022-12-19 by phrogg I'm just getting toast notifications like: "Malformed JSON from Bangle.js: End of input at character 43 of [...]" with the json I send to the watch. Does this mean the intend I send is not correctly send over in full length? The strange thing is it worked before, but stopped to work as it seems. Or where does this error come from? Posted at 2022-12-19 by @gfwilliams Great!
I think it just comes if your code is printing something to the console (like That could just be some debug code, or it could actually be an error message from Bangle.js. Maybe you could check your Gadgetbridge logs and see what was actually sent? Posted at 2022-12-20 by phrogg Ah yeah, I noticed. Something got malformed but seems to be working again, I think I will release it in the next days as I kind of beta and wait for feedback to fix further issues, as it is working for me now without any. Posted at 2022-12-21 by phrogg Ok, it is working most of the time, but sometimes the JSON file gets destroyed. I will share my code later and hopefully someone can point me out where the error is. I think it is related to the phone writing the json file in the same time the watch is trying to read it. Are there any ways to lock a file, or something familiar? Posted at 2022-12-22 by phrogg It is online but for testing and sharing purposes only until now. The widget: https://github.com/phrogg/BangleApps and for the app: https://codeberg.org/phrogg/BG2BangleJSApp Posted at 2022-12-29 by phrogg I fixed some bugs, and it works very reliable for me right now. I will make PRs now and try to release it. It's still in beta, though. Posted at 2023-01-03 by myxor @phrogg i can not find your app on Fdroid. Neither by using the link on your git README nor by searching in Fdroid. Posted at 2023-01-03 by phrogg Hey, I didn't release the app in F-Droid yet. Even if I would have, it takes quite some time before it will be approved and added. You can download it under releases in my git though: https://codeberg.org/phrogg/BG2BangleJSApp/releases Also sorry for not doing that already, but I've made some more small improvements, and I'm not done yet completely, so I will open a PR for both the app and the widget after that's figured out. Posted at 2023-01-17 by kenpem Hello, all! Any further updates on this project? I'm about to embark on something very similar myself.. Posted at 2023-01-17 by phrogg Sounds great, I think the best approach would be to improve my approach, I'm currently in finalizing the app so that it will be approved by the f-droid staff. I posted my links above where you can see the app and the widget as well. You can just submit a PR, or we could work together to improve it further. I'm also currently looking into adding the banglejs ability right in xdrip so that no extra app is needed. Posted at 2023-02-10 by Kenoubi Hi @phrogg, your widget isn't working for me (it just shows "BG") in spite of my having all the parts as far as I can tell:
What can I do to troubleshoot? I'd really like this to work. Thanks! Kenn Posted at 2023-02-10 by phrogg Hey, there could be several things, did you allow my app to "Draw over apps" in the settings? Attachments: Posted at 2023-02-11 by Kenoubi @phrogg It works! I had already enabled draw over other apps, but the only receiver I had was Tasker. Now the only problem is it appears to be ignoring the setting for mg/dl and still using mmol/l. Posted at 2023-02-11 by phrogg Great to hear that :) If you just changed it, you will to have to wait for the next value to be received. Does it display correctly now? If not, I should take a look. Posted at 2023-02-13 by Kenoubi Nope, it's refreshed many times but continues to use mmol/l. Posted at 2023-02-14 by phrogg Hmh, strange, I will take a look and reply later today, if my GF does not kill me because of that xD Posted at 2023-02-14 by phrogg Fixed it, see here espruino/BangleApps#2577 |
Beta Was this translation helpful? Give feedback.
-
Posted at 2020-11-30 by epw
Hi!
The two most important features of a smart watch, for my personal use, are displaying notifications, and displaying a particular integer that my phone knows that is updated every 5 minutes (it's my blood sugar, retrieved by xDrip+, but that's not a terribly important detail).
Notifications seem to be easy, thanks Gadgetbridge!
The display of the integer is where things get difficult, and I'm trying to figure out a good starting approach. My experience with Bluetooth has been that it's really easy to get caught in confusing dead ends where you can't tell whether you have some small bug or your whole approach is wrong, so I'd appreciate some direction before I dive in too deep.
The phone can publish the data in a few ways: it's send out as a broadcast Intent in Android, and it can be accessible through a local Web server, so I can write an Android app that hooks into either of those methods and forward it along to any other method, like advertising with Bluetooth.
Then, I'd write a widget or custom watch face in the Bangle.js that listens for that advertisement and displays the value.
However, if I'm reading things right, then this would interfere with other NRF functions, so Gadgetbridge would stop working? I'd really like to know this before I've written the two ends of this system.
It seems like another approach could be to modify Gadgetbridge, to use the channel it already has set up, but to make a special kind of "notification" that is intercepted in the Bangle.js app and interpreted to mean "save these data into storage." Then my widget could just read from storage and display the value there. Of course, this would mean either maintaining my own fork of Gadgetbridge, or getting my code path merged in for this specific, personal need, neither of which seems great.
Does anyone have any insight or suggestions? There's lots of help for using the sensors built into the Bangle.js, but I haven't found anything clear for doing something like this.
Thanks in advance!
Beta Was this translation helpful? Give feedback.
All reactions