diff --git a/lib/MeasureUnit/MeasureUnit.ino b/lib/MeasureUnit/MeasureUnit.ino index 79d5e74..f91f9d6 100644 --- a/lib/MeasureUnit/MeasureUnit.ino +++ b/lib/MeasureUnit/MeasureUnit.ino @@ -1,6 +1,6 @@ /** * Cet exemple correspond à l'application de test de la bibliothèque MeasureUnit qui - * permet de calculer la température mesurée par une matrice de thermistance + * permet de calculer la température qui est fonction de la résistance d'une matrice de thermistance * * Anatole SCHRAMM-HENRY * 17/12/2019 @@ -9,46 +9,79 @@ #include "MeasureUnit.h" #include "PayloadFormatter.h" #include "Ads1115.h" +#include "LoRaRadio.h" + +//#define RADIO_ENABLED uint8_t analogInput[] = {0,1,2,3,4,5,6,7}; double *tempArray = NULL; //Objet de calcule de la temperature -ThermistorSetting thermistorSetting(3380, 10000); +//ThermistorSetting thermistorSetting(3380, 10000); +ThermistorSetting thermistorSetting(3650, 470); //AdcSetting adcSetting(3300.0, 12, 310, 3); -AdcSetting adcSetting(3410.0, 15, 6, 10);//6, 10); +AdcSetting adcSetting(3298.13, 15, 6, 10);//6, 10); Ads1115 adc; -MeasureUnit measureUnit(analogInput, 8, 990, thermistorSetting, adc); +//MeasureUnit measureUnit(analogInput, 8, 990, thermistorSetting, adc); +MeasureUnit measureUnit(analogInput, 8, 99, thermistorSetting, adc); //Objet de création des trames LoRa PayloadFormatter payloadFormatter(2,4); DateTime payloadDate(2020,12,26,8,42); boolean data(false); -uint8_t *payload(NULL); +uint8_t *payload(NULL), _timeCounter(0), size(0), _channel(0); boolean calibrer(false); -unsigned long _time(millis()); +unsigned long _time(0); +/* + * Radio Part +*/ +void os_getArtEui (u1_t* buf) { } +void os_getDevEui (u1_t* buf) { } +void os_getDevKey (u1_t* buf) { } +void onEvent(ev_t ev) +{ + +} + +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] = {26,33,32}; +PinMap pinMap(18, LMIC_UNUSED_PIN, 14, dio); +LoRaRadio radio(pinMap); void setup() { Serial.begin(115200); delay(1000); Serial.println("Start setup"); + //Radio init + #ifdef RADIO_ENABLED + radio.init(); + radio.setTTNSession(0x1, DEVADDR, NWKSKEY, APPSKEY); + radio.setRadioEUChannels(); + #endif + //Adc init adc.setAdcSetting(adcSetting); //measureUnit.setGlobalTempOffset(-17); + _time = millis(); Serial.println("End setup"); - + Serial.println("| T1 | T2 | T3 | T4 | T5 | T6 | T7 | T8 |"); } -void loop() { - //Version synchrone +void loop() { + //Version synchrone (bloquante) //tempArray = measureUnit.getTemperatures(); + //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(); if(tempArray != NULL) @@ -68,7 +101,7 @@ void loop() { //On affiche la trame associée: payloadFormatter.startSession(1); - uint8_t size = payloadFormatter.buildPayload(&payload, &payloadDate,tempArray); + size = payloadFormatter.buildPayload(&payload, &payloadDate,tempArray); if(size != 0) { //Serial.print("LoRa packet --> ");Serial.print("size : ");Serial.print(size);Serial.println(" bytes"); @@ -80,26 +113,30 @@ void loop() { } else Serial.print("Failed to build LoRa packet"); - /*if(payloadFormatter.endSession()) - Serial.println("Session ended successfully");*/ + //if(payloadFormatter.endSession()) + //Serial.println("Session ended successfully"); + + #ifdef RADIO_ENABLED + if(_timeCounter == 30 && size != 0) + { + _timeCounter = 0; + Serial.printf("Sending data\n"); + radio.send(1, payload, size); + } + + _timeCounter++; + #endif } //On effectue la calibration - if(millis() - _time > 5000 && !calibrer) + /*if(millis() - _time > 5000 && !calibrer) { Serial.println("********************Starting calibration********************"); measureUnit.levelAsyncTemperaturesOff(); Serial.println("********************Ending calibration********************"); calibrer = true; - } - - if(Serial.available()) - { - if(Serial.read() == 'c') - { - //Serial.println("********************Starting calibration********************"); - measureUnit.levelAsyncTemperaturesOff(); - //Serial.println("********************Ending calibration********************"); - } - } + }*/ + #ifdef RADIO_ENABLED + radio.run(); + #endif }