Lucas hace 7 meses
padre
commit
84b7460d48
Se han modificado 2 ficheros con 57 adiciones y 0 borrados
  1. 48 0
      ESPBLE.py
  2. 9 0
      listtesting.py

+ 48 - 0
ESPBLE.py

@@ -0,0 +1,48 @@
+import asyncio
+from bleak import BleakScanner
+from bleak import BleakClient
+
+target_name = "Long name works now"
+
+SERVICE_UUID=        "d86aecf2-d87d-489f-b664-b02de82b2fc0"
+CHARACTERISTIC_UUID= "d86aecf2-d87d-489f-b664-b02de82b2fc0"
+
+async def connect():
+    target_address = None
+    devices = await BleakScanner.discover()
+    for d in devices:
+        print(d)
+        if target_name == d.name:
+            target_address = d.address
+            print("found target {} bluetooth device with address {} ".format(target_name,target_address))
+            break
+        else:
+            print("could not find device")
+    return target_address
+
+async def main():
+    target_address = await connect()
+
+    if target_address is not None:
+        async with BleakClient(target_address) as client:
+            print(f"Connected: {client.is_connected}")
+
+            while 1:
+                #text = input()
+                #if text == "quit":
+                #    break
+
+                #await client.write_gatt_char(CHARACTERISTIC_UUID, bytes(text, 'UTF-8'), response=True)
+
+                try:
+                    data = await client.read_gatt_char(CHARACTERISTIC_UUID)
+                    datastr = data.decode('utf-8') #convert byte to str
+                    print("data: {}".format(datastr))
+
+                except Exception:
+                    print("failed to get data, restarting connection.")
+
+
+
+
+asyncio.run(main())

+ 9 - 0
listtesting.py

@@ -0,0 +1,9 @@
+data = "2.123,2048.9999,9.3,99.4,992,904.0"
+dlist = data.split(",")
+print(dlist)
+intlist = []
+
+for string in dlist:
+    intlist.append(float(string))
+
+print(intlist)