Welcome to the Pycom forum Forum
    • \[\[global:header.categories\]\]
    • \[\[global:header.recent\]\]
    • \[\[global:header.tags\]\]
    • \[\[global:header.popular\]\]
    • Login

    Explore Pybytes | Official Documentation | Report a Firmware Bug/Issue | GitHub

    LOPY BLE Peripheral

    Scheduled Pinned Locked Moved LoPy
    lopybleperipheral
    4 Posts 2 Posters 517 Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • M Offline
      mitchlau
      last edited by

      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

      1. Is there any Peripheral example to follow??
      2. 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 )
      3. 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

      M 1 Reply Last reply Reply Quote 0
      • M Offline
        mitchlau @mitchlau
        last edited by

        @mitchlau

        I get it pair with IOS however i dont know how to sent data over,
        Is anyone can give me an example on this

        import 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)
        
        
        1 Reply Last reply Reply Quote 0
        • J Offline
          johand
          last edited by

          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

          M 1 Reply Last reply Reply Quote 1
          • M Offline
            mitchlau @johand
            last edited by

            @johand

            Thanks for the answer this work prefect

            1 Reply Last reply Reply Quote 0

            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
            • 1 / 1
            • First post
              Last post

            Pycom on Twitter

            Pycom