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

    Receive USRP data on lopy lora

    Scheduled Pinned Locked Moved LoPy
    lora lopy
    6 Posts 2 Posters 1.1k 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.
    • N Offline
      nilam
      last edited by

      i tried to receive data from USRP, my code to receive data is
      rx_data = s.recv(64)
      if(rx_data):
      print("Received data: "+str(rx_data))

      received data is not in properly decoded
      it displays some things like this:

      Rx_cnt:12
      (rx_timestamp=2217324419, rssi=-78, snr=1.0, sfrx=8, sftx=0, tx_trials=0)
      Received data: b'\xbd\xca'
      Rx_cnt:13
      (rx_timestamp=2218930349, rssi=-79, snr=2.0, sfrx=8, sftx=0, tx_trials=0)
      Received data: b'\xc5+*\xfe'
      Rx_cnt:14
      (rx_timestamp=2219519010, rssi=-75, snr=1.0, sfrx=8, sftx=0, tx_trials=0)
      Received data: b'\xe7\xdfl\xfb'
      Rx_cnt:15
      (rx_timestamp=2220686254, rssi=-84, snr=-0.0, sfrx=8, sftx=0, tx_trials=0)
      Received data: b'\xad\xee'
      Rx_cnt:16
      (rx_timestamp=2221272054, rssi=-77, snr=2.0, sfrx=8, sftx=0, tx_trials=0)
      Received data: b'\x95\xe7\xb8\xfa\xf0c\xee'
      Rx_cnt:17
      (rx_timestamp=2221760271, rssi=-93, snr=-3.0, sfrx=8, sftx=0, tx_trials=0)
      how to decode to get hex bytes or string text output

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

        @nilam You'll get hex ascii representation with ubinascii.hexlify(), like:

        import ubinascii
        print("Received data: ", ubinascii.hexlify(rx_data))
        

        I the samples you gave there are almost no printable characters, so displaying it as ASCII is not that useful.

        N 1 Reply Last reply Reply Quote 0
        • N Offline
          nilam @robert-hh
          last edited by nilam

          @robert-hh what is the format of received data? like b'\xc5+*\xfe'.
          is it utf-8? base64?
          Sorry, i am asking very basic .

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

            @nilam Python displays it as a mix of hex and ascii. so at
            b'\xc5+*\xfe' you have 4 bytes, two of them, + and * are printable. I made a little hexdump function, which translates that to the usual way. It expects an bytes object as input

            #
            # Hexdump Function
            #
            FILTER=''.join([(len(repr(chr(x)))==3) and chr(x) or '.' for x in range(256)])
            
            def hexdump(src, length=16):
                N=0; result=''
                while src:  # loop through string
                   s,src = src[:length],src[length:]
                   hexa = ' '.join(["%02X"%x for x in s])
                   s = ''.join([FILTER[s[_]] for _ in range(len(s))])
                   result += "%04X   %-*s   %s\n" % (N, length*3, hexa, s)
                   N += length
                return result
            

            so hexdump(b'\xc5+*\xfe') returns:

            0000   C5 2B 2A FE                                        .+*.\n
            

            As a side note: if you enclose you code with lines, that consist of three backticks (```), it gets printed accodingly

            N 1 Reply Last reply Reply Quote 0
            • N Offline
              nilam @robert-hh
              last edited by

              @robert-hh thank you for quick response.

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

                @nilam Just to be pedantic, I simplified hexdump a bit. This is old code, collected when I started with Python.

                FILTER=''.join([(len(repr(chr(x)))==3) and chr(x) or '.' for x in range(256)])
                
                def hexdump(src, length=16):
                    N=0; result=''
                    while src:  # loop through string
                       s,src = src[:length],src[length:]
                       hexa = ' '.join(["%02X"%x for x in s])
                       s = ''.join([FILTER[_] for _ in s])
                       result += "%04X   %-*s   %s\n" % (N, length*3, hexa, s)
                       N += length
                    return result
                

                I have my doubts whether I did all of that myself at that time, especially the FILTER= .. expression.

                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