Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
NamNamIoT committed Jul 18, 2024
1 parent c0f75b3 commit 8c38bb4
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 93 deletions.
30 changes: 15 additions & 15 deletions examples/LoRa_P2P/LoRa_P2P.ino
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,21 @@ void recv_cb(rui_lora_p2p_recv_t data)
void send_cb(void)
{
Serial.printf("P2P set Rx mode %s\r\n",
api.lorawan.precv(65534) ? "Success" : "Fail");
api.lora.precv(65534) ? "Success" : "Fail");
}

void setup()
{
Serial.begin(115200);
Serial.println("RAK3172_Canopus LoRaWan P2P Example");
Serial.println("RAK3172_Canopus lora P2P Example");
Serial.println("------------------------------------------------------");
init_io();
startTime = millis();

if (api.lorawan.nwm.get() != 0)
if (api.lora.nwm.get() != 0)
{
Serial.printf("Set Node device work mode %s\r\n",
api.lorawan.nwm.set(0) ? "Success" : "Fail");
api.lora.nwm.set() ? "Success" : "Fail");
api.system.reboot();
}

Expand All @@ -85,21 +85,21 @@ void setup()
Serial.printf("AT Command Version: %s\r\n",
api.system.cliVersion.get().c_str());
Serial.printf("Set P2P mode frequency %3.3f: %s\r\n", (myFreq / 1e6),
api.lorawan.pfreq.set(myFreq) ? "Success" : "Fail");
api.lora.pfreq.set(myFreq) ? "Success" : "Fail");
Serial.printf("Set P2P mode spreading factor %d: %s\r\n", sf,
api.lorawan.psf.set(sf) ? "Success" : "Fail");
api.lora.psf.set(sf) ? "Success" : "Fail");
Serial.printf("Set P2P mode bandwidth %d: %s\r\n", bw,
api.lorawan.pbw.set(bw) ? "Success" : "Fail");
api.lora.pbw.set(bw) ? "Success" : "Fail");
Serial.printf("Set P2P mode code rate 4/%d: %s\r\n", (cr + 5),
api.lorawan.pcr.set(cr) ? "Success" : "Fail");
api.lora.pcr.set(cr) ? "Success" : "Fail");
Serial.printf("Set P2P mode preamble length %d: %s\r\n", preamble,
api.lorawan.ppl.set(preamble) ? "Success" : "Fail");
api.lora.ppl.set(preamble) ? "Success" : "Fail");
Serial.printf("Set P2P mode tx power %d: %s\r\n", txPower,
api.lorawan.ptp.set(txPower) ? "Success" : "Fail");
api.lorawan.registerPRecvCallback(recv_cb);
api.lorawan.registerPSendCallback(send_cb);
api.lora.ptp.set(txPower) ? "Success" : "Fail");
api.lora.registerPRecvCallback(recv_cb);
api.lora.registerPSendCallback(send_cb);
Serial.printf("P2P set Rx mode %s\r\n",
api.lorawan.precv(65534) ? "Success" : "Fail");
api.lora.precv(65534) ? "Success" : "Fail");
// let's kick-start things by waiting 3 seconds.
}

Expand All @@ -112,11 +112,11 @@ void loop()
rx_done = false;
while (!send_result)
{
send_result = api.lorawan.psend(sizeof(payload), payload);
send_result = api.lora.psend(sizeof(payload), payload);
Serial.printf("P2P send %s\r\n", send_result ? "Success" : "Fail");
if (!send_result)
{
Serial.printf("P2P finish Rx mode %s\r\n", api.lorawan.precv(0) ? "Success" : "Fail");
Serial.printf("P2P finish Rx mode %s\r\n", api.lora.precv(0) ? "Success" : "Fail");
delay(1000);
}
}
Expand Down
30 changes: 15 additions & 15 deletions examples/LoRa_P2P_Rx/LoRa_P2P_Rx.ino
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,21 @@ void recv_cb(rui_lora_p2p_recv_t data)
void send_cb(void)
{
Serial.printf("P2P set Rx mode %s\r\n",
api.lorawan.precv(65534) ? "Success" : "Fail");
api.lora.precv(65534) ? "Success" : "Fail");
}

void setup()
{
Serial.begin(115200);
Serial.println("RAK3172_Canopus LoRaWan P2P Example");
Serial.println("RAK3172_Canopus lora P2P Example");
Serial.println("------------------------------------------------------");
init_io();
startTime = millis();

if (api.lorawan.nwm.get() != 0)
if (api.lora.nwm.get() != 0)
{
Serial.printf("Set Node device work mode %s\r\n",
api.lorawan.nwm.set(0) ? "Success" : "Fail");
api.lora.nwm.set() ? "Success" : "Fail");
api.system.reboot();
}

