0

DHT 22 Temperature and Humidity sensor with adafruit code
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Re: DHT 22 Temperature and Humidity sensor with adafruit cod

by TTemppi on Sun May 10, 2015 12:50 pm

ssdd1985 wrote:That's is same tutorial I followed. I only started a couple of days ago so I will of gotten the updated one. One think I will scrap and start for scratch keep thinking I must off missed something going over and over it.


Hi,
I have had the same problem as you after Oauth2 authentication was taken into use. Everything worked fine before that. Now I have once started from scratch and installed everything again as instructed. And also generated OAUTH2 credentials (json and all) few times without luck.
Every time I try to run the script I get that same message:

Logging sensor measurements to DHTLogger every 60 seconds.
Press Ctrl-C to quit.
Unable to login and get spreadsheet. Check OAuth credentials, spreadsheet name, and make sure spreadsheet is shared to the client_email address in the OAuth .json file!

So has someone really managed to get this to work, or should I start looking for some other solutions?

TTemppi
 
Posts: 1
Joined: Sun May 10, 2015 12:44 pm

Re: DHT 22 Temperature and Humidity sensor with adafruit cod

by ssdd1985 on Sun May 10, 2015 1:45 pm

TTemppi wrote:
ssdd1985 wrote:That's is same tutorial I followed. I only started a couple of days ago so I will of gotten the updated one. One think I will scrap and start for scratch keep thinking I must off missed something going over and over it.


Hi,
I have had the same problem as you after Oauth2 authentication was taken into use. Everything worked fine before that. Now I have once started from scratch and installed everything again as instructed. And also generated OAUTH2 credentials (json and all) few times without luck.
Every time I try to run the script I get that same message:

Logging sensor measurements to DHTLogger every 60 seconds.
Press Ctrl-C to quit.
Unable to login and get spreadsheet. Check OAuth credentials, spreadsheet name, and make sure spreadsheet is shared to the client_email address in the OAuth .json file!

So has someone really managed to get this to work, or should I start looking for some other solutions?



glad its not just me. was convinced i missed something.

ssdd1985
 
Posts: 3
Joined: Fri May 08, 2015 5:55 pm

Re: DHT 22 Temperature and Humidity sensor with adafruit cod

by tdicola on Mon May 11, 2015 1:56 am

You might try some of the suggestions here on the gspread library's github issues page: https://github.com/burnash/gspread/issues/224 Since Google changed the authentication system and deprecated username and password it looks like a lot of other folks are having problems too. I was able to make the system work by following all the steps written up in the guide, but it's tough to know if there's some other state with a google account that might be causing problems for other folks. Unfortunately I think the best option is to check out what other folks using the gspread library have tried to see if that can work for you too.

