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 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.
-
@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 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 resultso hexdump(b'\xc5+*\xfe') returns:
0000 C5 2B 2A FE .+*.\nAs a side note: if you enclose you code with lines, that consist of three backticks (```), it gets printed accodingly
-
@robert-hh thank you for quick response.
-
@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 resultI have my doubts whether I did all of that myself at that time, especially the FILTER= .. expression.
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