Expand All @@ -52,21 +52,21 @@ void setup()
Serial.printf("AT Command Version: %s\r\n",
api.system.cliVersion.get().c_str());
Serial.printf("Set P2P mode frequency %3.3f: %s\r\n", (myFreq / 1e6),
api.lorawan.pfreq.set(myFreq) ? "Success" : "Fail");
api.lora.pfreq.set(myFreq) ? "Success" : "Fail");
Serial.printf("Set P2P mode spreading factor %d: %s\r\n", sf,
api.lorawan.psf.set(sf) ? "Success" : "Fail");
api.lora.psf.set(sf) ? "Success" : "Fail");
Serial.printf("Set P2P mode bandwidth %d: %s\r\n", bw,
api.lorawan.pbw.set(bw) ? "Success" : "Fail");
api.lora.pbw.set(bw) ? "Success" : "Fail");
Serial.printf("Set P2P mode code rate 4/%d: %s\r\n", (cr + 5),
api.lorawan.pcr.set(cr) ? "Success" : "Fail");
api.lora.pcr.set(cr) ? "Success" : "Fail");
Serial.printf("Set P2P mode preamble length %d: %s\r\n", preamble,
api.lorawan.ppl.set(preamble) ? "Success" : "Fail");
api.lora.ppl.set(preamble) ? "Success" : "Fail");
Serial.printf("Set P2P mode tx power %d: %s\r\n", txPower,
api.lorawan.ptp.set(txPower) ? "Success" : "Fail");
api.lorawan.registerPRecvCallback(recv_cb);
api.lorawan.registerPSendCallback(send_cb);
api.lora.ptp.set(txPower) ? "Success" : "Fail");
api.lora.registerPRecvCallback(recv_cb);
api.lora.registerPSendCallback(send_cb);
Serial.printf("P2P set Rx mode %s\r\n",
api.lorawan.precv(65534) ? "Success" : "Fail");
api.lora.precv(65534) ? "Success" : "Fail");
}

void loop()
Expand All @@ -79,11 +79,11 @@ void loop()
while (!send_result)
{
digitalWrite(LED_SEND, HIGH);
send_result = api.lorawan.psend(sizeof(payload), payload);
send_result = api.lora.psend(sizeof(payload), payload);
Serial.printf("P2P send %s\r\n", send_result ? "Success" : "Fail");
if (!send_result)
{
Serial.printf("P2P finish Rx mode %s\r\n", api.lorawan.precv(0) ? "Success" : "Fail");
Serial.printf("P2P finish Rx mode %s\r\n", api.lora.precv(0) ? "Success" : "Fail");
delay(1000);
}
}
Expand Down
30 changes: 15 additions & 15 deletions examples/LoRa_P2P_Tx/LoRa_P2P_Tx.ino
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,21 @@ void recv_cb(rui_lora_p2p_recv_t data)
void send_cb(void)
{
Serial.printf("P2P set Rx mode %s\r\n",
api.lorawan.precv(65534) ? "Success" : "Fail");
api.lora.precv(65534) ? "Success" : "Fail");
}

void setup()
{
Serial.begin(115200);
Serial.println("RAK3172_Canopus LoRaWan P2P Example");
Serial.println("RAK3172_Canopus lora P2P Example");
Serial.println("------------------------------------------------------");
init_io();
startTime = millis();

if (api.lorawan.nwm.get() != 0)
if (api.lora.nwm.get() != 0)
{
Serial.printf("Set Node device work mode %s\r\n",
api.lorawan.nwm.set(0) ? "Success" : "Fail");
api.lora.nwm.set() ? "Success" : "Fail");
api.system.reboot();
}

Expand All @@ -74,21 +74,21 @@ void setup()
Serial.printf("AT Command Version: %s\r\n",
api.system.cliVersion.get().c_str());
Serial.printf("Set P2P mode frequency %3.3f: %s\r\n", (myFreq / 1e6),
api.lorawan.pfreq.set(myFreq) ? "Success" : "Fail");
api.lora.pfreq.set(myFreq) ? "Success" : "Fail");
Serial.printf("Set P2P mode spreading factor %d: %s\r\n", sf,
api.lorawan.psf.set(sf) ? "Success" : "Fail");
api.lora.psf.set(sf) ? "Success" : "Fail");
Serial.printf("Set P2P mode bandwidth %d: %s\r\n", bw,
api.lorawan.pbw.set(bw) ? "Success" : "Fail");
api.lora.pbw.set(bw) ? "Success" : "Fail");
Serial.printf("Set P2P mode code rate 4/%d: %s\r\n", (cr + 5),
api.lorawan.pcr.set(cr) ? "Success" : "Fail");
api.lora.pcr.set(cr) ? "Success" : "Fail");
Serial.printf("Set P2P mode preamble length %d: %s\r\n", preamble,
api.lorawan.ppl.set(preamble) ? "Success" : "Fail");
api.lora.ppl.set(preamble) ? "Success" : "Fail");
Serial.printf("Set P2P mode tx power %d: %s\r\n", txPower,
api.lorawan.ptp.set(txPower) ? "Success" : "Fail");
api.lorawan.registerPRecvCallback(recv_cb);
api.lorawan.registerPSendCallback(send_cb);
api.lora.ptp.set(txPower) ? "Success" : "Fail");
api.lora.registerPRecvCallback(recv_cb);
api.lora.registerPSendCallback(send_cb);
Serial.printf("P2P set Rx mode %s\r\n",
api.lorawan.precv(65534) ? "Success" : "Fail");
api.lora.precv(65534) ? "Success" : "Fail");
}

