Datasheet
Schematic
#include <M5Stack.h>
#include <M5LoRa.h>
//declaration
String outgoing; // outgoing message
byte msgCount = 0; // count of outgoing messages
byte localAddress = 0xBB; // address of this device
byte destination = 0xFF; // destination to send to
//initialization
M5.begin();
LoRa.setPins(); // set CS, reset, IRQ pin
LoRa.begin(433E6); // initialize ratio at 915 MHz
//send message
void sendMessage(String outgoing) {
LoRa.beginPacket(); // start packet
LoRa.write(destination); // add destination address
LoRa.write(localAddress); // add sender address
LoRa.write(msgCount); // add message ID
LoRa.write(outgoing.length()); // add payload length
LoRa.print(outgoing); // add payload
LoRa.endPacket(); // finish packet and send it
msgCount++; // increment message ID
//receive message
void onReceive(int packetSize) {
if (packetSize == 0) return; // if there's no packet, return
int recipient = LoRa.read(); // recipient address
byte sender = LoRa.read(); // sender address
byte incomingMsgId = LoRa.read(); // incoming msg ID
byte incomingLength = LoRa.read(); // incoming msg length
String incoming = "";
while (LoRa.available()) {
incoming += (char)LoRa.read();
}
}
onReceive(LoRa.parsePacket());
M5Stack Docs