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

    Data format for Sigfox transmission

    Scheduled Pinned Locked Moved SiPy
    4 Posts 3 Posters 364 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.
    • J Offline
      jez
      last edited by

      Hi Folks,

      I'm stepping out of my comfort zone here and I'm sure I'm struggling on a simple task but I hope you can help.

      I've successfully integrated a Sipy into a 3rd party monitoring platform via Azure, works beautifully.

      However my test has involved simply sending example text eg

      s.send("23005000") #send 23.00°C and 50.00%rh
      

      Now I want to obviously use a variable to insert the real temp and humidity (for example), I feel I have tried a million permutations of hex, bytes etc etc and always get a error or the data is not received correctly on the Sigfox backend.

      Can anyone give me a steer here on the correct approach (using micropython) or point me to some suitable documentation

      Out simply eg the below is clearly wrong, so how do you process a float for transmission?

      temp = 23.00
      hum = 50.00
      s.send(temp+hum) 
      
      

      Thanks

      R 1 Reply Last reply Reply Quote 0
      • R Offline
        rskoniec @jez
        last edited by rskoniec

        @jez According to the docs maybe you should try with bytes:

        s.send(bytes([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]))
        

        The machine is working as good as it's code.

        1 Reply Last reply Reply Quote 1
        • J Offline
          jez
          last edited by

          Ok... so can you explain how do you create a list of bytes from a int or float for example? Would you just chop it up into individual characters or use hex?

          robert-hhR 1 Reply Last reply Reply Quote 0
          • robert-hhR Offline
            robert-hh @jez
            last edited by

            @jez You can use the ustruct module to get a packed byte string. See https://docs.pycom.io/firmwareapi/micropython/ustruct/. If you prefer readable content, you can use one of the two format methods: % operator or str.format(). The result is a str, which you may have to convert to a bytes object with str.encode().
            Both is pretty much standard Python.

            1 Reply Last reply Reply Quote 1

            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