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

    pack binary trame

    Scheduled Pinned Locked Moved Discussion
    2 Posts 2 Posters 153 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.
    • Q Offline
      quentho
      last edited by

      hello,

      i receive a value from 7 sensors. After that i create a binary trame to send in sigfox. But i can't send the hexa value in sigfox so i try to use the pack function but i have a probleme with the fmt . i don't know which ftm choose. For the moment my code but it's not working because i receive only

      b'\x00\xb0\x00\x00\x00\x00\x00\x00'
      
      class tools:
      
          def trame(capt1,capt2,capt3,capt4):
              result= (1 << 4) | 0001
              result = (result << 10) | capt1
              result = (result << 4 ) | 0010
              result = (result << 10) | capt2
              result = (result << 4 ) | 0011
              result= (result << 12 ) | capt3
              """result = (result << 4 ) | 0100
              result= (result << 8 ) | capt4"""
              print(hex(result))
              result=pack('hhl', result)
              return  result
      
      
      robert-hhR 1 Reply Last reply Reply Quote 0
      • robert-hhR Offline
        robert-hh @quentho
        last edited by

        @quentho If you have three format specifiers in ustruct.pack(), you have to supply three values. The questions is, how you want to pack that into a message? And what is the value range of each sensor? And why do you add these 0001, 0010, 0011, 0100 (1,2,3,4) pattern into the string?

        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