/** * Cet exemple correspond à l'application de test de la bibliothèque MeasureUnit qui * permet de calculer la température qui est fonction de la résistance d'une matrice de thermistance * * Anatole SCHRAMM-HENRY * Tim THUREL * Version compatible avce le LTC2439 * 10/05/2020 */ #include #include #include #include #include #include "MeasureUnit.h" #include "ThermistorSettings.h" #include //#define RADIO_ENABLED #define PUSH_BUTTON 0 /* * Liste des offsets trouvés * | -0.49 | 0.36 | -0.29 | 0.38 | 0.44 | -0.35 | -0.21 | 0.14 | * | -0.72 | 0.07 | -0.52 | -0.01 | 2.38 | -0.65 | -0.44 | -0.11 | * | -0.99 | -0.06 | -0.74 | 2.24 | 0.73 | -0.86 | -0.68 | 0.35 | * | -0.53 | -0.49 | -0.27 | 1.17 | 0.07 | 0.14 | -0.02 | -0.08 | * | -0.62 | -0.73 | 1.58 | 0.42 | -0.27 | 0.09 | -0.25 | -0.21 | * */ //Objet de calcule de la température LTC2439 adc(2,12); ThermistorSettings thermistorSettings(3380, 10000); MeasureUnit measureUnit(16, 1000, thermistorSettings, adc); //Objet de création des trames LoRa PayloadFormatter payloadFormatter(1,16); RTC_DS1307 rtc; DateTime payloadDate; STS21 sts21; boolean data(false); uint8_t *payload(NULL), _timeCounter(0), size(0), _channel(0); boolean calibrer(false); unsigned long _time(0); double *tempArray = NULL; /* * Radio Part */ void os_getArtEui (u1_t* buf) { } void os_getDevEui (u1_t* buf) { } void os_getDevKey (u1_t* buf) { } static u1_t NWKSKEY[16] = { 0x1F, 0x9E, 0xE2, 0x7A, 0xC8, 0xBA, 0xE8, 0xEA, 0xF5, 0xC2, 0x5E, 0x47, 0x5D, 0xE0, 0x77, 0x55 }; static u1_t APPSKEY[16] = { 0x3B, 0x89, 0x86, 0x96, 0xBB, 0xAA, 0x38, 0x1E, 0x1F, 0xC4, 0xAD, 0x03, 0xEF, 0x3F, 0x56, 0x12 }; static u4_t DEVADDR = 0x260113D3;//0x03FF0001 ; // <-- Change this address for every node! u1_t dio[3] = {15,3,LMIC_UNUSED_PIN}; PinMap pinMap(2, LMIC_UNUSED_PIN, 0, dio); LoRaRadio radio(pinMap); void downlinkHandler(u1_t length, u1_t dataBeg, u1_t *data) { Serial.println("Downlink received : "); for(uint8_t i(0); i < length; i++) { Serial.printf("%u -> %d\n",i,data[dataBeg + i]); } Serial.println(); //Action en fonction de l'octet de commande switch(data[dataBeg+0]) { case 0x01://Mise à jour de l'heure //Octets suivants: //2 jour 3 mois 4 année 5 heures 6 minutes if(length == 6) { Serial.printf("dd: %u, m: %u, yyyy: %d, hh: %u, mm: %u\n", data[dataBeg+1], data[dataBeg+2], data[dataBeg+3]+2000, data[dataBeg+4], data[dataBeg+5]); } else Serial.println("Action réglage RTC : paramètres insuffisants"); break; case 0x02: /*memcpy(screenTxt,(data+dataBeg+1), length-1); screenTxt[length-1] = '\0'; display.stopscroll(); display.clearDisplay(); display.setTextColor(WHITE); display.setCursor(0,15); display.setTextSize(2); display.print(screenTxt); display.display(); display.startscrollleft(0,16);*/ break; default: Serial.println("Action inconnue"); } } void setup() { Serial.begin(115200); delay(1000); Serial.println("Start setup"); WiFi.mode(WIFI_OFF); //Partie concernant l'initialisation de la radio #ifdef RADIO_ENABLED radio.init(); radio.setTTNSession(0x1, DEVADDR, NWKSKEY, APPSKEY); radio.setRadioEUChannels(); /* * La directive setMCUClockError() permet de laisser une fenêtre plus grande pour le slot de * réception (Downlink). En effet ce slot doit durer 2 secondes et il peut durer moins en raison * d'imprécisions d'horloge. */ //radio.setMCUClockError(50); radio.setDownlinkHandler(&(downlinkHandler)); #endif _time = millis(); if(rtc.begin()) Serial.println("RTC Ok!"); else Serial.println("RTC Fail!"); if(sts21.begin()) { Serial.println("Sensor present !"); sts21.setResolution(STS21::RES_14); } else Serial.println("Sensor missing !"); Serial.println("End setup"); Serial.println("| T1 | T2 | T3 | T4 | T5 | T6 | T7 | T8 | T9 | T10 | T11 | T12 | T13 | T14 | T15 | T16 |"); } void loop() { //Version asynchrone : measureUnit.startTemperatureMeasurement(); //On peut tester si la conversion est terminée avec : //if(measureUnit.isMeasurementReady()) //measureUnit.getAsyncTemperatures() renvoie NULL si la recupération de la température n'est pas terminée tempArray = measureUnit.getAsyncTemperatures(); double temp = sts21.getTemperature(); if(tempArray != NULL) { Serial.print("|"); for(int i(0); i < 16; i++) { Serial.print(" ");Serial.print(tempArray[i],2);Serial.print(" |"); } //On affiche la trame associée: payloadFormatter.startSession(1); payloadDate = rtc.now(); size = payloadFormatter.buildPayload(&payload, &payloadDate, 22.5,tempArray); if(size != 0) { //Serial.print("LoRa packet --> ");Serial.print("size : ");Serial.print(size);Serial.println(" bytes"); for(int i(0); i < size; i++) { payload[i] <= 0x0F ? Serial.print("0") : Serial.print(""); Serial.print(payload[i], HEX); Serial.print(" "); } Serial.printf("|%u-%u-%u %u:%u ext temp : %.2f \n", payloadDate.day(),payloadDate.month(),payloadDate.year(),payloadDate.hour(),payloadDate.minute(), temp); } else Serial.print("Failed to build LoRa packet"); payloadFormatter.endSession(); #ifdef RADIO_ENABLED if(_timeCounter == 30 && size != 0) { _timeCounter = 0; Serial.printf("Sending data\n"); radio.send(1, payload, size); } _timeCounter++; delay(1000); #endif } //On effectue la calibration #ifdef RADIO_ENABLED radio.run(); #endif measureUnit.run(); }