Send data from WiPy to LoPy with BLE
-
Hi,
I' m trying to send data (I just need to send a temperature value) via BLE from WiPy to LoPy with the example posted on the offical documentation.
The boards connects properly, but when the Client tries to get the services list (services = conn.services()) it doesn't succeed.
LoPy (Client):
from network import Bluetooth import time bt = Bluetooth() bt.start_scan(-1) while True: adv = bt.get_adv() if adv and bt.resolve_adv_data(adv.data, Bluetooth.ADV_NAME_CMPL) == 'WiPy': try: conn = bt.connect(adv.mac) services = conn.services() print(services) for service in services: print(service.uuid()) time.sleep(0.050) if type(service.uuid()) == bytes: print('Reading chars from service = {}'.format(service.uuid())) else: print('Reading chars from service = %x' % service.uuid()) chars = service.characteristics() for char in chars: if (char.properties() & Bluetooth.PROP_READ): print('char {} value = {}'.format(char.uuid(), char.read())) conn.disconnect() break except: print("Error while connecting or reading from the BLE device") break else: time.sleep(0.050)WiPy (Server):
from network import Bluetooth import pycom pycom.heartbeat(False) bluetooth = Bluetooth() bluetooth.set_advertisement(name='WiPy', service_uuid=b'1234567890123456') def conn_cb (bt_o): events = bt_o.events() if events & Bluetooth.CLIENT_CONNECTED: print("Client connected") pycom.rgbled(0x007f00) # green elif events & Bluetooth.CLIENT_DISCONNECTED: print("Client disconnected") pycom.rgbled(0x7f0000) # red bluetooth.callback(trigger=Bluetooth.CLIENT_CONNECTED | Bluetooth.CLIENT_DISCONNECTED, handler=conn_cb) bluetooth.advertise(True) srv1 = bluetooth.service(uuid=b'1234567890123456', isprimary=True) chr1 = srv1.characteristic(uuid=b'ab34567890123456', value=5) char1_read_counter = 0 def char1_cb_handler(chr): global char1_read_counter char1_read_counter += 1 events = chr.events() if events & Bluetooth.CHAR_WRITE_EVENT: print("Write request with value = {}".format(chr.value())) else: if char1_read_counter < 3: print('Read request on char 1') else: return 'ABC DEF' char1_cb = chr1.callback(trigger=Bluetooth.CHAR_WRITE_EVENT | Bluetooth.CHAR_READ_EVENT, handler=char1_cb_handler) srv2 = bluetooth.service(uuid=1234, isprimary=True) chr2 = srv2.characteristic(uuid=4567, value=0x1234) char2_read_counter = 0xF0 def char2_cb_handler(chr): global char2_read_counter char2_read_counter += 1 if char2_read_counter > 0xF1: return char2_read_counter char2_cb = chr2.callback(trigger=Bluetooth.CHAR_READ_EVENT, handler=char2_cb_handler) -
@amartinez
Will be better if you post textual data not images
to post code you can surround it by triple ```
link to other possible formatting
http://commonmark.org/help/ -
@livius done, sorry.
-
I've updated the WiPy (Server) code with Alex's help, but it still not working.
from network import Bluetooth import pycom pycom.heartbeat(False) bluetooth = Bluetooth() bluetooth.set_advertisement(name='WiPy', service_uuid=b'1234567890123456') pycom.rgbled(0x00007f) # Blue def conn_cb(bt_o): events = bt_o.events() if events & Bluetooth.CLIENT_CONNECTED: print("Client connected") pycom.rgbled(0x007f00) # green elif events & Bluetooth.CLIENT_DISCONNECTED: print("Client disconnected") pycom.rgbled(0x7f0000) # red bluetooth.callback(trigger=Bluetooth.CLIENT_CONNECTED | Bluetooth.CLIENT_DISCONNECTED, handler=conn_cb) bluetooth.advertise(True) srv1 = bluetooth.service(uuid=b'1234567890123456', isprimary=True) char1 = srv1.characteristic(uuid=b'ab34567890123456', value=25) temperature = 27 #Temperature value char1.value(temperature) srv1.start() -
Hi @amartinez,
I've been testing this out this morning and it appears to be a bug in the connecting device code - I've just been speaking with Daniel and he's going to debug it today. I'll keep you in the loop and you can see the github issue here - https://github.com/pycom/pycom-micropython-sigfox/issues/15.
-
@bucknall Thank you so much! I' m a bit desesperated with this!
-
@amartinez
hi
i have same problem like
services=conn.services() is not started how to solve if you get a answer. -
@nagarjuna-reddy same here
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better π
Register Login