I am planning to create a real-time Dashboard in Anvil, where I will Connect a Bluetooth wearable to the Dashboard to show the real-time Health Data.
Before starting the project, I want to know the feasibility of it in Anvil, because of the Javascript work needed for it. can any experts here confirm, will I be able to connect this Bluetooth Device through Javascript/ typescript to Anvil.
here is the example of Javascript code for connecting the device to the Web, from Github
import { MuseClient } from 'muse-js';
async function main() {
let client = new MuseClient();
await client.connect();
await client.start();
client.eegReadings.subscribe(reading => {
console.log(reading);
});
client.telemetryData.subscribe(telemetry => {
console.log(telemetry);
});
client.accelerometerData.subscribe(acceleration => {
console.log(acceleration);
});
}
main();
this project is feasible only if I can connect the Bluetooth device to the dashboard.
I am interested to develop my MVP in Anvil if I can connect this Bluetooth wearable device using the Javascript Bluetooth bridge.
please help me to know the feasibility with Anvil for this project.
thanking you in advance.
I haven’t run all that code, but I did add this script tag to Native Libraries in an Anvil app, imported window from anvil.js to print what it had (dir(window)) and saw MuseClient and a couple other Muse references in the output:
<script src="https://unpkg.com/muse-js@3.3.0/dist/muse.js"></script>
Based on this, it should be possible unless there’s some specific implementation detail that I am unaware of – but you definitely can at least start prototyping with it!
Update: While on the topic of JS imports, here’s the doc to all the ways to access JS code and objects in Anvil: Anvil Docs | Accessing Javascript
3 Likes
Thank you very Much @duncan_richards12 for the quick reply.
I am happy to know it is feasible.
unless there’s some specific implementation detail that I am unaware of
My intention is to get the input data from the device to the anvil and process it for the dashboard in real-time.
surely I will start prototyping and check the docs onceagain.
1 Like
There’s also a version on skypack.dev
import anvil.js
class Form1(Form1Template):
...
def connect_button_click(self, **event_args):
"""When the connect button is clicked"""
self.setup_muse()
def setup_muse(self):
MuseModule = anvil.js.import_from('https://cdn.skypack.dev/muse-js')
MuseClient = MuseModule.MuseClient
client = MuseClient()
client.connect()
client.start()
...
4 Likes