Update README.md

master
呓喵酱 4 years ago committed by GitHub
parent dd7a25699f
commit 31d4213a2c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 41
      README.md

@ -1,49 +1,55 @@
# LoRa-mqtt
## 使用案例 - 使用回调函数
[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2FIoTcat%2FLoRa-mqtt.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2FIoTcat%2FLoRa-mqtt?ref=badge_shield)
![size](https://badge-size.herokuapp.com/iotcat/LoRa-mqtt/master/lora-mqtt.h)
Use MQTT in LoRa communicationg..
[简体中文](./zh.md)
## Usage - with Callback Functions
```C++
#define LORA_SOCKET_IP "1.0.0.1" //需唯一
#define LORA_SOCKET_IP "1.0.0.1" //need to be unique
#include "lora-mqtt.h"
LoRaMQTT mqtt;
void setup(){
mqtt.ini(); //初始化
mqtt.onReceived(doIfRec); //注册回调函数,当接收到新消息时触发
mqtt.subscribe("主题名称"); //订阅mqtt主题
mqtt.ini(); //initalization
mqtt.onReceived(doIfRec); //register callback functions which will be executed when received message
mqtt.subscribe("Subject"); //subscribe MQTT subject
}
void doIfRec(String subject, String content){
//当收到新消息时执行这个函数中的内容
//When received message this function will be executed.
mqtt.publish("主题", "内容"); //发布mqtt消息
mqtt.publish("Subject", "Content"); //publish a mqtt message
}
void loop(){
//注意loop()全局不得有delay,否则会导致接收不稳定
mqtt.core(); //循环组件
//No delay() could be used in loop()
mqtt.core(); //Mqtt service core
}
```
## 使用案例 - 使用条件触发
## Usage - with If in loop()
```C++
#define LORA_SOCKET_IP "1.0.0.1" //需唯一
#define LORA_SOCKET_IP "1.0.0.1" //need to be unique
#include "lora-mqtt.h"
LoRaMQTT mqtt;
void setup(){
mqtt.ini(); //初始化
mqtt.subscribe("主题名称"); //订阅mqtt主题
mqtt.ini(); //initalization
mqtt.subscribe("Subject"); //subscribe MQTT subject
}
void loop(){
//注意loop()全局不得有delay,否则会导致接收不稳定
//When received message this function will be executed.
if(mqtt.isNewMsg()){
String subject, content;
@ -51,9 +57,8 @@ void loop(){
Serial.println(subject, content);
}
mqtt.core(); //循环组件
mqtt.core(); //Mqtt service core
}
```

Loading…
Cancel
Save