void loop()
Expand All @@ -97,10 +97,10 @@ void loop()
bool send_result = false;
while (!send_result)
{
send_result = api.lorawan.psend(sizeof(payload), payload);
send_result = api.lora.psend(sizeof(payload), payload);
if (!send_result)
{
api.lorawan.precv(0);
api.lora.precv(0);
delay(1000);
}
}
Expand Down
56 changes: 23 additions & 33 deletions examples/Lora_Modbus/function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,19 @@ long startTime;
bool rx_done = false;
uint16_t sf = 12, bw = 0, cr = 0, preamble = 8, txPower = 22;

void Modbus_read(uint8_t *buf, uint16_t len)
{
void Modbus_read(uint8_t *buf, uint16_t len) {
Serial.print("\r\n[Lora]Read/Write: ");
for (int i = 0; i < len; i++)
{
for (int i = 0; i < len; i++) {
Serial.print("[");
Serial.print(buf[i], HEX);
Serial_modbus.printf("%c", buf[i]);
Serial.print("]");
}
}

void recv_cb(rui_lora_p2p_recv_t data)
{
void recv_cb(rui_lora_p2p_recv_t data) {
rx_done = true;
if (data.BufferSize == 0)
{
if (data.BufferSize == 0) {
Serial.println("Empty buffer.");
return;
}
Expand All @@ -35,19 +31,16 @@ void recv_cb(rui_lora_p2p_recv_t data)
digitalWrite(LED_RECV, LOW);
}

void send_cb(void)
{
void send_cb(void) {
Serial.printf("\r\n[Lora]Back to Rx mode %s",
api.lorawan.precv(65534) ? "Success" : "Fail");
api.lora.precv(65534) ? "Success" : "Fail");
}

bool init_lora(double freq)
{
bool init_lora(double freq) {

if (api.lorawan.nwm.get() != 0)
{
if (api.lora.nwm.get() != 0) {
Serial.printf("Set Node device work mode %s\r\n",
api.lorawan.nwm.set(0) ? "Success" : "Fail");
api.lora.nwm.set() ? "Success" : "Fail");
api.system.reboot();
}

Expand All @@ -61,38 +54,35 @@ bool init_lora(double freq)
Serial.printf("AT Command Version: %s\r\n",
api.system.cliVersion.get().c_str());
Serial.printf("Set P2P mode frequency %3.3f: %s\r\n", (freq / 1e6),
api.lorawan.pfreq.set(freq) ? "Success" : "Fail");
api.lora.pfreq.set(freq) ? "Success" : "Fail");
Serial.printf("Set P2P mode spreading factor %d: %s\r\n", sf,
api.lorawan.psf.set(sf) ? "Success" : "Fail");
api.lora.psf.set(sf) ? "Success" : "Fail");
Serial.printf("Set P2P mode bandwidth %d: %s\r\n", bw,
api.lorawan.pbw.set(bw) ? "Success" : "Fail");
api.lora.pbw.set(bw) ? "Success" : "Fail");
Serial.printf("Set P2P mode code rate 4/%d: %s\r\n", (cr + 5),
api.lorawan.pcr.set(cr) ? "Success" : "Fail");
api.lora.pcr.set(cr) ? "Success" : "Fail");
Serial.printf("Set P2P mode preamble length %d: %s\r\n", preamble,
api.lorawan.ppl.set(preamble) ? "Success" : "Fail");
api.lora.ppl.set(preamble) ? "Success" : "Fail");
Serial.printf("Set P2P mode tx power %ddB: %s\r\n", txPower,
api.lorawan.ptp.set(txPower) ? "Success" : "Fail");
api.lorawan.registerPRecvCallback(recv_cb);
api.lorawan.registerPSendCallback(send_cb);
api.lora.ptp.set(txPower) ? "Success" : "Fail");
api.lora.registerPRecvCallback(recv_cb);
api.lora.registerPSendCallback(send_cb);
Serial.printf("P2P set Rx mode %s\r\n",
api.lorawan.precv(65534) ? "Success" : "Fail");
api.lora.precv(65534) ? "Success" : "Fail");
delay(1000);
return true;
}

