-
Using the Web Bluetooth api, download a python program. Do I need a backend, or not? Is there a library for that? Tried this: async function downloadProgram() {
const pybricksServiceUUID = 'c5f50001-8280-46da-89f4-6d8051e4aeef';
const pybricksControlEventCharacteristicUUID = 'c5f50002-8280-46da-89f4-6d8051e4aeef';
const device = await navigator.bluetooth.requestDevice({
filters: [
{
services: [pybricksServiceUUID]
}
]
});
const server = await device.gatt.connect();
const service = await server.getPrimaryService(pybricksServiceUUID);
const characteristic = await service.getCharacteristic(pybricksControlEventCharacteristicUUID);
const encoder = new TextEncoder();
const program = encoder.encode('print("Hello")');
await characteristic.writeValue(program);
console.log('Download successful.');
} But it needs to compile the code, or is this happening on the hub? I got Downloading a program with JavaScript would be perfect. It would allow me to build some python generators without needing to copy-paste into Pybricks Code (which I'm actually doing). |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 8 replies
-
There is no library. You can look at the Pybricks Code source code for inspiration. The download and run logic is here: https://github.com/pybricks/pybricks-code/blob/master/src/hub/sagas.ts And most of the WebBluetooth stuff is here: https://github.com/pybricks/pybricks-code/blob/master/src/ble/sagas.ts |
Beta Was this translation helpful? Give feedback.
There is no library. You can look at the Pybricks Code source code for inspiration.
The download and run logic is here: https://github.com/pybricks/pybricks-code/blob/master/src/hub/sagas.ts
And most of the WebBluetooth stuff is here: https://github.com/pybricks/pybricks-code/blob/master/src/ble/sagas.ts