Sensori BMP085 , DHT22 con systemd (Raspbian Jessie)

Discussioni relative all'uso di sensori vari (temperatura, umidità, ....)
dottorniù
Messaggi: 36
Iscritto il: 16/03/2016, 23:49

Re: Sensori BMP085 , DHT22 con systemd (Raspbian Jessie)

Messaggioda dottorniù » 17/11/2016, 4:31

Buongiorno,

questo è /etc/systemd/system/dht22.service

Codice: Seleziona tutto

[Unit]
Description=dht22

[Service]
Type=oneshot
ExecStart=/usr/local/bin/dht22.sh 22 4 6

[Install]
WantedBy=multi-user.target



questo /usr/local/bin/dht22.sh

Codice: Seleziona tutto

#!/bin/sh
DATA="$(ADHT_metern.py $1 $2 $3)"
#echo $DATA
if [ x"$DATA" != x ] && [ "$DATA" != "ERROR" ]; then
 echo $DATA | cut -f 1 –d\ > /run/shm/metern$3.txt
 echo $DATA | cut -f 2 –d\ >> /run/shm/metern$3.txt
fi


e questo /usr/local/bin/ADHT_metern.py

Codice: Seleziona tutto

#!/usr/bin/python
# Copyright (c) 2014 Adafruit Industries
# Author: Tony DiCola
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
import sys
import Adafruit_DHT
# Parse command line parameters.
sensor_args = { '11': Adafruit_DHT.DHT11,
 '22': Adafruit_DHT.DHT22,
 '2302': Adafruit_DHT.AM2302 }
if len(sys.argv) == 4 and sys.argv[1] in sensor_args:
 sensor = sensor_args[sys.argv[1]]
 pin = sys.argv[2]
 id = sys.argv[3]
else:
 print 'usage: sudo ./Adafruit_DHT.py [11|22|2302] GPIOpin# metern_id'
 print 'example: sudo ./Adafruit_DHT.py 2302 4 8 - Read from an AM2302 connected to GPIO #4 and metern id 8'
 sys.exit(1)
# Try to grab a sensor reading. Use the read_retry method which will retry up
# to 15 times to get a sensor reading (waiting 2 seconds between each retry).
humidity, temperature = Adafruit_DHT.read_retry(sensor, pin)
# Note that sometimes you won't get a reading and
# the results will be null (because Linux can't
# guarantee the timing of calls to read the sensor).
# If this happens try again!
if humidity is not None and temperature is not None:
 print '{0}_1({1:0.1f}*C)'.format(id, temperature)
 print '{0}_2({1:0.1f}*%)'.format(id, humidity)
else:
 print 'ERROR'
 sys.exit(1)



Avatar utente
Flane
Messaggi: 2460
Iscritto il: 16/01/2016, 15:02

Re: Sensori BMP085 , DHT22 con systemd (Raspbian Jessie)

Messaggioda Flane » 17/11/2016, 8:16

Nel file service prova a specificare anche l'interprete:

Codice: Seleziona tutto

ExecStart=/bin/sh /usr/local/bin/dht22.sh 22 4 6


Non sò se risolve ma si tratta di capire cosa non và nel service .....

dottorniù
Messaggi: 36
Iscritto il: 16/03/2016, 23:49

Re: Sensori BMP085 , DHT22 con systemd (Raspbian Jessie)

Messaggioda dottorniù » 17/11/2016, 12:45

da una lettura veloce mi pare restituisca lo stesso errore

Codice: Seleziona tutto

pi@raspberrypi:~ $ sudo systemctl start dht22.service
Job for dht22.service failed. See 'systemctl status dht22.service' and 'journaltl -xn' for details.
pi@raspberrypi:~ $ sudo systemctl status dht22.service
● dht22.service - dht22
   Loaded: loaded (/etc/systemd/system/dht22.service; enabled)
   Active: failed (Result: exit-code) since gio 2016-11-17 12:42:00 CET; 21s ag
  Process: 19970 ExecStart=/bin/sh /usr/local/bin/dht22.sh 22 4 6 (code=exited,status=1/FAILURE)
 Main PID: 19970 (code=exited, status=1/FAILURE)

nov 17 12:42:00 raspberrypi sh[19970]: [40B blob data]
nov 17 12:42:00 raspberrypi sh[19970]: [40B blob data]
nov 17 12:42:00 raspberrypi systemd[1]: dht22.service: main process exited, ...
nov 17 12:42:00 raspberrypi systemd[1]: Failed to start dht22.
nov 17 12:42:00 raspberrypi systemd[1]: Unit dht22.service entered failed state
Hint: Some lines were ellipsized, use -l to show in full.

dottorniù
Messaggi: 36
Iscritto il: 16/03/2016, 23:49

Re: Sensori BMP085 , DHT22 con systemd (Raspbian Jessie)

Messaggioda dottorniù » 19/11/2016, 14:57

