44
55async def main ():
66
7+ b = Bluetooth ()
8+
9+ await b .connect (print_response_handler = lambda s : print (s ))
10+
11+ # Upload the Lua script
712 lua_script = """
813 -- Decompression function
914 function decomp_func(data)
@@ -13,9 +18,6 @@ async def main():
1318 -- Register the decompression function
1419 frame.compression.process_function(decomp_func)
1520
16- -- Variable where the compressed data will be stored
17- compressed_data = ''
18-
1921 -- Function to handle the compressed data received from Bluetooth
2022 function ble_func(data)
2123 frame.compression.decompress(data, 1024)
@@ -26,21 +28,18 @@ async def main():
2628
2729 """
2830
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
3831 await b .upload_file (lua_script , "main.lua" )
3932 await b .send_reset_signal ()
4033
4134 await asyncio .sleep (1 )
4235
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+
4443 await b .send_data (compressed_data )
4544
4645 await b .send_break_signal ()
0 commit comments