Page 1 sur 1

DHT11 Arduino Uno Serial USB RPi 3B+ Domoticz

Publié : 16 avr. 2019, 22:11
par Dane01000
erreur lua8.PNG
erreur lua8.PNG (148.83 Kio) Consulté 2436 fois
Bonjour à tous,
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
Je décrit mon montage:
-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;
}
-Mon Domoticz:
À 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!!!!

Re: DHT11 Arduino Uno Serial USB RPi 3B+ Domoticz

Publié : 18 avr. 2019, 20:08
par Neutrino
Bonjour,

Tu es sûr du chemin de ta première ligne ?
JSON = (loadfile "/home/pi/bin/domoticz/scripts/lua/JSON.lua")() -- one-time load of the routines

Comment lire une ligne d'erreur :
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:43:00.367 : Moment où est intervenue l'erreur
EventSystem : Origine de l'erreur EventSystem = Script
in /home/pi/domoticz/scripts/lua/script_time_DHT11.lua : Fichier qui à remonté l'erreur
/home/pi/domoticz/scripts/lua/script_time_DHT11.lua:1 : fichier et numéro de ligne de l'erreur
attempt to call a nil value : Tentative d'appel d'une valeur nulle

Re: DHT11 Arduino Uno Serial USB RPi 3B+ Domoticz

Publié : 18 avr. 2019, 22:10
par Antori91
Bonsoir,
Déjà à priori un problème avec votre code Arduino, il n'imprime pas un format JSON à la syntaxe correcte. Vous imprimez par exemple Humidity (%): 55 quand il faut imprimer "Humidity (%)" : "55". Vous pouvez vous inspirer de la ligne 168 du code https://github.com/Antori91/Home_Automa ... _Dht22.ino
Exemple de JSON que génère cette ligne 168 de code ;
{
"SensorID":"TEMPOUEST",
"Temperature_Celsius":" 19.7",
"Humidity_Percentage":" 66.0",
"HeatIndex_Celsius":" 19.4",
"Sensor_Elapse_Running_Time":"392:30:41"
}

PS: A noter que si JSON.lua attend un JSON valide, c'est tout le JSON généré par votre code Arduino qui est à revoir.