:o uoooooooooo dopo tre giorni di sbattimenti sono arrivato a capo del problema e mi è venuta voglia di tirarmi un paio di martellate sui co....i :shock: :D

il problema erano i due meno che meno non erano nel file /usr/local/bin/dht22.sh
Non ricordavo più il thread di amorospo in cui elencava quello ed altri errori trovati nella guida.... avevo corretto tutto ma non quello :oops: :oops:

Ora tutto funziona regolarmente.

pluto21
Messaggi: 12
Iscritto il: 29/11/2016, 21:31

Re: Sensori BMP085 , DHT22 con systemd (Raspbian Jessie)

Messaggioda pluto21 » 23/03/2017, 21:01

Ciao, volevo chiedervi una cosa riguardo al sensore dht22 ,ho installato questo sensore seguendo la guida + tutte le correzioni , ho però un problema durante il giorno in alcuni momenti le letture di temp. e umidità vanno a zero, allego pagina di metern e il csv, questo problema c'è sia con letture ogni 5 min. e sia ogni 15 min. ,dimenticavo uso
raspian jessi 2.6a l'ultima versione di Flane che ringrazio ancora per la sua guida
Allegati
Cattura2.PNG
Cattura1.PNG
Impianto 2,88 Kw con 123solar e metern


turbuntux
Messaggi: 34
Iscritto il: 04/01/2018, 19:33

Re: Sensori BMP085 , DHT22 con systemd (Raspbian Jessie)

Messaggioda turbuntux » 20/01/2018, 23:14

seguo
Impianto 5kw - inverter ingecom 4.6TL 20 pannelli 250w 2 stringhe - orientamento SUD
Raspberry per il monitoraggio consumi produzione temperature varie con ds18b20.

pluto21
Messaggi: 12
Iscritto il: 29/11/2016, 21:31

Re: Sensori BMP085 , DHT22 con systemd (Raspbian Jessie)

Messaggioda pluto21 » 18/03/2020, 20:05

Ciao,
sto provando ad installare il sensore BMP180 , ma nel momento che eseguo il passaggio della guida " python setup.py install" ottengo questo errore
"/usr/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'long_description_content_type'
warnings.warn(msg)", la distribuzione è la Solarjessie , ma ho provato anche la Solarstretch , premetto che ho installato il sensore dht22 e funziona
bene .
Ringrazio chi può darmi un aiuto
Impianto 2,88 Kw con 123solar e metern

dolam
Messaggi: 222
Iscritto il: 15/08/2016, 23:08

Re: Sensori BMP085 , DHT22 con systemd (Raspbian Jessie)

Messaggioda dolam » 16/04/2020, 20:07

@dottorniù potresti indicarmi cortesemente il thread di amorospo che hai citato qui:
"Non ricordavo più il thread di amorospo in cui elencava quello ed altri errori trovati nella guida"

Grazie

carest
Messaggi: 62
Iscritto il: 08/11/2018, 22:09

Re: Sensori BMP085 , DHT22 con systemd (Raspbian Jessie)

Messaggioda carest » 21/08/2020, 17:46

Salve
dopo molto tempo
viewtopic.php?f=13&t=1850&hilit=sensori+dht22&start=50#p8090
sono riuscito ad installare il DHT22
Ho seguito la guida http://www.flanesi.it/doku/doku.php?id= ... vari_dht22 e ho avuto solo piccoli problemi:

1) sembra che i driver non si possano scaricare da git, o almeno io non ci sono riuscito (anticipato qui: viewtopic.php?f=4&t=2590&start=60#p10108) quindi ho risolto copiando a mano (direttamente dalla vecchia SD che avevo sostituito a metà aprile per un problema....) in: /home/pi il direttorio: "Adafruit_Python_DHT"

2) Il file /etc/cron.d/dht22 aveva dei meno che in realtà non lo erano e quindi non funzionavano; me ne sono accorto perché visualizzando il file apparivano caratteri strani, poi ho anche visto che era un problema già noto (viewtopic.php?f=13&t=1845&start=20#p3146). In realtà io ho copiato il testo dal PDF e non dalla guida on-line che ho citato prima, quindi non so se lì il problema è rimasto.

3) Purtroppo ho verificato anche che il DHT22 (e in misura inferiore anche il DS18B20) non sopporta cavi troppo lunghi... con cavi che hanno capacità di 350pF smette di funzionare a random, in pratica è instabile e non utilizzabile come monitoraggio. Con il cavo di rete di 7 metri che volevo utilizzare (capacità tipica di 50 pF/metro, ma anche collegando fili diversi che avevano capacità leggermente inferiori era sempre poco reattivo e spesso restituiva errori) che volevo utilizzare non sono riuscito... lo utilizzerò solo con il sensore di temperatura DS18B20, mentre terrò il DHT22 vicino al raspberry.


Torna a “Meters hardware”

Chi c’è in linea

Visitano il forum: Nessuno e 1 ospite