Hello! I have stumbled upon this special dashboard through a reddit post. I currently have an environmental monitor project that integrates the Raspberry Pi Sense HAT and the UPS Pico. The Sense hat is a multi purpose sensor that is mainly used to pick up the temperature for my project and the UPS Pico serves as a backup battery incase of a power outage. I have integrated the sensor data on both the UPS Pico and Sense HAT into the Initial State platform but would like to switch over to Cayenne.
If youβre interested in looking my code it is down below:
from sense_hat import SenseHat
from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText
from ISStreamer.Streamer import Streamer
import RPi.GPIO as GPIO
import time
import sys
import datetime
import smbus
import smtplib
import urllib2
i2c = smbus.SMBus(1)
--------- User Settings ---------
CITY = βHamiltonβ
BUCKET_NAME = β " + CITY + " Weatherβ
BUCKET_KEY = βsense-hatβ
ACCESS_KEY = " "
SENSOR_LOCATION_NAME = " "
MINUTES_BETWEEN_SENSEHAT_READS = 0.05
---------------------------------
streamer = Streamer(bucket_name=BUCKET_NAME, bucket_key=BUCKET_KEY, access_key=ACCESS_KEY)
sense = SenseHat()
sense.clear()
red = (255, 0, 0)
green = (0, 255, 0)
orange = (255, 128, 0)
r = red
g = green
o = orange
red_pixels = [
r, r, r, r, r, r, r, r,
r, r, r, r, r, r, r, r,
r, r, r, r, r, r, r, r,
r, r, r, r, r, r, r, r,
r, r, r, r, r, r, r, r,
r, r, r, r, r, r, r, r,
r, r, r, r, r, r, r, r,
r, r, r, r, r, r, r, r
]
orange_pixels = [
o, o, o, o, o, o, o, o,
o, o, o, o, o, o, o, o,
o, o, o, o, o, o, o, o,
o, o, o, o, o, o, o, o,
o, o, o, o, o, o, o, o,
o, o, o, o, o, o, o, o,
o, o, o, o, o, o, o, o,
o, o, o, o, o, o, o, o
]
green_pixels = [
g, g, g, g, g, g, g, g,
g, g, g, g, g, g, g, g,
g, g, g, g, g, g, g, g,
g, g, g, g, g, g, g, g,
g, g, g, g, g, g, g, g,
g, g, g, g, g, g, g, g,
g, g, g, g, g, g, g, g,
g, g, g, g, g, g, g, g
]
def send_temp_trigger():
EVENT = βVERY_HOTβ
BASE_URL = βWebhooks works better with IFTTTβ
KEY = β β
response = urllib2.urlopen(
BASE_URL + EVENT + β/with/key/β + KEY)
print(response.read())
def bat_level():
time.sleep(0.1)
data = i2c.read_word_data(0x69, 0x01)
data = format(data,β02xβ)
return (float(data) / 100)
def pwr_mode():
data = i2c.read_byte_data(0x69, 0x00)
data = data & ~(1 << 7)
if (data == 1):
return β1 Fully Poweredβ #Power mode on RPi
elif (data == 2):
return β2 Backup Batteryβ #Power mode on Battery
else:
return β0 Error!β #Error
def rpi_level():
time.sleep(0.1)
data = i2c.read_word_data(0x69, 0x03)
data = format(data,β02xβ)
return (float(data) / 100)
def sot23_temp():
time.sleep(0.1)
data = i2c.read_byte_data(0x69, 0x0C)
data = format(data,β02xβ)
return data
def getBatteryPercentage():
time.sleep(0.1)
dataVolts = bat_level()
dataLevel = ((dataVolts-3.4)/0.8)*100
return dataLevel
while True:
#humidity sensor will change color dynamically according to different values
temp = sense.temp
calctemp = 0.0071temptemp+0.86*temp-11.0
if calctemp <= 21:
sense.set_pixels(green_pixels)
elif calctemp <= 23:
sense.set_pixels(orange_pixels)
else:
sense.set_pixels(red_pixels)
Read the sensors
temp_c = sense.get_temperature()
humidity = sense.get_humidity()
pressure_mb = sense.get_pressure()
battery_level = bat_level()
power_mode = pwr_mode()
raspberryPi_level = rpi_level()
UPS_Pico_temp = sot23_temp()
UPS_BAT_PERCENT = getBatteryPercentage()
Format the data
calctemp = float(β{0:.1f}β.format(calctemp))
humidity = float(β{0:.2f}β.format(humidity))
pressure_mb = float(β{0:.2f}β.format(pressure_mb))
battery_level = float(β{0:.1f}β.format(battery_level))
raspberryPi_level = float(β{0:.1f}β.format(raspberryPi_level))
UPS_BAT_PERCENT = float(β{0:.1f}β.format(UPS_BAT_PERCENT))
Print and stream
print " "
print " Weather Monitor Status"
print β"
print SENSOR_LOCATION_NAME + " Temperature(C): " + str(calctemp)
print SENSOR_LOCATION_NAME + " Humidity(%): " + str(humidity)
print SENSOR_LOCATION_NAME + " Pressure(IN): " + str(pressure_mb)
print SENSOR_LOCATION_NAME + " Battery(V): " + str(battery_level)
print SENSOR_LOCATION_NAME + " Power Mode(M): " + str(power_mode)
print SENSOR_LOCATION_NAME + " Raspberry Pi(V): " + str(raspberryPi_level)
print SENSOR_LOCATION_NAME + " UPS Pico Temperature(C): " + str(UPS_Pico_temp)
print SENSOR_LOCATION_NAME + " UPS Pico Battery Level(%): " + str(UPS_BAT_PERCENT)
print "β
print " "
streamer.log(β " + SENSOR_LOCATION_NAME + " Temperature(C)β, calctemp)
streamer.log(β " + SENSOR_LOCATION_NAME + " Humidity(%)β, humidity)
streamer.log(β " + SENSOR_LOCATION_NAME + " Pressure(IN)β, pressure_mb)
streamer.log(β " + SENSOR_LOCATION_NAME + " Battery(V)β, battery_level)
streamer.log(β " + SENSOR_LOCATION_NAME + " Power Mode(M)β, power_mode)
streamer.log(β " + SENSOR_LOCATION_NAME + " Raspberry Pi(V)β, raspberryPi_level)
streamer.log(β " + SENSOR_LOCATION_NAME + " UPS Pico Temperature(C)β, UPS_Pico_temp)
streamer.log(" " + SENSOR_LOCATION_NAME + " UPS Pico Battery Level(%): ", UPS_BAT_PERCENT)
streamer.flush()
time.sleep(60*MINUTES_BETWEEN_SENSEHAT_READS)