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

    Connect the Puck.js to The Things Network using a Pycom LoPy

    Scheduled Pinned Locked Moved Projects
    puck-jslopyblelorawanttn
    4 Posts 3 Posters 2.8k Views 3 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.
    • PiAirP Offline
      PiAir
      last edited by

      0_1491760974305_Puck.js_board.jpg
      The Puck.js is a BLE enabled button with built in thermometer, light and battery level sensors. I combined the example code available for the Puck.js and the LoPy so that when you press the Puck.js, it connects via BLE to the LoPy and sends it the current thermometer, light and battery level. The LoPy then posts that data to The Things Network.

      Code etc. available online here.

      1 Reply Last reply Reply Quote 2
      • J Offline
        jmarcelino
        last edited by jmarcelino

        Great write up! I always love new BLE examples :-)

        Just a note on the UUID stuff you found. The UUID on LoPy and the Puck are just two different ways to store the same thing, though the Puck is usually the 'standard' way.

        I have a little helper function which given the standard (Puck.js) way, converts it to the LoPy:

        def uuid2bytes(uuid):
            uuid = uuid.encode().replace(b'-',b'')
            tmp = binascii.unhexlify(uuid)
            return bytes(reversed(tmp))
        

        You can then use it as

        srv1 = bluetooth.service(uuid=uuid2bytes('15ECCA29-0B6E-40B3-9181-BE9509B53200'), isprimary=True)

        Since this is your own custom service it's best if you generate your own new UUID, otherwise other devices might be confused if they scan by service (a very common way sadly not yet supported by LoPy)

        You can use the uuidgen command to get your own on Linux or Mac or through one of the many UUID generator sites like https://www.uuidgenerator.net

        1 Reply Last reply Reply Quote 1
        • PiAirP Offline
          PiAir
          last edited by

          Thanks Jose! I added the info to the blog post (with credits of course). The Puck.js doesn't have support for NRF.setScanResponse() yet either. That is planned for the next (major) firmware update.
          The Puck.js has some other nice features though once you start playing with BLE, for example by default it has TX/RX services over BLE (with optional password) so you can reprogram it remotely over BLE, or simply switch the LED lights ON/OFF over BLE - https://www.espruino.com/About+Bluetooth+LE
          An example use would be something like a message waiting button that blinks if messages are waiting and once pressed, over BLE connects to another device to tell it to start reading the messages of something like that.

          RobTuDelftR 1 Reply Last reply Reply Quote 1
          • RobTuDelftR Offline
            RobTuDelft @PiAir
            last edited by

            @PiAir Very nice, thanks for sharing!

            Without data you're just another person with an opinion.
            Hackster | About me

            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