Algorithme général
main.m
void setup()
setupCapteurTemperature();
getIdCapteurTemperature();
connectWiFi();
delay(INIT_T);
void loop()
while(count < COUNT_T) count=TempLoop(t,count);
disconnectWiFi();
delay(PAUSE);
ESP.restart();
// Boucle d'acquisition de la température
int TempLoop(unsigned long now, int count){
if( now - lastTemp > STEP_T ){
// Acquisition de la température
temperature = getTemperature();
// Envoi de la mesure par la REST-api
sendDatasREST(ID_T, temperature);
++count;
// Temps de la dernière mesure acquise
lastTemp = millis();
}
return count;
}ThingSpeak.h
host = "api.thingspeak.com"
// envoie des données avec la REST-api
void sendDatasREST(String ID_T, float temperature) {
char STR_T[6];
if(connected) {
WiFiClient client;
const int httpPort = 80;
if (client.connect(host, httpPort)) {
dtostrf(temperature, 2, 4, STR_T);
client.print(String("GET ") + path + "&field1="+ ID_T + "&field2=" + STR_T + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"Connection: keep-alive\r\n\r\n");
}
}
return;
}PARAMETRES.h
// Paramètres généraux du Capteur de température static const float DELTA_T = 0.55; // (°C), delta de calibration static const int RESOLUTION_T = 12; // résolution, comprise entre 9 et 12 // Paramètres de l'acquisition de température (temps en s) static const int ts_INIT_T = 5; // (s) static const int ts_STEP_T = 20; // (s) static const int tm_STEP_T = 0; // (min) static const int COUNT_T = 5; // (nombre) // Paramètres de mise en pause static const int ts_PAUSE = 0; // (s) static const int tm_PAUSE = 20; // (min)