Use hue as temp sensor
This commit is contained in:
parent
f5eaa0603b
commit
921bcc56e5
1 changed files with 41 additions and 25 deletions
|
@ -10,14 +10,17 @@ from board import SCK, MOSI, MISO, D8, D24, D23, D18
|
||||||
from adafruit_rgb_display import color565
|
from adafruit_rgb_display import color565
|
||||||
import adafruit_rgb_display.ili9341 as ili9341
|
import adafruit_rgb_display.ili9341 as ili9341
|
||||||
|
|
||||||
from raspyrfm import *
|
#from raspyrfm import *
|
||||||
import sensors
|
#import sensors
|
||||||
from sensors import rawsensor
|
#from sensors import rawsensor
|
||||||
import sys
|
import sys
|
||||||
import threading
|
import threading
|
||||||
|
|
||||||
from PIL import Image, ImageDraw, ImageFont, ImageColor
|
from PIL import Image, ImageDraw, ImageFont, ImageColor
|
||||||
|
|
||||||
|
import requests
|
||||||
|
|
||||||
|
|
||||||
class TextBox:
|
class TextBox:
|
||||||
def __init__(self, pos, size, max_jitter, color, background, fitting_text):
|
def __init__(self, pos, size, max_jitter, color, background, fitting_text):
|
||||||
self.color = color
|
self.color = color
|
||||||
|
@ -91,22 +94,22 @@ backlight.direction = digitalio.Direction.OUTPUT
|
||||||
backlight.value = True
|
backlight.value = True
|
||||||
|
|
||||||
|
|
||||||
if raspyrfm_test(5, RFM69):
|
#if raspyrfm_test(5, RFM69):
|
||||||
print("Found RaspyRFM mod")
|
# print("Found RaspyRFM mod")
|
||||||
rfm = RaspyRFM(5, RFM69) #when using the RaspyRFM twin
|
# rfm = RaspyRFM(5, RFM69) #when using the RaspyRFM twin
|
||||||
else:
|
#else:
|
||||||
print("No RFM69 module found!")
|
# print("No RFM69 module found!")
|
||||||
exit()
|
# exit()
|
||||||
|
|
||||||
rfm.set_params(
|
#rfm.set_params(
|
||||||
Freq = 868.30, #MHz center frequency
|
# Freq = 868.30, #MHz center frequency
|
||||||
Datarate = 17.241, #kbit/s baudrate
|
# Datarate = 17.241, #kbit/s baudrate
|
||||||
ModulationType = rfm69.FSK, #modulation
|
# ModulationType = rfm69.FSK, #modulation
|
||||||
Deviation = 30, #kHz frequency deviation
|
# Deviation = 30, #kHz frequency deviation
|
||||||
SyncPattern = [0x2d, 0xd4], #syncword
|
# SyncPattern = [0x2d, 0xd4], #syncword
|
||||||
Bandwidth = 150, #kHz bandwidth
|
# Bandwidth = 150, #kHz bandwidth
|
||||||
RssiThresh = -105, #dBm RSSI threshold
|
# RssiThresh = -105, #dBm RSSI threshold
|
||||||
)
|
#)
|
||||||
|
|
||||||
|
|
||||||
mean_temp = 0
|
mean_temp = 0
|
||||||
|
@ -127,10 +130,16 @@ def update_temp():
|
||||||
if temps:
|
if temps:
|
||||||
mean_temp = sum(temps) / len(temps)
|
mean_temp = sum(temps) / len(temps)
|
||||||
|
|
||||||
|
def fetch_temp(bridge, user, sensor):
|
||||||
|
r=requests.get(f"http://{bridge}/api/{user}/sensors/{str(sensor)}")
|
||||||
|
if r:
|
||||||
|
return r.json()["state"]["temperature"]/100
|
||||||
|
return None
|
||||||
|
|
||||||
temp_thread = threading.Thread(target=update_temp, name="Temp Thread")
|
|
||||||
|
|
||||||
temp_thread.start()
|
#temp_thread = threading.Thread(target=update_temp, name="Temp Thread")
|
||||||
|
|
||||||
|
#temp_thread.start()
|
||||||
|
|
||||||
|
|
||||||
#display.vline(0,clock_box.size[1],1,color565(LINE_COLOR))
|
#display.vline(0,clock_box.size[1],1,color565(LINE_COLOR))
|
||||||
|
@ -147,7 +156,10 @@ old_temp=""
|
||||||
display.fill(color565(BKGND_COLOR))
|
display.fill(color565(BKGND_COLOR))
|
||||||
try:
|
try:
|
||||||
while True:
|
while True:
|
||||||
check_pixel = display.read((0,0)
|
cur_temp = fetch_temp("philips-hue", "GQ03rw1saUS0n88G5yj9j7-TsteFIE1yxtlBOgzD", 71)
|
||||||
|
if cur_temp:
|
||||||
|
mean_temp = cur_temp
|
||||||
|
|
||||||
#display.reset()
|
#display.reset()
|
||||||
#time.sleep(0.5)
|
#time.sleep(0.5)
|
||||||
|
|
||||||
|
@ -157,7 +169,11 @@ try:
|
||||||
time_str = time.strftime(CLOCK_FORMAT, now_parts)
|
time_str = time.strftime(CLOCK_FORMAT, now_parts)
|
||||||
temp_str = TEMP_FORMAT % mean_temp
|
temp_str = TEMP_FORMAT % mean_temp
|
||||||
|
|
||||||
if time_str != old_time:
|
# display.reset()
|
||||||
|
display.init()
|
||||||
|
# display.fill(color565(BKGND_COLOR))
|
||||||
|
|
||||||
|
if True: #time_str != old_time:
|
||||||
clock_box.draw_text(display, time_str, jitter_pos)
|
clock_box.draw_text(display, time_str, jitter_pos)
|
||||||
old_time = time_str
|
old_time = time_str
|
||||||
|
|
||||||
|
@ -168,7 +184,7 @@ try:
|
||||||
# backlight.duty_cycle = DAY_BRIGHT
|
# backlight.duty_cycle = DAY_BRIGHT
|
||||||
# else:
|
# else:
|
||||||
# backlight.duty_cycle = NIGHT_BRIGHT
|
# backlight.duty_cycle = NIGHT_BRIGHT
|
||||||
if temp_str != old_temp:
|
if True: #temp_str != old_temp:
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
temp_box.draw_text(display, temp_str, jitter_pos)
|
temp_box.draw_text(display, temp_str, jitter_pos)
|
||||||
old_temp = temp_str
|
old_temp = temp_str
|
||||||
|
@ -178,7 +194,7 @@ try:
|
||||||
|
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
clock_box.draw_text(display, "off" ,(0,0))
|
clock_box.draw_text(display, "off" ,(0,0))
|
||||||
temp_box.draw_text(display,"",(0,0))
|
# temp_box.draw_text(display,"",(0,0))
|
||||||
shutdown=True
|
shutdown=True
|
||||||
temp_thread.join()
|
# temp_thread.join()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue