Noob question: how to send data through bluetooth
-
Hi everyone, I would like to transmit light intensity measurement through bluetooth but I cannot understand how to do this since I'm a pycom noob and it is not very clear to me the mechanism, I think I lack some basics concepts.
After some attemps I was able to connect to my phone and discover my Fipy using BLE Scanner app but I don't know how to continue.This is my code at the moment
from network import Bluetooth import ubinascii import time import pycom from pycoproc_2 import Pycoproc import machine from LTR329ALS01 import LTR329ALS01 pycom.heartbeat(False) pycom.rgbled(0x0A0A08) # white py = Pycoproc() pybytes_enabled = False if 'pybytes' in globals(): if(pybytes.isconnected()): print('Pybytes is connected, sending signals to Pybytes') pybytes_enabled = True lt = LTR329ALS01(py) bt = Bluetooth() bt.set_advertisement(name='FraccaPy', service_uuid=b'1234567890123456') bt.advertise(True) if not bt.isscanning(): bt.start_scan(-1) # start scanning with no timeout print('Trying to establish connection with Nord') connection = bt.connect('ac5fea133f19') if (connection.isconnected()): print ('Successfully connected to Nord') # while True: # time.sleep(1) # # print read data on screen # print("Light [channel Blue lux, channel Red lux]: " + str(lt.light())) # # switch on led graduated in relation to external light # red = lt.light()[1]*0.5 # blue = lt.light()[0]*0.5 # led = round (red + blue) # pycom.rgbled(led << 8) # # transmit data via Wi-Fi # if(pybytes_enabled): # pybytes.send_signal(1, lt.light())Any help would be greatly appreciated, thanks in advance.
-
We recently provided an example for this here: https://docs.pycom.io/tutorials/networks/ble/callback/
Let me know if that works for you -
@Gijs actually I solved my problem before seeing this , anyway it is very interesting.
In particular, my problem was solved by removingif not bt.isscanning(): bt.start_scan(-1) # start scanning with no timeout print('Trying to establish connection with Nord') connection = bt.connect('ac5fea133f19')I found out these commands were not needed and they broke my code.
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