mirror of
https://github.com/m5stack/m5-docs.git
synced 2026-05-20 10:23:01 -07:00
updated exmaple section for LORAWAN
This commit is contained in:
BIN
Binary file not shown.
|
After Width: | Height: | Size: 272 KiB |
@@ -54,83 +54,78 @@ LoRaWAN**默认的串口配置:**
|
||||
|
||||
### Arduino IDE
|
||||
|
||||
这是主从LORA模块点对点通信的例程,模块与M5Core之间通过AT指令通讯。
|
||||
这是两个 LoRaWAN 模块之间通信的例程。
|
||||
|
||||
*具体例程请点击[这里](https://github.com/m5stack/M5-ProductExampleCodes/tree/master/Module/LORAWAN/Arduino)。*
|
||||
**功能:** 按下按键 B,设置模块工作在 433MHz 频段,并发送字符串 “Hello World”; 按下按键 C,设置模块工作在 868MHz 频段,并发送字符串 “Hello World”; 按下按键 A,Core 清屏。
|
||||
|
||||
**注意:** 在编译程序之前需要将 `LoRaWan for M5Stack.rar` 解压到路径 `C:\Users\<user_name>\Documents\Arduino\libraries` 下。
|
||||
|
||||
*以下仅为用法示意,并不完整。如果需要完整例程请点击[这里](https://github.com/m5stack/M5-ProductExampleCodes/tree/master/Module/LORAWAN/Arduino)。*
|
||||
|
||||
```arduino
|
||||
/*
|
||||
Master.ino
|
||||
device_A.ino
|
||||
*/
|
||||
|
||||
#include <M5Stack.h>
|
||||
#include <LoRaWan.h>
|
||||
|
||||
// entry test mode
|
||||
String cmd_test_mode = "AT+Mode=Test";
|
||||
// Configure the modem,like Freq, SF, BW, Preamble length, TX output power
|
||||
String cmd_rfconf = "AT+TEST=RFCFG,472.3,8,250,8,8,20";
|
||||
// send data as HEX format
|
||||
String cmd_send_data = "AT+TEST=TXLRPKT,\"30 31 32 33 34 35\"";
|
||||
#define SerialUSB Serial
|
||||
|
||||
void setup() {
|
||||
M5.begin();
|
||||
Serial.begin(9600);
|
||||
Serial2.begin(9600, SERIAL_8N1, 16, 17);
|
||||
// declaration
|
||||
M5.begin();
|
||||
SerialUSB.begin(9600);
|
||||
lora.init();
|
||||
delay(2000); // must delay for lorawan power on
|
||||
|
||||
delay(1000);// delay for lorawan power on
|
||||
/* LoRaWAN Init */
|
||||
Serial2.println(cmd_test_mode);
|
||||
delay(500);
|
||||
Serial2.println(cmd_rfconf);
|
||||
delay(500);
|
||||
}
|
||||
// 433MHz frequency initialization
|
||||
lora.initP2PMode(433, SF12, BW500, 8, 8, 20);
|
||||
|
||||
void loop() {
|
||||
if(M5.BtnA.wasPressed()) {
|
||||
Serial2.println(cmd_send_data);
|
||||
Serial.println(cmd_send_data);
|
||||
}
|
||||
M5.update();
|
||||
}
|
||||
// 868MHz frequency initialization
|
||||
lora.initP2PMode(868, SF12, BW500, 8, 8, 20);
|
||||
|
||||
// send string
|
||||
lora.transferPacketP2PMode("hello world");
|
||||
|
||||
// receive data
|
||||
short length = 0;
|
||||
short rssi = 0;
|
||||
memset(buffer, 0, 128);
|
||||
length = lora.receivePacketP2PMode(buffer, 128, &rssi, 1);
|
||||
```
|
||||
|
||||
```arduino
|
||||
/*
|
||||
Slaver.ino
|
||||
device_B.ino
|
||||
*/
|
||||
|
||||
#include <M5Stack.h>
|
||||
#include <LoRaWan.h>
|
||||
|
||||
// entry test mode
|
||||
String cmd_test_mode = "AT+Mode=Test";
|
||||
// Configure the modem,like Freq, SF, BW, Preamble length
|
||||
String cmd_rfconf = "AT+TEST=RFCFG,472.3,8,250,8,8,20";
|
||||
// allow to receive data
|
||||
String cmd_receive_data = "AT+TEST=RXLRPKT";
|
||||
#define SerialUSB Serial
|
||||
|
||||
void setup() {
|
||||
M5.begin();
|
||||
Serial.begin(9600);
|
||||
Serial2.begin(9600, SERIAL_8N1, 16, 17);
|
||||
delay(1000);// delay for lorawan power on
|
||||
/* LoRaWAN Init */
|
||||
Serial2.println(cmd_test_mode);
|
||||
delay(500);
|
||||
Serial2.println(cmd_rfconf);
|
||||
delay(500);
|
||||
Serial2.println(cmd_receive_data);
|
||||
delay(500);
|
||||
}
|
||||
// declaration
|
||||
M5.begin();
|
||||
SerialUSB.begin(9600);
|
||||
lora.init();
|
||||
delay(2000); // must delay for lorawan power on
|
||||
|
||||
void loop() {
|
||||
if(Serial2.available()) {
|
||||
int ch = Serial2.read();
|
||||
M5.Lcd.print((char)ch);
|
||||
Serial.write(ch);
|
||||
}
|
||||
}
|
||||
// 433MHz frequency initialization
|
||||
lora.initP2PMode(433, SF12, BW500, 8, 8, 20);
|
||||
|
||||
// 868MHz frequency initialization
|
||||
lora.initP2PMode(868, SF12, BW500, 8, 8, 20);
|
||||
|
||||
// send string
|
||||
lora.transferPacketP2PMode("hello world");
|
||||
|
||||
// receive data
|
||||
short length = 0;
|
||||
short rssi = 0;
|
||||
memset(buffer, 0, 128);
|
||||
length = lora.receivePacketP2PMode(buffer, 128, &rssi, 1);
|
||||
```
|
||||
|
||||
<img src="assets/img/product_pics/module/module_example/LORAWAN/example_module_lorawan_01.png">
|
||||
|
||||
## 原理图
|
||||
|
||||
<img src="assets/img/product_pics/module/lorawan_sch.png">
|
||||
Reference in New Issue
Block a user