Another thing you might check out is using an intermediary service like Temboo to help access Google documents. Temboo can apparently take care of a lot of the authentication work for you (although from what I understand it still has to do some OAuth setup in Google's console). You might check it out to see if it helps. Good luck!

tdicola
 
Posts: 1074
Joined: Thu Oct 17, 2013 9:11 pm

Re: DHT 22 Temperature and Humidity sensor with adafruit cod

by BarraMaster on Tue May 19, 2015 9:13 am

I am having problems with the google sheets authentication process. I've been over the set up a number of times thinking I have missed something. (maybe I have) can any one help please.

Logging sensor measurements to Garden every 30 seconds.
Press Ctrl-C to quit.
Unable to login and get spreadsheet. Check OAuth credentials, spreadsheet name, and make sure spreadsheet is shared to the client_email address in the OAuth .json file!

BarraMaster
 
Posts: 1
Joined: Wed Feb 18, 2015 3:54 am

Re: DHT 22 Temperature and Humidity sensor with adafruit cod

by PatrikZk on Thu May 28, 2015 1:07 pm

tdicola wrote:You might try some of the suggestions here on the gspread library's github issues page: https://github.com/burnash/gspread/issues/224 Since Google changed the authentication system and deprecated username and password it looks like a lot of other folks are having problems too. I was able to make the system work by following all the steps written up in the guide, but it's tough to know if there's some other state with a google account that might be causing problems for other folks. Unfortunately I think the best option is to check out what other folks using the gspread library have tried to see if that can work for you too.

Another thing you might check out is using an intermediary service like Temboo to help access Google documents. Temboo can apparently take care of a lot of the authentication work for you (although from what I understand it still has to do some OAuth setup in Google's console). You might check it out to see if it helps. Good luck!


Hello, as first, I want to say, I'm 15 years old boy, who don't know complex things about this, well I don't know anything, so I'm really scared what to do. I tried things, which was described, but nothing works to me. My english is so horrible, that I don't even know if I'm saying right things so you can imagine how I'm translating the procedures and steps to myself. So get to the problem....I tried Temboo, but it was not success, well then I tried the GitHub "help" from the link. And then I get on other links and other etc., so I have confusion in my head now, really don't know what to do :( ...Is there any chance, that your team will do it easier ? Something like before ?

PatrikZk
 
Posts: 3
Joined: Thu May 28, 2015 12:42 pm

Re: DHT 22 Temperature and Humidity sensor with adafruit cod

by rikkert on Mon Jun 08, 2015 4:38 pm

Hello,

I'm having a problem with connecting mij Raspberry pi to google docs. I follwed the instructions on https://learn.adafruit.com/dht-humidity ... cs-updated but I cant get this thing working.

I get the reply:
Unable to login and get spreadsheet. Check OAuth credentials, spreadsheet name, and make sure spreadsheet is shared to the client_email address in the OAuth .json file!

Please give me a clue whats wrong with this file.

Thanks!!!!!!!!!

Rik
I changed some numbers so I won't get a lot of data from other people.

My json file is:
{
"private_key_id": "2ba34edb956c1e3dbc5c2b5d22755ecfd07b2422",
"private_key": "-----BEGIN PRIVATE KEY----\nMIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAKzeVu1Qje976BXL\n2kqdSF+4X5pjphwRzL+YC+Sf6kU5vKPJBxUZeF4HbXNr/ns39a2aTx+zA7MCJwjy\nVv1RxpbDMHy+wdcxv96KjhMJEstRXurTpaIWu6OsEzXWczIMUgQ10JAYfZcN3DNu\nuukQhTs+AEajf7AgHgGFRAe+9uvzAgMBAAECgYBCV2Wm15ZRBQ1RaBVTMz82NOzD\ntGBoP1CDateNmu1uObUyahDEwSyXcWRIunZEVXp8cE7TTIEr7rSKU26c8wgx7CFd\naNSkmoeMHYVU9uirIXsjZnsN5WuZGNBEY38qvaJBebtWPNGvZvFjVffb0gEQG/qZ\nKWkChNohxvkgPM1zoQJBANZ+4a2s7OWdwVWEjgisaMWiiaxoeXzl/UFP4s8RL93Z\n9je2yY/nMafsesP0YxdBRoOTLjvD6bL7BxMiRA9TXmMCQQDOUXGY8a7VLOL3CQap\nzghNMj98ki0LSh4cvaxWbHBoIVzyj2YZw7gCx4YGe2M8XQt8qnXQPBDfmQCFdj51\nzCkxAkBTh+H3Mqqm2QKbfR2a/xlmLeAThjQZka9IqgWXwge0C9e45rQkGFLcJFnC\nyf905PTC9KRCng76pougxe1fUoYlAkEAl+82HpFsVKQ3iABnnciSKHcmdZAYB8ZP\nIo8zSHmW1bgsAJxFbhfJfJJ+Smu3Co7ilK3bELwLGP5Nefs3x/vPIQJBAKZZ16zr\nHnG085JBOodaCFBJCf80cfhqeQSVPPrZGC3+cD5OweQwWoyMeCruDZgArH0dcwKA\nPGlcS8EzxIPN2yA\u003d\n-----END PRIVATE KEY-----\n",
"client_email": "437922248621-nvnf1r3k5pn9v0h16juk45avfn8e4ji1@developer.gserviceaccount.com",
"client_id": "537922248621-nvnf1r3k5pn9v0h16juk45avfn8e4ji1.apps.googleusercontent.com",
"type": "service_account"
}

The py script:
Code: Select all | TOGGLE FULL SIZE
#!/usr/bin/python

# Google Spreadsheet DHT Sensor Data-logging Example

# Depends on the 'gspread' and 'oauth2client' package being installed.  If you
# have pip installed execute:
#   sudo pip install gspread oauth2client

# 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,
# FITNES 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 json
import sys
import time
import datetime

import Adafruit_DHT
import gspread
from oauth2client.client import SignedJwtAssertionCredentials

# Type of sensor, can be Adafruit_DHT.DHT11, Adafruit_DHT.DHT22, or Adafruit_DHT.AM2302.
DHT_TYPE = Adafruit_DHT.DHT22

# Example of sensor connected to Raspberry Pi pin 23
DHT_PIN  = 23


# Google Docs OAuth credential JSON file.  Note that the process for authenticating
# with Google docs has changed as of ~April 2015.  You _must_ use OAuth2 to log
# in and authenticate with the gspread library.  Unfortunately this process is much
# more complicated than the old process.  You _must_ carefully follow the steps on
# this page to create a new OAuth service in your Google developer console:
#   http://gspread.readthedocs.org/en/latest/oauth2.html
#
# Once you've followed the steps above you should have downloaded a .json file with
# your OAuth2 credentials.  This file has a name like SpreadsheetData-<gibberish>.json.
# Place that file in the same directory as this python script.
#
# Now one last _very important_ step before updating the spreadsheet will work.
# Go to your spreadsheet in Google Spreadsheet and share it to the email address
# inside the 'client_email' setting in the SpreadsheetData-*.json file.  For example
# if the client_email setting inside the .json file has an email address like:
#   149345334675-md0qff5f0kib41meu20f7d1habos3qcu@developer.gserviceaccount.com
# Then use the File -> Share... command in the spreadsheet to share it with read
# and write acess to the email address above.  If you don't do this step then the
# updates to the sheet will fail!
GDOCS_OAUTH_JSON       = 'pcmkantoor-3ba34edb956c.json'

# Google Docs spreadsheet name.
GDOCS_SPREADSHEET_NAME = 'PCM'

# How long to wait (in seconds) between measurements.
FREQUENCY_SECONDS      = 30


def login_open_sheet(oauth_key_file, spreadsheet):
   """Connect to Google Docs spreadsheet and return the first worksheet."""
   try:
      json_key = json.load(open(oauth_key_file))
      credentials = SignedJwtAssertionCredentials(json_key['client_email'],
                                       json_key['private_key'],
                                       ['https://spreadsheets.google.com/feeds'])
      gc = gspread.authorize(credentials)
      worksheet = gc.open(spreadsheet).sheet1
      return worksheet
   except:
      print 'Unable to login and get spreadsheet.  Check OAuth credentials, spreadsheet name, and make sure spreadsheet is shared to the client_email address in the OAuth .json file!'
      sys.exit(1)


print 'Logging sensor measurements to {0} every {1} seconds.'.format(GDOCS_SPREADSHEET_NAME, FREQUENCY_SECONDS)
print 'Press Ctrl-C to quit.'
worksheet = None
while True:
   # Login if necessary.
   if worksheet is None:
      worksheet = login_open_sheet(GDOCS_OAUTH_JSON, GDOCS_SPREADSHEET_NAME)

   # Attempt to get sensor reading.
   humidity, temp = Adafruit_DHT.read(DHT_TYPE, DHT_PIN)

   # Skip to the next reading if a valid measurement couldn't be taken.
   # This might happen if the CPU is under a lot of load and the sensor
   # can't be reliably read (timing is critical to read the sensor).
   if humidity is None or temp is None:
      time.sleep(2)
      continue

   print 'Temperature: {0:0.1f} C'.format(temp)
   print 'Humidity:    {0:0.1f} %'.format(humidity)
 
   # Append the data in the spreadsheet, including a timestamp
   try:
      worksheet.append_row((datetime.datetime.now(), temp, humidity))
   except:
      # Error appending data, most likely because credentials are stale.
      # Null out the worksheet so a login is performed at the top of the loop.
      print 'Append error, logging in again'
      worksheet = None
      time.sleep(FREQUENCY_SECONDS)
      continue

   # Wait 30 seconds before continuing
   print 'Wrote a row to {0}'.format(GDOCS_SPREADSHEET_NAME)
   time.sleep(FREQUENCY_SECONDS)

rikkert
 
Posts: 3
Joined: Mon Jun 08, 2015 4:03 pm

Re: DHT 22 Temperature and Humidity sensor with adafruit cod

by adafruit_support_rick on Mon Jun 08, 2015 4:52 pm

Have a look at this post. It might help
viewtopic.php?f=19&t=72568&p=379377#p379252

adafruit_support_rick
 
Posts: 35012
Joined: Tue Mar 15, 2011 11:42 am
Location: Buffalo, NY

Re: DHT 22 Temperature and Humidity sensor with adafruit cod

by polskifacet on Thu Jun 11, 2015 11:39 am

Here is my line of code to show temp in F and humidity.
Code: Select all | TOGGLE FULL SIZE
print 'Temp: {0:0.1f}*F Humidity={1:0.1f}%'.format(temperature * (9.0/5.0) + 32, humidity)

polskifacet
 
Posts: 1
Joined: Thu Jun 11, 2015 11:33 am

Re: DHT 22 Temperature and Humidity sensor with adafruit cod

by gualo on Wed Nov 04, 2015 11:10 am

Hi,
I'm having trouble trying to read my recently acquired DHT22 on a Raspberry Pi 2.
I built the circuit as detailed in https://learn.adafruit.com/dht-humidity-sensing-on-raspberry-pi-with-gdocs-logging/wiring.
I installed the library from the adafruit/Adafruit_Python_DHT git repository.

When I run
Code: Select all | TOGGLE FULL SIZE
sudo ./AdafruitDHT.py 22 4
I always get the error message "Failed to get reading. Try again!"
I checked and rechecked everything many times so I'm sure the circuit is right.
I also tried using 7 as a pin number in case it works with the wiringPi system, but still nothing :-(

I tried it again using a 3 pin generic DHT11, same results.

Is there a way to check if the DHT22/DHT11 is functioning normally?

I've no clue as to what could be the problem.
Thanks for any help.

gualo
 
Posts: 3
Joined: Wed Nov 04, 2015 10:46 am

Re: DHT 22 Temperature and Humidity sensor with adafruit cod

by adafruit_support_rick on Thu Nov 05, 2015 4:23 am

Please post some pictures showing your soldering and wiring

adafruit_support_rick
 
Posts: 35012
Joined: Tue Mar 15, 2011 11:42 am
Location: Buffalo, NY

Re: DHT 22 Temperature and Humidity sensor with adafruit cod

by gualo on Thu Nov 05, 2015 6:38 am

Thanks for your fast reply.
I may have grilled the sensor when I modified the circuit "live" :-(
I ordered a new sensor just in case.
By the way, is there a direct way to check if the sensor is still OK?

In case that's not the issue, here is my circuit.

Image

gualo
 
Posts: 3
Joined: Wed Nov 04, 2015 10:46 am

Re: DHT 22 Temperature and Humidity sensor with adafruit cod

by mixmaestromark on Thu Nov 05, 2015 7:09 pm

Hi,
Thanks for the great project.

I am trying to get this to work on my BBB. I have the original Angstrom installation though, not Debian and I am struggling to get the Python library to install. I assume this is because I am not using the correct commands for Angstrom.

Obviously the debian commands...
sudo apt-get update
sudo apt-get install build-essential python-dev python-openssl

dont work.

I have tried replacing "sudo apt-get" with opkg, but I get the response "unknown package "build-essential"".

If someone could just point me in the direction of what I can read to find out what the correct commands for Angstrom are that would be appreciated.

Thanks.

mixmaestromark
 
Posts: 1
Joined: Thu Nov 05, 2015 6:51 pm

Re: DHT 22 Temperature and Humidity sensor with adafruit cod

by gualo on Fri Nov 06, 2015 11:15 am

gualo wrote:Thanks for your fast reply.
I may have grilled the sensor when I modified the circuit "live" :-(
I ordered a new sensor just in case.

Turns out it was a stupid connection error related to my new breadboard, my bad, sorry, now I get the readings :-)

Thanks for your help.

gualo
 
Posts: 3
Joined: Wed Nov 04, 2015 10:46 am

Re: DHT 22 Temperature and Humidity sensor with adafruit cod

by tdicola on Mon Nov 09, 2015 2:56 am

mixmaestromark wrote:Hi,
Thanks for the great project.

I am trying to get this to work on my BBB. I have the original Angstrom installation though, not Debian and I am struggling to get the Python library to install. I assume this is because I am not using the correct commands for Angstrom.

Obviously the debian commands...
sudo apt-get update
sudo apt-get install build-essential python-dev python-openssl

dont work.

I have tried replacing "sudo apt-get" with opkg, but I get the response "unknown package "build-essential"".

If someone could just point me in the direction of what I can read to find out what the correct commands for Angstrom are that would be appreciated.

Thanks.


Ah yeah the guides are really written to use the Debian OS for the BBB. They switched over to Debian as the recommended OS for the board so you'll have a lot more luck using it--try grabbing the latest Debian image from here: http://beagleboard.org/latest-images

For the errors you're hitting the Angstrom OS doesn't use the apt package manager. Instead it uses opkg, but the packages it has are probably different or maybe don't even exist compared to Debian. Those instructions are installing the GCC compiler suite and python development headers. You might search around with 'opkg list' command to see all the available packages. However grabbing and installing the Debian image above should work with the guide and make things a lot easier.

tdicola
 
Posts: 1074
Joined: Thu Oct 17, 2013 9:11 pm

Re: DHT 22 Temperature and Humidity sensor with adafruit cod

by rfeyer on Sat Jan 30, 2016 8:20 am

What a great tutorial - it certainly worked, TY!

I do have a question: using the Adafruit_DHT module, one has to use SUDO to run a .py or .sh.

However, this is giving me problems since it then can not automatically start when the RPi for some reason has to reboot.
Is there any way to have the modules loaded on reboot so the .py program can be started automatically?
Rainer

rfeyer
 
Posts: 1
Joined: Sat Jan 30, 2016 8:18 am

Please be positive and constructive with your questions and comments.