Je cherche de l'aide car je suis au bout de mes connaissances qui sont assez limitées en programmation. Disons que j'ai 40 ans et que cela fait un an que j'essaie sur RPi.
Mon Problème est
Je n'arrive pas à lire une DHT11 dans domoticz.J'ai cette erreur que je n'arrive pas à résoudre même avec différents scripts.
Code : Tout sélectionner
2019-04-16 21:43:00.367 Error: EventSystem: in /home/pi/domoticz/scripts/lua/script_time_DHT11.lua: /home/pi/domoticz/scripts/lua/script_time_DHT11.lua:1: attempt to call a nil value
2019-04-16 21:44:00.377 Error: EventSystem: in /home/pi/domoticz/scripts/lua/script_time_DHT11.lua: /home/pi/domoticz/scripts/lua/script_time_DHT11.lua:1: attempt to call a nil value
2019-04-16 21:45:00.387 Error: EventSystem: in /home/pi/domoticz/scripts/lua/script_time_DHT11.lua: /home/pi/domoticz/scripts/lua/script_time_DHT11.lua:1: attempt to call a nil value-1 RPi 3B+
pi@raspberrypi:~ $ lsb_release -a
No LSB modules are available.
Distributor ID: Raspbian
Description: Raspbian GNU/Linux 9.8 (stretch)
Release: 9.8
Codename: stretch
-1 Arduino Uno Rev3
-1 carte made in china DHT11 3 pins
5v,gnd et pin 4
Créé dans domoticz dummy, puis vue dans dispositifs:
idx:148
matériel: DHT11
ID: 140E4
nom: DHT11
type: Temp + Humidity
sous-type:THGN122/123/132, THGR122/228/238/268
données: 0.0 C, 50 %
Mon code Arduino IDE (dont version 1.8.9) statut ok en moniteur série avec variation des valeurs
Code : Tout sélectionner
#include <dht11.h>
dht11 DHT11;
#define DHT11PIN 4
void setup()
{
Serial.begin(9600);
Serial.println("DHT11 TEST PROGRAM ");
Serial.print("LIBRARY VERSION: ");
Serial.println(DHT11LIB_VERSION);
Serial.println();
}
void loop()
{
Serial.println("\n");
int chk = DHT11.read(DHT11PIN);
Serial.print("Read sensor: ");
switch (chk)
{
case DHTLIB_OK:
Serial.println("OK");
Serial.print("Humidity (%): ");
Serial.println((float)DHT11.humidity, 2);
Serial.print("Temperature (°C): ");
Serial.println((float)DHT11.temperature, 2);
Serial.print("Temperature (°F): ");
Serial.println(Fahrenheit(DHT11.temperature), 2);
Serial.print("Temperature (°K): ");
Serial.println(Kelvin(DHT11.temperature), 2);
Serial.print("Dew PointFast (°C): ");
Serial.println(dewPointFast(DHT11.temperature, DHT11.humidity));
break;
case DHTLIB_ERROR_CHECKSUM:
Serial.println("Checksum error");
break;
case DHTLIB_ERROR_TIMEOUT:
Serial.println("Time out error");
break;
default:
Serial.println("Unknown error");
break;
}
delay(2000);
}
//Celsius to Fahrenheit conversion
double Fahrenheit(double celsius)
{
return 1.8 * celsius + 32;
}
//Celsius to Kelvin conversion
double Kelvin(double celsius)
{
return celsius + 273.15;
}
// dewPoint function NOAA
// reference (1) : http://wahiduddin.net/calc/density_algorithms.htm
// reference (2) : http://www.colorado.edu/geography/weather_station/Geog_site/about.htm
double dewPointFast(double celsius, double humidity)
{
double a = 17.271;
double b = 237.7;
double temp = (a * celsius) / (b + celsius) + log(humidity*0.01);
double Td = (b * temp) / (a - temp);
return Td;
}À propos de Domoticz
Version: 4.9700
Build Hash: a3a45906
Compile Date: 2018-06-23 16:24:51
dzVents Version: 2.4.6
Python Version: 3.5.3 (default, Sep 27 2018, 17:25:39) [GCC 6.3.0 20170516]
-Mon script /home/pi/domoticz/scripts/lua/script_time_DHT11.lua
Code : Tout sélectionner
JSON = (loadfile "/home/pi/bin/domoticz/scripts/lua/JSON.lua")() -- one-time load of the routines
-- Index of DHT11 device in domoticz
local deviceIdx = 148
local serialPort = "/dev/ttyACM1"
commandArray = {}
-- Start job
-- Open seria port and read
rserial=io.open(serialPort, "r")
read_value = rserial:read()
local json_value = JSON:decode(read_value)
-- Data : TEMP;HUM;HUM_STAT
-- HUM_STAT can be one of:
-- 0=Normal
-- 1=Comfortable
-- 2=Dry
-- 3=Wet
local hum_stat = 0;
if json_value.hum<30 then hum_stat=2 end
if json_value.hum>70 then hum_stat=3 end
if (json_value.hum>=45 and json_value.hum<=50) then hum_stat=1 end
commandArray['UpdateDevice']=deviceIdx..'|148|'..json_value.temp..';'..json_value.hum..';'..hum_stat
return commandArray
Merci par avance pour votre aide!!!!