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.
呓喵酱
dd31efc7f8
|
4 years ago | |
---|---|---|
.gitignore | 5 years ago | |
LICENSE | 5 years ago | |
README.md | 4 years ago | |
lora-socket.h | 5 years ago | |
lora-socket.ino | 5 years ago | |
stringVec.h | 5 years ago | |
vector.h | 5 years ago | |
zh.md | 4 years ago |
README.md
LoRa-socket
Usage - with Callback Functions
#define LORA_SOCKET_IP "1.0.0.1" //need to be unique
#include "lora-socket.h"
LoRaSocket socket;
void setup(){
socket.ini(); //initalization
socket.onReceived(doIfRec); //Register a callback function, which is triggered when a new message is received
}
void doIfRec(String message, String fromIP, String toIP, String msgType){
//Execute the this function when a new message is received
socket.udp("Hi"); //Broadcast using udp
socket.udp("Hi xx", "1.0.0.2"); //Use udp to send messages to 1.0.0.2
socket.tcp("Hi xxx", "1.0.0.2"); //Use tcp to send messages reliably to 1.0.0.2
}
void loop(){
//No delay() could be used in loop()
socket.core(); //Socket service core
}
Usage - with If in loop()
#define LORA_SOCKET_IP "1.0.0.1" //need to be unique
#include "lora-socket.h"
LoRaSocket socket;
void setup(){
socket.ini(); //initalization
}
void loop(){
//No delay() could be used in loop()
if(socket.isNewMsg()){ //Determine whether there is new message
Serial.println(socket.getNewMsg()); //Print out new messages directly [Method 1]
String message, fromIP, toIP, msgType;
socket.getNewMsg(message, fromIP, toIP, msgType); //Get content and information by reference [Method 2]
}
socket.core(); //Socket service core
}