-
Notifications
You must be signed in to change notification settings - Fork 0
/
batterytemperature.py
51 lines (34 loc) · 1.15 KB
/
batterytemperature.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# This program reads the temperature inside the Heat Battery (optional Pt100)
import board
import digitalio
import adafruit_max31865
spi = board.SPI()
cs = digitalio.DigitalInOut(board.D5) # Chip select of the MAX31865 board.
sensor = adafruit_max31865.MAX31865(spi, cs)
##import time # The time library is useful for delays
##import RPi.GPIO as GPIO
import mysql.connector
# Main program
def batterytemperature():
mydb = mysql.connector.connect(
host="localhost",
user="root",
password="raspberry",
database="HeatBatt"
)
mycursor = mydb.cursor()
#Read the temperature from the Pt100
# spi = board.SPI()
# cs = digitalio.DigitalInOut(board.D5) # Chip select of the MAX31865 board.
# sensor = adafruit_max31865.MAX31865(spi, cs)
# Read temperature.
temp = sensor.temperature
# Print the value.
#print("Temperature: {0:0.3f}C".format(temp))
temperaturestring=str("{0:0.3f}".format(temp))
#Write results in SQL
sqlstring = "UPDATE settings SET setting_value = '" + temperaturestring + "' WHERE setting_name = 'Battery_temperature'"
#print (sqlstring)
mycursor.execute(sqlstring)
mydb.commit()
mydb.close()