Update README.md

master
呓喵酱 5 years ago committed by GitHub
parent 0a2a5bd815
commit 53ff98e638
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 33
      README.md

@ -1,6 +1,6 @@
# LoRa-socket
## 使用案例
## 使用案例 - 使用回调函数
```C++
#define LORA_SOCKET_IP "1.0.0.1" //需唯一
@ -10,7 +10,8 @@
LoRaSocket socket;
void setup(){
socket.ini();
socket.ini(); //初始化
socket.onReceived(doIfRec); //注册回调函数,当接收到新消息时触发
}
void doIfRec(String message, String fromIP, String toIP, String msgType){
@ -22,7 +23,33 @@ void doIfRec(String message, String fromIP, String toIP, String msgType){
}
void loop(){
socket.core();
//注意loop()全局不得有delay,否则会导致接收不稳定
socket.core(); //循环组件
}
```
## 使用案例 - 使用条件触发
```C++
#define LORA_SOCKET_IP "1.0.0.1" //需唯一
#include "lora-socket.h"
LoRaSocket socket;
void setup(){
socket.ini(); //初始化
}
void loop(){
//注意loop()全局不得有delay,否则会导致接收不稳定
if(socket.isNewMsg()){ //判断是否有新消息
Serial.println(socket.getNewMsg()); //直接打印出新消息(法一)
String message, fromIP, toIP, msgType;
socket.getNewMsg(message, fromIP, toIP, msgType); //通过引用获取消息内容,发信ip,收信ip,消息类型
}
}

Loading…
Cancel
Save