Receive USRP data on lopy lora



  • 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



  • @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.



  • @robert-hh thank you for quick response.



  • @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



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



  • @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.


Log in to reply
 

Pycom on Twitter