RAK3272 P2P Help

I’m attempting to peer two RAK3172 modules together with two RPi’s. Currently testing with a simple send script on one pi and a receive script on the other. I’ll paste in the two scripts at the end of this topic but I also tried the single-line

UART.write(b"AT+P2P=914000000:9:500:0:8:22\n")

on both pi’s with no luck or an AT_ERROR.

Receive Script:

import serial
import time

UART = serial.Serial('/dev/serial0', 
                    baudrate=115200, 
                    timeout=1, 
                    parity=serial.PARITY_NONE,
		    stopbits=serial.STOPBITS_ONE)

#UART.write(b"ATE\n")

UART.write(b"AT\n")
rcv = UART.read(10)
print(rcv.decode())
#time.sleep(1)

# P2P Work Mode
UART.write(b"AT+NWM=0\n")
rcv = UART.read(10)
print(rcv.decode())
#time.sleep(1)

# Peer Frequency- 914.000000 MHz
UART.write(b"AT+PFREQ=914000000\n")
rcv = UART.read(10)
print(rcv.decode())
#time.sleep(1)        


UART.write(b"AT+PSF=6\n")
rcv = UART.read(10)
print(rcv.decode())
#time.sleep(1)

# Bandwidth
UART.write(b"AT+PBW=500\n")
rcv = UART.read(10)
print(rcv.decode())
#time.sleep(1)

# P2P Coding Rate (0-3)
UART.write(b"AT+PCR=0\n")
rcv = UART.read(10)
print(rcv.decode())
#time.sleep(1)

# P2P Preamable Length (2-65535)
UART.write(b"AT+PPL=8\n")
rcv = UART.read(10)
print(rcv.decode())
#time.sleep(1)

# P2P Transmit Power (5-22)
UART.write(b"AT+PTP=22\n")
rcv = UART.read(10)
print(rcv.decode())
#time.sleep(1)

# OR "AT+P2P=freq():SF(5-12):BW(125,250,500):CodeRate(0-3):Preamble(2-655636):TXPower(5-22dBm)>"

#UART.write(b"AT+P2P=914000000:9:500:0:8:22\n")
#rcv = UART.read(10)
#print(rcv.decode())
#time.sleep(2)

counter = 0
while True:
    print(counter, " Waiting for data...")
    UART.write(b"AT+PRECV=65535")
    rcv = UART.read()
    print(rcv.decode())
    UART.reset_output_buffer()
    counter += 1

Send Script:

import serial
import time

UART = serial.Serial('/dev/serial0', 
                    baudrate=115200, 
                    timeout=1, 
                    parity=serial.PARITY_NONE,
		    stopbits=serial.STOPBITS_ONE)


#UART.write(b"ATE\n")

UART.write(b"AT\n")
rcv = UART.read(10)
print(rcv.decode())
#time.sleep(1)

# P2P Work Mode
UART.write(b"AT+NWM=0\n")
rcv = UART.read(10)
print(rcv.decode())
#time.sleep(1)

# Peer Frequency- 914.000000 MHz
UART.write(b"AT+PFREQ=914000000\n")
rcv = UART.read(10)
print(rcv.decode())
#time.sleep(1)        


UART.write(b"AT+PSF=6\n")
rcv = UART.read(10)
print(rcv.decode())
#time.sleep(1)

# Bandwidth
UART.write(b"AT+PBW=500\n")
rcv = UART.read(10)
print(rcv.decode())
#time.sleep(1)

# P2P Coding Rate (0-3)
UART.write(b"AT+PCR=0\n")
rcv = UART.read(10)
print(rcv.decode())
time.sleep(1)

# P2P Preamable Length (2-65535)
UART.write(b"AT+PPL=8\n")
rcv = UART.read(10)
print(rcv.decode())
#time.sleep(1)

# P2P Transmit Power (5-22)
UART.write(b"AT+PTP=22\n")
rcv = UART.read(10)
print(rcv.decode())
#time.sleep(1)

# OR "AT+P2P=freq():SF(5-12):BW(125,250,500):CodeRate(0-3):Preamble(2-655636):TXPower(5-22dBm)>"
#UART.write(b"AT+P2P=914000000:9:500:0:8:22\n")
#rcv = UART.read(10)
#print(rcv.decode())
#time.sleep(2)


data = 0

while True:
    print(data, " Sending")
    UART.write(b"AT+PSEND=hello\n")
    #UART.write(data)
    #UART.write(b"\n")
    time.sleep(1)
    UART.reset_output_buffer()
    data += 1

Thanks in advance!

is one problem.
AT+PSEND expects ASCII characters representing hexadecimal values.
If you want to send “Hello” the command would be
AT+PSEND=48656C6C6F

Even though the whole string in encoded to bytes? I tried the hex value you gave but not getting anything, is the way I have the PRECV setup correct? I’m new to UART on RPi’s too but I’m not getting any response when I try to read the 3272’s reply during AT command setup either

