4
4
5
5
async def main ():
6
6
7
+ b = Bluetooth ()
8
+
9
+ await b .connect (print_response_handler = lambda s : print (s ))
10
+
11
+ # Upload the Lua script
7
12
lua_script = """
8
13
-- Decompression function
9
14
function decomp_func(data)
@@ -13,9 +18,6 @@ async def main():
13
18
-- Register the decompression function
14
19
frame.compression.process_function(decomp_func)
15
20
16
- -- Variable where the compressed data will be stored
17
- compressed_data = ''
18
-
19
21
-- Function to handle the compressed data received from Bluetooth
20
22
function ble_func(data)
21
23
frame.compression.decompress(data, 1024)
@@ -26,21 +28,18 @@ async def main():
26
28
27
29
"""
28
30
29
- compressed_data = bytearray (
30
- b"\x04 \x22 \x4d \x18 \x64 \x40 \xa7 \x6f \x00 \x00 \x00 \xf5 \x3d \x48 \x65 \x6c \x6c \x6f \x21 \x20 \x49 \x20 \x77 \x61 \x73 \x20 \x73 \x6f \x6d \x65 \x20 \x63 \x6f \x6d \x70 \x72 \x65 \x73 \x73 \x65 \x64 \x20 \x64 \x61 \x74 \x61 \x2e \x20 \x49 \x6e \x20 \x74 \x68 \x69 \x73 \x20 \x63 \x61 \x73 \x65 \x2c \x20 \x73 \x74 \x72 \x69 \x6e \x67 \x73 \x20 \x61 \x72 \x65 \x6e \x27 \x74 \x20 \x70 \x61 \x72 \x74 \x69 \x63 \x75 \x6c \x61 \x72 \x6c \x79 \x3b \x00 \xf1 \x01 \x69 \x62 \x6c \x65 \x2c \x20 \x62 \x75 \x74 \x20 \x73 \x70 \x72 \x69 \x74 \x65 \x49 \x00 \xa0 \x20 \x77 \x6f \x75 \x6c \x64 \x20 \x62 \x65 \x2e \x00 \x00 \x00 \x00 \x5f \xd0 \xa3 \x47 "
31
- )
32
-
33
- b = Bluetooth ()
34
-
35
- await b .connect (print_response_handler = lambda s : print (s ))
36
-
37
- # Upload the Lua script
38
31
await b .upload_file (lua_script , "main.lua" )
39
32
await b .send_reset_signal ()
40
33
41
34
await asyncio .sleep (1 )
42
35
43
- # Send compressed data
36
+ # Send the compressed data. Here the total size of the data is is pretty small,
37
+ # but usually you would want to split the data into MTU sized chunks and stitch
38
+ # them together on the device side before decompressing.
39
+ compressed_data = bytearray (
40
+ b"\x04 \x22 \x4d \x18 \x64 \x40 \xa7 \x6f \x00 \x00 \x00 \xf5 \x3d \x48 \x65 \x6c \x6c \x6f \x21 \x20 \x49 \x20 \x77 \x61 \x73 \x20 \x73 \x6f \x6d \x65 \x20 \x63 \x6f \x6d \x70 \x72 \x65 \x73 \x73 \x65 \x64 \x20 \x64 \x61 \x74 \x61 \x2e \x20 \x49 \x6e \x20 \x74 \x68 \x69 \x73 \x20 \x63 \x61 \x73 \x65 \x2c \x20 \x73 \x74 \x72 \x69 \x6e \x67 \x73 \x20 \x61 \x72 \x65 \x6e \x27 \x74 \x20 \x70 \x61 \x72 \x74 \x69 \x63 \x75 \x6c \x61 \x72 \x6c \x79 \x3b \x00 \xf1 \x01 \x69 \x62 \x6c \x65 \x2c \x20 \x62 \x75 \x74 \x20 \x73 \x70 \x72 \x69 \x74 \x65 \x49 \x00 \xa0 \x20 \x77 \x6f \x75 \x6c \x64 \x20 \x62 \x65 \x2e \x00 \x00 \x00 \x00 \x5f \xd0 \xa3 \x47 "
41
+ )
42
+
44
43
await b .send_data (compressed_data )
45
44
46
45
await b .send_break_signal ()
0 commit comments