You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
1.4 KiB

5 years ago
# LoRa-mqtt
4 years ago
[![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)
4 years ago
Use MQTT in LoRa communication..
4 years ago
[简体中文](./zh.md)
## Usage - with Callback Functions
5 years ago
```C++
4 years ago
#define LORA_SOCKET_IP "1.0.0.1" //need to be unique
5 years ago
#include "lora-mqtt.h"
LoRaMQTT mqtt;
void setup(){
4 years ago
mqtt.ini(); //initalization
mqtt.onReceived(doIfRec); //register callback functions which will be executed when received message
mqtt.subscribe("Subject"); //subscribe MQTT subject
5 years ago
}
void doIfRec(String subject, String content){
4 years ago
//When received message this function will be executed.
5 years ago
4 years ago
mqtt.publish("Subject", "Content"); //publish a mqtt message
5 years ago
}
void loop(){
4 years ago
//No delay() could be used in loop()
mqtt.core(); //Mqtt service core
5 years ago
}
```
4 years ago
## Usage - with If in loop()
5 years ago
```C++
4 years ago
#define LORA_SOCKET_IP "1.0.0.1" //need to be unique
5 years ago
#include "lora-mqtt.h"
LoRaMQTT mqtt;
void setup(){
4 years ago
mqtt.ini(); //initalization
mqtt.subscribe("Subject"); //subscribe MQTT subject
5 years ago
}
void loop(){
4 years ago
//When received message this function will be executed.
5 years ago
if(mqtt.isNewMsg()){
String subject, content;
mqtt.getNewMsg(subject, content);
Serial.println(subject, content);
}
4 years ago
mqtt.core(); //Mqtt service core
5 years ago
}
```
4 years ago