add code for sensor logging
This commit is contained in:
parent
c45434006e
commit
8cfe0bbe52
2 changed files with 66 additions and 0 deletions
32
Google_Sheet_Sensor_Logging/bme280_logger.py
Executable file
32
Google_Sheet_Sensor_Logging/bme280_logger.py
Executable file
|
|
@ -0,0 +1,32 @@
|
||||||
|
import time
|
||||||
|
from datetime import datetime
|
||||||
|
import board
|
||||||
|
import adafruit_bme280
|
||||||
|
from google.oauth2.service_account import Credentials
|
||||||
|
from googleapiclient.discovery import build
|
||||||
|
|
||||||
|
#--| User Config |-----------------------------------------------
|
||||||
|
SERVICE_ACCOUNT_FILE = 'YOUR_CREDENTIALS_FILE.json'
|
||||||
|
SPREADSHEET_ID = 'YOUR_SHEET_ID'
|
||||||
|
DATA_LOCATION = 'A1'
|
||||||
|
UPDATE_RATE = 60
|
||||||
|
#--| User Config |-----------------------------------------------
|
||||||
|
|
||||||
|
# Sensor setup
|
||||||
|
bme = adafruit_bme280.Adafruit_BME280_I2C(board.I2C())
|
||||||
|
|
||||||
|
# Google Sheets API setup
|
||||||
|
SCOPES = ['https://spreadsheets.google.com/feeds',
|
||||||
|
'https://www.googleapis.com/auth/drive']
|
||||||
|
CREDS = Credentials.from_service_account_file(SERVICE_ACCOUNT_FILE, scopes=SCOPES)
|
||||||
|
SHEET = build('sheets', 'v4', credentials=CREDS).spreadsheets()
|
||||||
|
|
||||||
|
# Logging loop
|
||||||
|
print("Logging...")
|
||||||
|
while True:
|
||||||
|
values = [[datetime.now().isoformat(), bme.pressure, bme.temperature, bme.humidity]]
|
||||||
|
SHEET.values().append(spreadsheetId=SPREADSHEET_ID,
|
||||||
|
valueInputOption='RAW',
|
||||||
|
range=DATA_LOCATION,
|
||||||
|
body={'values' : values}).execute()
|
||||||
|
time.sleep(UPDATE_RATE)
|
||||||
34
Google_Sheet_Sensor_Logging/max31855_logger.py
Executable file
34
Google_Sheet_Sensor_Logging/max31855_logger.py
Executable file
|
|
@ -0,0 +1,34 @@
|
||||||
|
import time
|
||||||
|
from datetime import datetime
|
||||||
|
import board
|
||||||
|
import digitalio
|
||||||
|
import adafruit_max31855
|
||||||
|
from google.oauth2.service_account import Credentials
|
||||||
|
from googleapiclient.discovery import build
|
||||||
|
|
||||||
|
#--| User Config |-----------------------------------------------
|
||||||
|
SERVICE_ACCOUNT_FILE = 'YOUR_CREDENTIALS_FILE.json'
|
||||||
|
SPREADSHEET_ID = 'YOUR_SHEET_ID'
|
||||||
|
DATA_LOCATION = 'A1'
|
||||||
|
UPDATE_RATE = 60
|
||||||
|
#--| User Config |-----------------------------------------------
|
||||||
|
|
||||||
|
# Sensor setup
|
||||||
|
cs = digitalio.DigitalInOut(board.C0)
|
||||||
|
max31855 = adafruit_max31855.MAX31855(board.SPI(), cs)
|
||||||
|
|
||||||
|
# Google Sheets API setup
|
||||||
|
SCOPES = ['https://spreadsheets.google.com/feeds',
|
||||||
|
'https://www.googleapis.com/auth/drive']
|
||||||
|
CREDS = Credentials.from_service_account_file(SERVICE_ACCOUNT_FILE, scopes=SCOPES)
|
||||||
|
SHEET = build('sheets', 'v4', credentials=CREDS).spreadsheets()
|
||||||
|
|
||||||
|
# Logging loop
|
||||||
|
print("Logging...")
|
||||||
|
while True:
|
||||||
|
values = [[datetime.now().isoformat(), max31855.temperature]]
|
||||||
|
SHEET.values().append(spreadsheetId=SPREADSHEET_ID,
|
||||||
|
valueInputOption='RAW',
|
||||||
|
range=DATA_LOCATION,
|
||||||
|
body={'values' : values}).execute()
|
||||||
|
time.sleep(UPDATE_RATE)
|
||||||
Loading…
Reference in a new issue