Your UART settings seem to be ok.
Are you sure RX/TX are connected correct
RX RPi <=> TX RAK3172
TX RPi <=> RX RAK3172

Also keep in mind that the RAK3172 will only listen and respond to AT commands on the UART2 interface.

I am not a RPi or Python expert, but is this sequence actually waiting for a response and if yes, how long?

If there is a UART command that waits until a certain character is received, you should use that instead and wait for an LF or CR that marks the end of an response.

And the best idea to check if you connected the correct UART and have the pins assigned correct is to use an UART/USB adapter and a computer to test the communication.

I double checked my RX/TX pins and they were correct and using UART2. I had used a usb Uart adapter and was able to receive the commands sent to my computer with a similar python script but I will connect it again to make sure it’s still sending them correctly.

The uart.read command should read until the specified timeout at the top of the script (1 second) but I likely need to look into a better way or approach of reading the console

Update: Connected to my computer again and the left side is what my computer is receiving, then when I send “replytest” a few times here and there it always received it and printed in the Pi’s ssh console on the right. However, I realized i was missing the newline character for my receive command when I first connect, so that could be my issue but not sure why i wouldn’t get output for other commands, maybe it needs ATE command?

I never use ATE.
Just saw the commands you send are ending with \n, usually they should be \r\n ended => AT-Command-Manual.

1 second wait time for a response might be too short. Try a longer timeout.
This is from a LoRaWAN connection, but the timing for LoRa P2P is similar.

11:11:49.597 --> at+ver=?
11:11:49.597 --> 
11:11:49.597 --> AT+VER=3.4.2-rui3_22q1_update.112
11:11:49.607 --> OK
11:12:04.917 --> at+send=2:303030
11:12:04.921 --> 
11:12:04.933 --> OK
11:12:06.309 --> [TX-CB] TX status 0
11:12:06.309 --> [RX-CB] RX, port 0, DR 3, RSSI -37, SNR 11
11:12:06.418 --> 
11:12:06.418 --> +EVT:SEND_CONFIRMED_OK

Another tip (googled for Python), use UART.read_until(b'\r\n>') # Wait for CR LF instead of just using a timeout.

Got it, ill add the /r to my commands and alter my uart.read. Will likely test again tomorrow and update here if I still have issues

Thanks

Update is that the script doesn’t work as-is, but when I use the RAK serial tool to manually configure the receive side and then send PRECV command, i did get an event with the other pi running the send script, but I think the event happened during the setup of the pi’s AT commands and not after the PSEND. I don’t believe I got any data along with it either, I was trying to send the hex values you gave me for “hello”, event details below but I also noticed that I didn’t get a response from 3272 when using 115200 baud which I thought was the new default, only got response at 9600. Will change both bauds to 9600 and keep testing to see if anything else works

image

You received data, as your log shows:
image

The data is not ASCII, but 12 hex values.

Your setup and AT commands are correct, I can only guess your Python script for receiving is not working as expected.

One thing in your receive loop, you are sending repeatedly AT+PRECV=65535 to the RAK3172 and that is wrong. Receive should be enabled once, until you received a packet (the complete packet as I marked in the screenshot) and only after that AT+PRECV=65535 can be send again. I don’t think that your while loop will work as you think it should.

counter = 0
while True:
    print(counter, " Waiting for data...")
    UART.write(b"AT+PRECV=65535")
    rcv = UART.read()
    print(rcv.decode())
    UART.reset_output_buffer()
    counter += 1

I realized that issue with my recv command earlier when I had the module connected via uart adapter to my computer, because it showed AT_BUSY, but is there a way to configure the timeout for the recv? I noticed it would eventually time out after awhile and I wanted the loop to always be ready to receive (send receive command after timeout)

And I figured the data I received would be the hex values I was sending, when converting what i did receive to ASCII it results in this:

First, can you send an at+ver=? command to the RAK3172, I think you are using an old firmware version. I would suggest you update it to our latest RUI3 firmware.
Tutorials to switch from old firmware (V1.0.4) to RUI3 => RAK3172 Module Quick Start Guide | RAKwireless Documentation Center

For the receive command, the value in the PRECV command is the timeout. ==> AT Command Manual | RAKwireless Documentation Center

As I said, I don’t know Python, not sure what the rcv.decode() is doing with the received data. Did you try to just print to the console what you received?

I believe I’m on v1.0.2, I’ll look into updating. And should’ve realized that value was the timeout, I read that the 65535 value was no timeout so that’s why I was using it.

I was using rcv.decode() because I assumed the module would reply with bytes but that could be my issue, I’ll try printing directly or decoding from hex

Update: I removed the .decode() and I’m getting OK messages from AT commands, needs formatting but I can work on that. Additionally, my received events are also being displayed, but is the data in Hex? I will have to look into how to parse it within my code since it gives me mode and signal characteristics in addition to data, at least they’re colon delimited which should help

I also updated to 1.0.4 and using 115200 baud with no issues