#defineLORA_SOCKET_IP"1.0.0.1"//need to be unique
#include"lora-socket.h"
LoRaSocket socket;
voidsetup(){
socket.ini(); //initalization
socket.onReceived(doIfRec); //Register a callback function, which is triggered when a new message is received
}
voiddoIfRec(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
}
voidloop(){
//No delay() could be used in loop()
socket.core(); //Socket service core
}
Usage - with If in loop()
#defineLORA_SOCKET_IP"1.0.0.1"//need to be unique
#include"lora-socket.h"
LoRaSocket socket;
voidsetup(){
socket.ini(); //initalization
}
voidloop(){
//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
}