Created
January 24, 2018 16:41
-
-
Save sourceperl/1189f5484ba2bc8c2272ff8a88c8a7fb to your computer and use it in GitHub Desktop.
RN2483 LoRa point to point test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# RN2483 point to point test | |
# open serial link, init and display rx frames | |
import argparse | |
import serial | |
# some functions | |
def send_cmd(cmd): | |
ser.write(bytes('%s\r\n' % cmd, 'ascii')) | |
status_str = ser.readline().decode().rstrip() | |
print('send command "%s" return "%s"' % (cmd, status_str)) | |
def rx_frame(): | |
ser.write(bytes('radio rx 0\r\n', 'ascii')) | |
ser.readline() | |
return ser.readline().decode().rstrip() | |
# main program | |
if __name__ == '__main__': | |
# parse argument | |
parser = argparse.ArgumentParser(description='RN2483 receive') | |
parser.add_argument('-d', '--device', type=str, default='/dev/ttyACM0', | |
help='serial device (default is "/dev/ttyACM0")') | |
parser.add_argument('-b', '--baurate', type=int, default=57600, | |
help='serial baudrate') | |
args = parser.parse_args() | |
# open serial device | |
ser = serial.Serial(args.device, args.baurate) | |
# init RN2483 | |
print('\n----- init RN2483 -----\n') | |
send_cmd('sys factoryRESET') | |
send_cmd('sys reset') | |
send_cmd('radio set mod lora') | |
send_cmd('radio set freq 868100000') | |
send_cmd('radio set pwr 14') | |
send_cmd('radio set sf sf12') | |
send_cmd('radio set afcbw 125') | |
send_cmd('radio set rxbw 250') | |
send_cmd('radio set fdev 5000') | |
send_cmd('radio set prlen 8') | |
send_cmd('radio set crc on') | |
send_cmd('radio set cr 4/8') | |
send_cmd('radio set wdt 0') | |
send_cmd('radio set sync 12') | |
send_cmd('radio set bw 250') | |
send_cmd('mac pause') | |
# receive frames | |
print('\n------ rx frames ------\n') | |
i = 0 | |
while True : | |
i += 1 | |
rx_str = rx_frame() | |
print('[frame #%04d] %s' % (i, rx_str)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
The Things UNO (model: TTN-003-868-1.0) point to point sender | |
Send an unsigned integer every 5s. | |
Use it only for radio test (don't complain with radio regulation) !!! | |
This example code is in the public domain. | |
*/ | |
#define loraSerial Serial1 | |
#define debugSerial Serial | |
// some vars | |
uint32_t i = 0; | |
// some functions | |
void send_cmd(String cmd) { | |
debugSerial.println("send cmd: " + cmd); | |
loraSerial.println(cmd); | |
String str = loraSerial.readStringUntil('\n'); | |
debugSerial.println("return: " + str); | |
} | |
void send_uint(uint32_t value) { | |
debugSerial.println("send value: " + String(value, HEX)); | |
loraSerial.println("radio tx " + String(value, HEX)); | |
String str = loraSerial.readStringUntil('\n'); | |
debugSerial.println("return: " + str); | |
str = loraSerial.readStringUntil('\n'); | |
debugSerial.println(" " + str); | |
} | |
void setup() { | |
// init serials | |
debugSerial.begin(115200); | |
loraSerial.begin(57600); | |
// init lora chip | |
debugSerial.println("init of RN2483 chip"); | |
send_cmd("sys factoryRESET"); | |
send_cmd("sys reset"); | |
send_cmd("radio set mod lora"); | |
send_cmd("radio set freq 868100000"); | |
send_cmd("radio set pwr 14"); | |
send_cmd("radio set sf sf12"); | |
send_cmd("radio set afcbw 125"); | |
send_cmd("radio set rxbw 250"); | |
send_cmd("radio set fdev 5000"); | |
send_cmd("radio set prlen 8"); | |
send_cmd("radio set crc on"); | |
send_cmd("radio set cr 4/8"); | |
send_cmd("radio set wdt 0"); | |
send_cmd("radio set sync 12"); | |
send_cmd("radio set bw 250"); | |
send_cmd("mac pause"); | |
} | |
void loop() { | |
// send integer | |
send_uint(i++); | |
// wait next loop | |
delay(5000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment