LOPY BLE Peripheral
-
Hi i am beginner of LOPY
I am trying to send pysense data to i phone from BLE
As a result i am trying to {lopy as Peripheral -------(send data)------->i phone (central)}
My question is- Is there any Peripheral example to follow??
- I have import the library on the code however there is no file Bluetooth or network (Not sure where to find the library if i need to upload with Pymakr )
- why the code below result as 9999999999999??
I use the code below
import ubinascii from network import Bluetooth from time import sleep bt = Bluetooth() bt.init() bt.set_advertisement(name="lopy", manufacturer_data="lopy_v1") if bt.isscanning(): bt.stop_scan() bt.start_scan(-1) while bt.isscanning(): adv = bt.get_adv() if adv: print(adv)
RESULT::
mode:DIO, clock div:1
load:0x3fff8028,len:8
load:0x3fff8030,len:1728
load:0x4009fa00,len:0
load:0x4009fa00,len:14612
entry 0x400a059c
9
9
9
9
9
9
9
9
-
Thanks for the answer this work prefect
-
For BLE pairing is not needed.
Look at this example: https://docs.pycom.io/firmwareapi/pycom/network/bluetooth/gattscharacteristic.html
To send data, use:
chr2.value(MyData)
Johan
-
I get it pair with IOS however i dont know how to sent data over,
Is anyone can give me an example on thisimport binascii from network import Bluetooth from machine import Timer import time bluetooth = Bluetooth() bluetooth.set_advertisement(name='LoPy', service_uuid=b'1234567890123456') def conn_cb (bt_o): events = bt_o.events() # this method returns the flags and clears the internal registry if events & Bluetooth.CLIENT_CONNECTED: print("Client connected") while True: print("data send") bluetooth.set_advertisement(name='LoPy',manufacturer_data="lopy_v1") time.sleep(2.050) elif events & Bluetooth.CLIENT_DISCONNECTED: print("Client disconnected") bluetooth.callback(trigger=Bluetooth.CLIENT_CONNECTED | Bluetooth.CLIENT_DISCONNECTED, handler=conn_cb) bluetooth.advertise(True)