Looks like my code didnt post well, I will try again.
bleak code
#!/usr/bin/env python3 import asyncio import array from bleak import discover from bleak import BleakClient import json [#create](https://forum.espruino.com/search/?q=%23create) dictionary for the data to be sent dict = {'Code': '10'} address = "D8:AB:E0:B7:F5:AE" UUID_NORDIC_TX = "6e400002-b5a3-f393-e0a9-e50e24dcca9e" UUID_NORDIC_RX = "6e400003-b5a3-f393-e0a9-e50e24dcca9e" command = "Y('+json.dumps(dict)+')\n" def uart_data_received(sender, data): print("RX> {0}".format(data)) async def run(): devices = await discover() for d in devices: print(d) print("Connecting...") async def run(address, loop): async with BleakClient(address, loop=loop) as client: print("Connected") await client.start_notify(UUID_NORDIC_RX, uart_data_received) print("Writing command") c=command while len(c)>0: await client.write_gatt_char(UUID_NORDIC_TX,bytearray((c[0:20]),'utf-8') , True) c = c[20:] print("Waiting for data") await asyncio.sleep(1.0, loop=loop) # wait for a response print("Done!") loop = asyncio.get_event_loop() loop.run_until_complete(run(address, loop))
Console
Connecting... Connected Writing command Waiting for data RX> bytearray(b'Y({"Code": "10"})\r\n') RX> bytearray(b'Y({"Code": "10"})\r\n') RX> bytearray(b'Uncaught Error: Func') RX> bytearray(b'Uncaught Error: Func') RX> bytearray(b'tion "split" not fou') RX> bytearray(b'tion "split" not fou') RX> bytearray(b'nd!\r\n at line 1 col ') RX> bytearray(b'nd!\r\n at line 1 col ') RX> bytearray(b'250\r\n...ect(c/2-b,44') RX> bytearray(b'250\r\n...ect(c/2-b,44') RX> bytearray(b',c/2+b,45)}b=e.split') RX> bytearray(b',c/2+b,45)}b=e.split') RX> bytearray(b'("\\n");var h=(f-16*b') RX> bytearray(b'("\\n");var h=(f-16*b') RX> bytearray(b'.length)...\r\n ') RX> bytearray(b'.length)...\r\n ') RX> bytearray(b' ') RX> bytearray(b' ') RX> bytearray(b' ^\r\nin function ca') RX> bytearray(b' ^\r\nin function ca') RX> bytearray(b'lled from line 1 col') RX> bytearray(b'lled from line 1 col') RX> bytearray(b' 19\r\nE.showMessage(d') RX> bytearray(b' 19\r\nE.showMessage(d') RX> bytearray(b'ict);\r\n ') RX> bytearray(b'ict);\r\n ') RX> bytearray(b' ^\r\nat line 1 co') RX> bytearray(b' ^\r\nat line 1 co') RX> bytearray(b'l 19\r\nE.showMessage(') RX> bytearray(b'l 19\r\nE.showMessage(') RX> bytearray(b'dict);\r\n ') RX> bytearray(b'dict);\r\n ') RX> bytearray(b' ^\r\nin function') RX> bytearray(b' ^\r\nin function') RX> bytearray(b' "Y" called from lin') RX> bytearray(b' "Y" called from lin') RX> bytearray(b'e 1 col 17\r\nY({"Code') RX> bytearray(b'e 1 col 17\r\nY({"Code') RX> bytearray(b'": "10"})\r\n ') RX> bytearray(b'": "10"})\r\n ') RX> bytearray(b' ^\r\n>') RX> bytearray(b' ^\r\n>')
Code on watch
E.showMessage("Hello Code"); function Y(dict) { E.showMessage(dict); }
@user118216 started
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Looks like my code didnt post well, I will try again.
bleak code
Console
Code on watch