#include "LoRaWanMinimal_APP.h" #include "Arduino.h" //Set these OTAA parameters to match your app/node in TTN uint8_t devEui[] = { 0x70, 0xB3, 0xD5, 0x7E, 0xD0, 0x05, 0x4C, 0xD7 }; uint8_t appEui[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; uint8_t appKey[] = { 0xB9, 0xE1, 0xD1, 0xCA, 0x92, 0x70, 0x51, 0x69, 0x04, 0x78, 0x1F, 0xF9, 0xDA, 0xE0, 0xA7, 0xCA }; int temps = 180; // Indiquez dans cette ligne la fréquence d'envoi de données, en secondes. (Ne pas aller plus bas que 3minutes, soit 180sec) uint16_t userChannelsMask[6]={ 0x00FF,0x0000,0x0000,0x0000,0x0000,0x0000 }; static uint8_t counter=0; uint8_t lora_data[3]; uint8_t downlink ; /////////////////////////////////////////////////// //Some utilities for going into low power mode TimerEvent_t sleepTimer; //Records whether our sleep/low power timer expired bool sleepTimerExpired; static void wakeUp() { sleepTimerExpired=true; } static void lowPowerSleep(uint32_t sleeptime) { sleepTimerExpired=false; TimerInit( &sleepTimer, &wakeUp ); TimerSetValue( &sleepTimer, sleeptime ); TimerStart( &sleepTimer ); //Low power handler also gets interrupted by other timers //So wait until our timer had expired while (!sleepTimerExpired) lowPowerHandler(); TimerStop( &sleepTimer ); } /////////////////////////////////////////////////// void setup() { Serial.begin(115200); LoRaWAN.begin(LORAWAN_CLASS, ACTIVE_REGION); //Enable ADR LoRaWAN.setAdaptiveDR(true); while (1) { Serial.print("Joining... "); LoRaWAN.joinOTAA(appEui, appKey, devEui); if (!LoRaWAN.isJoined()) { //In this example we just loop until we're joined, but you could //also go and start doing other things and try again later Serial.println("JOIN FAILED! Sleeping for 30 seconds"); lowPowerSleep(30000); } else { Serial.println("JOINED"); break; } } } /////////////////////////////////////////////////// void loop() { counter++; delay(10); uint8_t voltage = getBatteryVoltage()/50; //Voltage in % int sensorValue2 = analogRead(ADC2)/16; int sensorValue3 = analogRead(ADC3)/16; Serial.printf("\nVal 2 : %d\n", sensorValue2); Serial.printf("\nVal 3 : %d\n", sensorValue3); Serial.printf("\nVoltage : %d\n", voltage); lora_data[0] = voltage; lora_data[1] = sensorValue2; lora_data[2] = sensorValue3; //Now send the data. The parameters are "data size, data pointer, port, request ack" Serial.printf("\nSending packet with counter=%d\n", counter); Serial.printf("\nValue 1 to send : %d\n", lora_data[1]); //Here we send confirmed packed (ACK requested) only for the first two (remember there is a fair use policy) bool requestack=counter<2?true:false; if (LoRaWAN.send(sizeof(lora_data), lora_data, 1, requestack)) { Serial.println("Send OK"); } else { Serial.println("Send FAILED"); } lowPowerSleep(temps*1000); delay(10); }