bool lora_send(int size_msg, uint8_t *msg)
{
bool lora_send(int size_msg, uint8_t *msg) {
Serial.printf("\r\n[Lora]P2P sending...");
bool send_result = false;
int count = 0;
api.lorawan.precv(0);
while (!send_result)
{
send_result = api.lorawan.psend(size_msg, msg);
api.lora.precv(0);
while (!send_result) {
send_result = api.lora.psend(size_msg, msg);
delay(1);
count++;
if (count > 2000)
{
if (count > 2000) {
Serial.printf("\r\n[Lora]P2P send Fail");
return false;
}
Expand Down
30 changes: 15 additions & 15 deletions examples/Rak2Ra02/Rak3172/Rak3172.ino
Original file line number Diff line number Diff line change
Expand Up @@ -58,22 +58,22 @@ void recv_cb(rui_lora_p2p_recv_t data)
void send_cb(void)
{
Serial.printf("P2P set Rx mode %s\r\n",
api.lorawan.precv(3000) ? "Success" : "Fail");
api.lora.precv(3000) ? "Success" : "Fail");
}

void setup()
{
init_io();
Serial.begin(115200);
Serial.println("RAK3172_Canopus LoRaWan P2P Example");
Serial.println("RAK3172_Canopus lora P2P Example");
Serial.println("------------------------------------------------------");
delay(2000);
startTime = millis();

if (api.lorawan.nwm.get() != 0)
if (api.lora.nwm.get() != 0)
{
Serial.printf("Set Node device work mode %s\r\n",
api.lorawan.nwm.set(0) ? "Success" : "Fail");
api.lora.nwm.set() ? "Success" : "Fail");
api.system.reboot();
}

Expand All @@ -87,21 +87,21 @@ void setup()
Serial.printf("AT Command Version: %s\r\n",
api.system.cliVersion.get().c_str());
Serial.printf("Set P2P mode frequency %3.3f: %s\r\n", (myFreq / 1e6),
api.lorawan.pfreq.set(myFreq) ? "Success" : "Fail");
api.lora.pfreq.set(myFreq) ? "Success" : "Fail");
Serial.printf("Set P2P mode spreading factor %d: %s\r\n", sf,
api.lorawan.psf.set(sf) ? "Success" : "Fail");
api.lora.psf.set(sf) ? "Success" : "Fail");
Serial.printf("Set P2P mode bandwidth %d: %s\r\n", bw,
api.lorawan.pbw.set(bw) ? "Success" : "Fail");
api.lora.pbw.set(bw) ? "Success" : "Fail");
Serial.printf("Set P2P mode code rate 4/%d: %s\r\n", (cr + 5),
api.lorawan.pcr.set(cr) ? "Success" : "Fail");
api.lora.pcr.set(cr) ? "Success" : "Fail");
Serial.printf("Set P2P mode preamble length %d: %s\r\n", preamble,
api.lorawan.ppl.set(preamble) ? "Success" : "Fail");
api.lora.ppl.set(preamble) ? "Success" : "Fail");
Serial.printf("Set P2P mode tx power %d: %s\r\n", txPower,
api.lorawan.ptp.set(txPower) ? "Success" : "Fail");
api.lorawan.registerPRecvCallback(recv_cb);
api.lorawan.registerPSendCallback(send_cb);
api.lora.ptp.set(txPower) ? "Success" : "Fail");
api.lora.registerPRecvCallback(recv_cb);
api.lora.registerPSendCallback(send_cb);
Serial.printf("P2P set Rx mode %s\r\n",
api.lorawan.precv(3000) ? "Success" : "Fail");
api.lora.precv(3000) ? "Success" : "Fail");
// let's kick-start things by waiting 3 seconds.
}

Expand All @@ -114,11 +114,11 @@ void loop()
rx_done = false;
while (!send_result)
{
send_result = api.lorawan.psend(sizeof(payload), payload);
send_result = api.lora.psend(sizeof(payload), payload);
Serial.printf("P2P send %s\r\n", send_result ? "Success" : "Fail");
if (!send_result)
{
Serial.printf("P2P finish Rx mode %s\r\n", api.lorawan.precv(0) ? "Success" : "Fail");
Serial.printf("P2P finish Rx mode %s\r\n", api.lora.precv(0) ? "Success" : "Fail");
delay(1000);
}
}
Expand Down

0 comments on commit 8c38bb4

Please sign in to comment.