Black Lives Matter - Action and Equality. ... Adafruit is part of the Stop Hate for Profit campaign. Adafruit is open and shipping.
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 kamak on Mon Jun 25, 2018 8:39 pm

Hi, had a bit of time to do some googling, and have managed to get the google spreadsheet script kind of working using 'strftime' – this will format the date and time as a string which can be sent to google sheets (so not formatted as date / time, but ok for my purposes). Bear in mind that I've no real idea what I'm doing, I'm just hacking stuff together from google searches. No doubt there's a better solution than this.

Declare a couple of variables in the 'while' loop, at around line 114, and print them.
(You could use one variable, but better for my purposes to split the date from the time).

Code: Select all | TOGGLE FULL SIZE
    date_str = json.dumps(datetime.datetime.now().strftime("%Y-%m-%d"))
    time_str = json.dumps(datetime.datetime.now().strftime("%H:%M:%S"))
    print(date_str)
    print(time_str)

Then modify the 'append to worksheet' line, to include the variable(s) instead of datetime:

Code: Select all | TOGGLE FULL SIZE
       worksheet.append_row((date_str, time_str, temp, humidity))

Writes to google sheets ok.
Looks possible to modify the string(s) in google sheets after logging, so will be recognised as a date / time, but I've no need for it.

Cheers

kamak
 
Posts: 8
Joined: Mon Jun 04, 2018 6:36 am

Please be positive and constructive with your questions and comments.