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¶m=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();
}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