LOLIN D32 avec capteur de pression HP303B et temp/SHT3X

Forum pour tous les autres objets : sondes météo, capteurs, actionneurs ...
Vous avez un besoin mais vous ne savez pas quel matériel choisir ? C'est ici.
damolc
Messages : 240
Inscription : 24 juil. 2016, 22:08

LOLIN D32 avec capteur de pression HP303B et temp/SHT3X

Message par damolc »

bonjour
je cherche depuis plusieurs jours a programmer pour l envoie dans Domoticz des mesures de pression humidité et pressions
je passe par arduino avec comme code :

Code : Tout sélectionner

#include <WiFi.h>
#include <LOLIN_HP303B.h>
#include <WEMOS_SHT3X.h>
#include <HTTPClient.h>
#include <PubSubClient.h>
#define IDX_THP 941
LOLIN_HP303B HP303B;
SHT3X sht30(0x45);
const char* ssid     = "xxxxxx";
const char* password = "xxxxxxxxx";
const char* host = "192.168.1.xx";
const int   port = 8080;
const int   watchdog = 60000; // Fréquence d'envoi des données à Domoticz - Frequency of sending data to Domoticz
unsigned long previousMillis = millis(); 


HTTPClient http;

void setup() {
 Serial.begin(115200);
    pinMode(5, OUTPUT);      // set the LED pin mode
  while (!Serial)
        ;

    //Address of the HP303B (0x77 or 0x76)
    HP303B.begin(); // I2C address = 0x77

    // HP303B.begin(0x76); //I2C address = 0x76
    delay(10);
  
  Serial.setDebugOutput(true);  
  Serial.println("Connecting Wifi...");

  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
   
  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.print(WiFi.localIP()); 
}

int value = 0;

void loop() {
  if(sht30.get()==0){
    Serial.print("Temperature in Celsius : ");
    Serial.println(sht30.cTemp);
    Serial.print("Relative Humidity : ");
    Serial.println(sht30.humidity);
    Serial.println();
  }
  else
  {
    Serial.println("Error!");
  }
  delay(1000);
  int32_t temperature;
    int32_t pressure;
    int16_t oversampling = 7;
    int16_t ret;
    Serial.println();

    //lets the HP303B perform a Single temperature measurement with the last (or standard) configuration
    //The result will be written to the paramerter temperature
    //ret = HP303B.measureTempOnce(temperature);
    //the commented line below does exactly the same as the one above, but you can also config the precision
    //oversampling can be a value from 0 to 7
    //the HP303B will perform 2^oversampling internal temperature measurements and combine them to one result with higher precision
    //measurements with higher precision take more time, consult datasheet for more information
    ret = HP303B.measureTempOnce(temperature, oversampling);

    if (ret != 0)
  unsigned long currentMillis = millis();

 

    if(WiFi.status() != WL_CONNECTED) {
      Serial.println("WiFi not connected !");
    } else {  
      Serial.println("Send data to Domoticz");
 ret = HP303B.measureTempOnce(temperature, oversampling);

    if (ret != 0)
    {
        //Something went wrong.
        //Look at the library code for more information about return codes
        Serial.print("FAIL! ret = ");
        Serial.println(ret);
    }
    else
    {
        Serial.print("Temperature: ");
        Serial.print(temperature);
        Serial.println(" degrees of Celsius");
    }

    //Pressure measurement behaves like temperature measurement
    //ret = HP303B.measurePressureOnce(pressure);
    ret = HP303B.measurePressureOnce(pressure, oversampling);
    if (ret != 0)
    {
        //Something went wrong.
        //Look at the library code for more information about return codes
        Serial.print("FAIL! ret = ");
        Serial.println(ret);
    }
    else
    {
        Serial.print("Pressure: ");
        Serial.print(pressure);
        Serial.println(" Pascal");
    }

    //Wait some time
    delay(500);
        
      float t = int(sht30.cTemp);
      float h = int(sht30.humidity);
      float pa = int(pressure);
      
      if ( isnan(t) || isnan(h) ) {
        Serial.println("DHT KO");
      } else {
        int hum_stat;
        int bar_for = 0;
        if ( h > 70 ) {
          hum_stat = 3;
        } else if ( h < 30 ) {
          hum_stat = 2; 
        } else if ( h >= 30 & h <= 45 ) {
          hum_stat = 0;
        } else if ( h > 45 & h <= 70 ) {
          hum_stat = 1;
        }

        if ( pa > 1030 ) {
          bar_for = 1;  
        } else if ( pa > 1010 & pa <= 1030 ) {
          bar_for = 2;
        } else if ( pa > 990 & pa <= 1010 ) {
          bar_for = 3;
        } else if ( pa > 970 & pa < 990 ) {
          bar_for = 4;
        }
        
        String url = "/json.htm?type=command&param=udevice&idx=941&nvalue=0&svalue=";
        url += String(t); url += ";";
        url += String(h); url += ";";
        url += String(hum_stat); url += ";";
        url += String(pa);url += ";";
        url += String(bar_for);
     
        sendDomoticz(url);
      }
    }
  }
}

