1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
|
//******************************************************************************
// SENSOR_FN.ino
//******************************************************************************
//=======================================================
#ifdef nrf
//=======================================================
void do_read_ulica() //<==== module déporté
{
static uint32_t t_fn=0;
byte pipeNo;
if (millis()-period_ulica<600000&&period_ulica!=0) // 10 mn
{
return;
}
if (millis()-t_fn<1000)
{
return;
}
t_fn=millis();
if (millis()-period_ulica>300000) // 5 mn
temp_u=200;
ref_temp_u=false;
Serial.println("read ulica");
if ( radio.available(&pipeNo)) // Non-blocking
{
uint8_t buff[32];
uint8_t len = sizeof(buff);
int i;
radio.read( &buff, sizeof(buff) );
String strth= (const char*) buff;
Serial.println(strth);
////////////////////////l'identification du paquet
if (strth.substring(0,6)=="25UTH;")
{
if (strth.indexOf(";",7)!=9&& strth.indexOf(";",10)!=13)
{
Serial.println(F("erreur d'analyse"));
delay(500);
}else{
Serial.print(F("ulica="));
Serial.println(strth);
//ppppp
String sth=strth.substring(6,9); //3 simv
if (sth.toInt()>150&&sth.toInt()<260)
{
if (temp_u!= sth.toInt()-200)
ref_temp_u=true;
temp_u=sth.toInt()-200;
period_ulica=millis();
if (log_file)
{
log_str="nrf24 do_read_ulica temp_u="+String(temp_u);
do_log();
}
}
}
}
}
}
#endif
//================================================================
#ifdef dht22
//================================================================
void do_read_dht()
{
static time_t t_period_dht=0;
delay(dht.getMinimumSamplingPeriod());
if (millis()<t_period_dht&&temp_kv!=200) return; //5min
// Reading temperature or humidity takes about 250 milliseconds!
// Les relevés des capteurs peuvent également être vieux de 2 secondes (c'est un capteur très lent)
float hum = dht.getHumidity();
float temp= dht.getTemperature();
float correction = 3 ;
temp_kv=(round(temp)-correction);
h_kv=round(hum);
// Check if any reads failed and exit early (to try again).
if (isnan(temp_kv) || isnan(h_kv)) {
Serial.println("Impossible de lire la sonde DHT!");
return;
}
#ifdef debug
float hic = dht.computeHeatIndex(temp_kv, h_kv, false);
Serial.print("Humidite: ");
Serial.println(h_kv);
Serial.print("Temperature: ");
Serial.println(temp_kv-4);
Serial.print("Heat index: ");
Serial.println(hic);
#endif debug
if (temp_kv<-50||temp_kv>70)
{
if (log_file)
{
log_str="DHT22 ERR temp_kv="+String(temp_kv);
do_log();
}
temp_kv=200;
}
if (h_kv<0||h_kv>100)
{
if (log_file)
{
log_str="DHT22 ERR H="+String(h_kv);
do_log();
}
h_kv=200;
}
if (temp_kv!=200)
{
ref_kv_th=true;
t_period_dht=millis()+t_dht_ref*200; //5min
}
}
#endif |