classe-c.ino
For a mains-powered actuator, class C divides downlink latency: the MKR WAN 1310 listens to RX2 continuously and applies a server command within seconds. Quiescent current rises to ~20 mA — mains installations only, never on battery.
Hardware
An Arduino MKR WAN 1310 (SAMD21 microcontroller, LoRa modem driven by an onboard ESP32 that also exposes Wi-Fi, LoRa antenna and Wi-Fi antenna). MKR WAN 1310 on mains/USB power, relay or actuator on pin 6, LoRaWAN server.
Wiring
Relay via transistor as in the P2P example; stable supply mandatory (the radio listens permanently).
How it works
MODEL_TYPE_C configures the stack to re-listen to RX2 whenever idle. parseIncoming() delivers downlinks as they arrive; latency depends on the server, not on the next uplink.
Running it
Install Arduino SAMD Boards and the MKRWAN 2.x library (MKRWAN1310), select the board, upload. The 1310 is driven through AT commands over its internal ESP32; for LoRa, plan a second LoRa board on the other end.
Variants
A class A compromise with short uplink periods if energy is limited, or pin a single RX2 channel server-side to make listening reliable.
classe-c.ino
// Class C : la MKR WAN 1310 ecoute RX2 en permanence (sur secteur).
// Ideal actionneur : la consigne serveur est appliquee en secondes.
#include <MKRWiSOLAR.h>
const uint8_t DEVICE_EUI[] = {0xDE,0xAD,0xBE,0xEF,0xFE,0xED,0xC0,0xFF};
const uint8_t APP_EUI[] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
const uint8_t APP_KEY[16] = {0}; // a provisionner
LoRaWAN lora;
const int RELAIS = 6;
void setup() {
Serial.begin(9600);
pinMode(RELAIS, OUTPUT);
lora.setDeviceEui(DEVICE_EUI);
lora.setAppEui(APP_EUI);
lora.setAppKey(APP_KEY);
lora.setRegion(EU_863_870_R1);
// MODEL_TYPE_C = class C : RX2 quasi permanente entre emissions
if (lora.join(OTAA, MODEL_TYPE_C, 30000, 8) == 0) while (true);
Serial.println(F("Class C a l'ecoute sur RX2 869.525 MHz"));
}
void loop() {
lora.run(); // ecoute RX2 + traitement des downlinks
if (lora.parseIncoming()) {
uint8_t *d = lora.getData();
if (lora.getDataPort() == 10 && lora.getDataSize() >= 1) {
digitalWrite(RELAIS, d[0] ? HIGH : LOW);
Serial.println(d[0] ? F("RELAI ON") : F("RELAI OFF"));
}
}
}