void sendDomoticz(String url){
  Serial.print("connecting to ");
  Serial.println(host);
  Serial.print("Requesting URL: ");
  Serial.println(url);
  http.begin(host,port,url);
  int httpCode = http.GET();
    if (httpCode) {
      if (httpCode == 200) {
        String payload = http.getString();
        Serial.println("Domoticz response "); 
        Serial.println(payload);
      }
    }
  Serial.println("closing connection");
  http.end();
}
malheureusement j ai toujours le meme message d erreur :
exit status 1
'sendDomoticz' was not declared in this scope
avec sur le log :

Code : Tout sélectionner

Arduino : 1.8.13 (Windows 7), Carte : "WEMOS LOLIN32, 80MHz, Default, 240MHz (WiFi/BT), 921600"
.....................
C:\Users\david\Documents\Arduino\test_fin\test_fin.ino: In function 'void loop()':
test_fin:157:25: error: 'sendDomoticz' was not declared in this scope

         sendDomoticz(url);

                         ^

C:\Users\david\Documents\Arduino\test_fin\test_fin.ino: At global scope:

test_fin:161:1: error: expected declaration before '}' token

 }
...........................
exit status 1
'sendDomoticz' was not declared in this scope

pourriez vous m aider pour corriger ça? merci
Keros
Messages : 6638
Inscription : 23 juil. 2019, 20:57

Modération

Message par Keros »

Sujet déplacé dans la section des capteurs.
Comment bien utiliser le forum : Poser une question, Mettre un script, un fichier, une image ou des logs
Mes petits guides : Débuter en programmation, Le débogage, Le choix de matériel, Les sauvegardes
Ma présentation - Mes Tutos
boum
Messages : 233
Inscription : 18 janv. 2019, 11:34
Localisation : France

Re: LOLIN D32 avec capteur de pression HP303B et temp/SHT3X

Message par boum »

il faut peut-être juste déplacer la fonction void sendDomoticz(String url){ … } plus haut dans le programme. Avant loop(), mais après HTTPClient http;
Domoticz v2022.2 sur linux-mint / Z-Wave-JS / RFXCom / Zigbee2MQTT
higgins91
Messages : 669
Inscription : 17 nov. 2016, 11:06

Re: LOLIN D32 avec capteur de pression HP303B et temp/SHT3X

Message par higgins91 »

il te manque quelque chose,

ligne 76 y'a un if sans "{"

du coup ta boucle void loop() { se termine une "}" trop tot !

tu peux faire un CTRL+T dans l'IDE pour faire un formatage auto, cela te permets de vite repérer le problème...

j'ai compilé sur mon poste et ça passe en rajoutant "{" ligne 76:

Code : Tout sélectionner

  if (ret != 0) {
Dz version : 2024.7
Rpi 4 avec dongle téléinfo, GPIO pour le moment !
higgins91
Messages : 669
Inscription : 17 nov. 2016, 11:06

Re: LOLIN D32 avec capteur de pression HP303B et temp/SHT3X

Message par higgins91 »

boum a écrit : 09 janv. 2021, 00:12 il faut peut-être juste déplacer la fonction void sendDomoticz(String url){ … } plus haut dans le programme. Avant loop(), mais après HTTPClient http;
pas besoin, les fonctions peuvent etre placées ou l'on veux, c'est le compilateur qui se charge du reste.
Dz version : 2024.7
Rpi 4 avec dongle téléinfo, GPIO pour le moment !
boum
Messages : 233
Inscription : 18 janv. 2019, 11:34
Localisation : France

Re: LOLIN D32 avec capteur de pression HP303B et temp/SHT3X

Message par boum »

Au temps pour moi. L'habitude du C. Au pire déplacer la fonction aurait changé le message d'erreur et aidé à la résolution.
Bien joué pour avoir trouvé le pb.
Dernière modification par Keros le 09 janv. 2021, 21:50, modifié 1 fois.
Raison : Merci de ne pas citer le message précédent lors d'une réponse directe
Domoticz v2022.2 sur linux-mint / Z-Wave-JS / RFXCom / Zigbee2MQTT
Répondre