diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..afc115a --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,68 @@ +#include +#include +#include + +#define LORA_SCK 5 +#define LORA_MISO 19 +#define LORA_MOSI 27 +#define LORA_NSS 18 +#define LORA_RST 23 +#define LORA_DIO0 26 +#define LORA_DIO1 33 + +void loraReset() { + pinMode(LORA_RST, OUTPUT); + digitalWrite(LORA_RST, LOW); + delay(10); + digitalWrite(LORA_RST, HIGH); + delay(10); +} + +SX1276 radio = new Module(LORA_NSS, LORA_DIO0, LORA_RST, LORA_DIO1); + +uint64_t joinEUI = 0x35f48318e1324e2e; +uint64_t devEUI = 0x0586fe41112d83d9; +uint8_t appKey[] = { + 0x0b, 0x84, 0xb4, 0x04, 0x0f, 0xd5, 0x56, 0x1b, + 0x00, 0x53, 0x94, 0x22, 0xc1, 0xf1, 0x4f, 0xd6 +}; +uint8_t *nwkKey = appKey; + +LoRaWANNode node(&radio, &EU868); + +void setup() { + Serial.begin(115200); + delay(2000); + + loraReset(); + SPI.begin(LORA_SCK, LORA_MISO, LORA_MOSI, LORA_NSS); + + Serial.print("[LoRa] Init... "); + int state = radio.begin(); + if (state != RADIOLIB_ERR_NONE) { + Serial.printf("ERREUR %d\n", state); + while (true) { delay(1000); } + } + Serial.println("OK"); + + node.beginOTAA(joinEUI, devEUI, nwkKey, appKey); + + Serial.print("[LoRaWAN] Join... "); + state = node.activateOTAA(); + if (state != RADIOLIB_LORAWAN_NEW_SESSION) { + Serial.printf("Echec : %d\n", state); + while (true) { delay(1000); } + } + Serial.println("Join OK !"); +} + +void loop() { + uint8_t payload[] = { 0x01, 0x02, 0x03 }; + int state = node.sendReceive(payload, sizeof(payload), 1); + if (state == RADIOLIB_ERR_NONE || state == RADIOLIB_LORAWAN_NO_DOWNLINK) { + Serial.println("[TX] OK"); + } else { + Serial.printf("[TX] Erreur : %d\n", state); + } + delay(60000); +} \ No newline at end of file