Skip to content

Commit

Permalink
Version 023
Browse files Browse the repository at this point in the history
  • Loading branch information
SwitchDoc Labs committed Mar 29, 2019
1 parent ab1e1e0 commit ae8a939
Show file tree
Hide file tree
Showing 9 changed files with 223 additions and 53 deletions.
66 changes: 66 additions & 0 deletions DustSensor.py
@@ -0,0 +1,66 @@
#!/usr/bin/env python

#SwithchDoc Labs September 2018
# Public Domain


# tests SDL_Pi_DustSensor Driver
import sys
sys.path.append('./SDL_Pi_DustSensor')
import time
import pigpio
import SDL_Pi_DustSensor


# Check for user imports
try:
import conflocal as config
except ImportError:
import config

import state

def read_AQI():

if (config.SWDEBUG):
print ("###############")
print ("Reading AQI")
print ("###############")

pi = pigpio.pi() # Connect to Pi.

dustSensor = SDL_Pi_DustSensor.SDL_Pi_DustSensor(pi, config.DustSensorPin) # set the GPIO pin number

# delay for 30 seconds for calibrated reading

time.sleep(30)

# get the gpio, ratio and concentration in particles / 0.01 ft3
g, r, c = dustSensor.read()

# concentration above 1,080,000 considered error
if (c>=1080000.00):
if (config.SWDEBUG):
print("Dust Sensor Concentration Error\n")

if (config.SWDEBUG):
print("Air Quality Measurements for PM2.5:")
print(" " + str(int(c)) + " particles/0.01ft^3")

# convert to SI units
concentration_ugm3=dustSensor.pcs_to_ugm3(c)
if (config.SWDEBUG):
print(" " + str(int(concentration_ugm3)) + " ugm^3")

# convert SI units to US AQI
# input should be 24 hour average of ugm3, not instantaneous reading
aqi=dustSensor.ugm3_to_aqi(concentration_ugm3)

if (config.SWDEBUG):
print(" Current AQI (not 24 hour avg): " + str(int(aqi)))
print("")

state.Outdoor_AirQuality_Sensor_Value = int(aqi)
pi.stop() # Disconnect from Pi.


2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -2,7 +2,7 @@ SkyWeather Libraries and Examples for Raspberry Pi Solar Powered Weather Station

Supports SwitchDoc Labs WeatherRack PiWeather Board

Version 1.21
Version V023

http://www.switchdoc.com/

Expand Down
1 change: 1 addition & 0 deletions SDL_Pi_DustSensor
Submodule SDL_Pi_DustSensor added at 8bfa9e
9 changes: 4 additions & 5 deletions SkyCamera.py
Expand Up @@ -79,7 +79,7 @@ def sendSkyPictureToWeatherStem():
def sendSkyWeather():

# defining the api-endpoint
API_ENDPOINT = "https://api.weatherstem.com/api/util"
API_ENDPOINT = "https://skyweather.weatherstem.com/"

# your API key here
API_KEY = "3gj8i0rm"
Expand All @@ -102,7 +102,6 @@ def sendSkyWeather():

data = {
"api_key":API_KEY,
"method": "social_sky_weather_upload",
"SkyWeatherVersion": config.SWVERSION,

"device":{
Expand Down Expand Up @@ -345,7 +344,7 @@ def sendSkyWeather():
"cameras":[
{
"name":"Sky Camera",
"image":"xxxyyyxxxencode64"
"image": encoded_string
}

]
Expand All @@ -355,11 +354,11 @@ def sendSkyWeather():

# sending post request and saving response as response object
r = requests.post(url = API_ENDPOINT, json = data)
print data
#print data
# extracting response text
pastebin_url = r.text
if (config.SWDEBUG):
print("The pastebin URL is:%s"%pastebin_url)
print("The pastebin URL is (r.text):%s"%pastebin_url)



Expand Down
65 changes: 20 additions & 45 deletions SkyWeather.py
Expand Up @@ -14,7 +14,7 @@
except ImportError:
import config

config.SWVERSION = "022"
config.SWVERSION = "023"


import sys
Expand Down Expand Up @@ -80,6 +80,8 @@

import SkyCamera

import DustSensor



################
Expand Down Expand Up @@ -442,35 +444,6 @@ def resetWXLink():
block1 = ""
block2 = ""

'''
###############
# Sunlight SI1145 Sensor Setup
################
# turn I2CBus 3 on
if (config.TCA9545_I2CMux_Present):
tca9545.write_control_register(TCA9545_CONFIG_BUS3)
try:
Sunlight_Sensor = SDL_Pi_SI1145.SDL_Pi_SI1145(indoor=0)
while (True):
visible = Sunlight_Sensor.readVisible()
print "visible=", visible
config.Sunlight_Present = True
vis = Sunlight_Sensor.readVisible()
IR = Sunlight_Sensor.readIR()
UV = Sunlight_Sensor.readUV()
IR_Lux = SI1145Lux.SI1145_IR_to_Lux(IR)
vis_Lux = SI1145Lux.SI1145_VIS_to_Lux(vis)
uvIndex = UV / 100.0
time.sleep(1.0)
except:
config.Sunlight_Present = False
'''

################
# DS3231/AT24C32 Setup
Expand Down Expand Up @@ -604,7 +577,8 @@ def process_as3935_interrupt():
updateBlynk.blynkStatusTerminalUpdate("Lightning Detected " + str(distance) + "km away.")

pclogging.log(pclogging.INFO, __name__, "Lightning Detected " + str(distance) + "km away. (%s)" % now)
sendemail.sendEmail("test", "GroveWeatherPi Lightning Detected\n", as3935LastStatus, config.textnotifyAddress, config.fromAddress, "");
if (config.enableText):
sendemail.sendEmail("test", config.STATIONID + " Lightning Detected\n", as3935LastStatus, config.textnotifyAddress, config.fromAddress, "");
# now set LED parameters
state.currentAs3935LastLightningTimeStamp = time.time()

Expand Down Expand Up @@ -636,9 +610,10 @@ def process_as3935_interrupt():

as3935 = RPi_AS3935(address=0x02, bus=1)

IndoorOutdoor = True # True means outdoor
try:

as3935.set_indoors(False)
as3935.set_indoors(IndoorOutdoor)
config.AS3935_Present = True
print "as3935 present at 0x02"
#process_as3935_interrupt()
Expand All @@ -651,7 +626,7 @@ def process_as3935_interrupt():

try:

as3935.set_indoors(False)
as3935.set_indoors(IndoorOutdoor)
config.AS3935_Present = True
#print "as3935 present"
except IOError as e:
Expand Down Expand Up @@ -985,7 +960,7 @@ def readWXLink(block1, block2):
# write SunAirPlus stats out to file
def writeSunAirPlusStats():

f = open("/home/pi/SDL_Pi_GroveWeatherPi/state/SunAirPlusStats.txt", "w")
f = open("/home/pi/SDL_Pi_SkyWeather/state/SunAirPlusStats.txt", "w")
f.write(str(batteryVoltage) + '\n')
f.write(str(batteryCurrent ) + '\n')
f.write(str(solarVoltage) + '\n')
Expand All @@ -1001,7 +976,7 @@ def writeSunAirPlusStats():
# write weather stats out to file
def writeWeatherStats():

f = open("/home/pi/SDL_Pi_GroveWeatherPi/state/WeatherStats.txt", "w")
f = open("/home/pi/SDL_Pi_SkyWeather/state/WeatherStats.txt", "w")
f.write(str(totalRain) + '\n')
f.write(str(as3935LightningCount) + '\n')
f.write(str(as3935LastInterrupt) + '\n')
Expand Down Expand Up @@ -1290,10 +1265,6 @@ def sampleWeather():
state.currentAltitude = bmp180Altitude
state.currentSeaLevel = bmp180SeaLevel

Indoor_AirQuality_Sensor_Value = 0
Outdoor_AirQuality_Sensor_Value = 0
state.Indoor_AirQuality_Sensor_Value = Indoor_AirQuality_Sensor_Value
state.Outdoor_AirQuality_Sensor_Value = Outdoor_AirQuality_Sensor_Value

# check for turn fan on
if (state.currentInsideTemperature > TEMPFANTURNON):
Expand Down Expand Up @@ -1592,7 +1563,7 @@ def patTheDog():
def shutdownPi(why):

pclogging.log(pclogging.INFO, __name__, "Pi Shutting Down: %s" % why)
sendemail.sendEmail("test", "GroveWeatherPi Shutting down:"+ why, "The GroveWeatherPi Raspberry Pi shutting down.", config.notifyAddress, config.fromAddress, "");
sendemail.sendEmail("test", "SkyWeather Shutting down:"+ why, "The SkyWeather Raspberry Pi shutting down.", config.notifyAddress, config.fromAddress, "");
sys.stdout.flush()
time.sleep(10.0)

Expand Down Expand Up @@ -1758,7 +1729,8 @@ def checkForButtons():
if ((state.runOLED == False) and (config.OLED_Originally_Present == True)):
reinitializeOLED = True

updateBlynk.blynkStatusUpdate()
if (config.USEBLYNK):
updateBlynk.blynkStatusUpdate()

if ((state.runOLED == True) and (reinitializeOLED == True)):
I2C_Lock.acquire()
Expand All @@ -1769,7 +1741,7 @@ def checkForButtons():


print ""
print "GroveWeatherPi Solar Powered Weather Station Version "+config.SWVERSION+" - SwitchDoc Labs"
print "SkyWeather Solar Powered Weather Station Version "+config.SWVERSION+" - SwitchDoc Labs"
print ""
print ""
print "Program Started at:"+ time.strftime("%Y-%m-%d %H:%M:%S")
Expand Down Expand Up @@ -1798,6 +1770,7 @@ def checkForButtons():
print returnStatusLine("SunAirPlus",config.SunAirPlus_Present)
print returnStatusLine("SI1145 Sun Sensor",config.Sunlight_Present)
print returnStatusLine("TSL2591 Sun Sensor",config.TSL2591_Present)
print returnStatusLine("DustSensor",config.DustSensor_Present)
print returnStatusLine("WXLink",config.WXLink_Present)
print
print returnStatusLine("UseBlynk",config.USEBLYNK)
Expand All @@ -1820,7 +1793,7 @@ def checkForButtons():

as3935Interrupt = False

pclogging.log(pclogging.INFO, __name__, "GroveWeatherPi Startup Version"+config.SWVERSION )
pclogging.log(pclogging.INFO, __name__, "SkyWeather Startup Version"+config.SWVERSION )

if (config.USEBLYNK):
updateBlynk.blynkEventUpdate("SW Startup Version "+config.SWVERSION)
Expand Down Expand Up @@ -1902,10 +1875,12 @@ def checkForButtons():
#check for Barometric Trend (every 15 minutes)
scheduler.add_job(barometricTrend, 'interval', seconds=15*60)


if (config.DustSensor_Present):
scheduler.add_job(DustSensor.read_AQI, 'interval', seconds=60*15)

# sky camera
if (config.Camera_Present):
scheduler.add_job(SkyCamera.takeSkyPicture, 'interval', seconds=60*15)
scheduler.add_job(SkyCamera.sendSkyWeather, 'interval', seconds=60*15)



Expand Down
8 changes: 6 additions & 2 deletions config.py
Expand Up @@ -4,7 +4,7 @@
# configuration file - contains customization for exact system
#

# it is a good idea to copy this file into a file called "conflocal.py" and edit that instead of this one. This file is wiped out if you update GroveWeatherPi.
# it is a good idea to copy this file into a file called "conflocal.py" and edit that instead of this one. This file is wiped out if you update SkyWeather.

SWDEBUG = False

Expand All @@ -22,14 +22,15 @@

fromAddress = "yourfromaddress@example.com"

enableText = False
textnotifyAddress = "yourphonenumber@yourprovider"

#MySQL Logging and Password Information

enable_MySQL_Logging = False
MySQL_Password = "password"

# modify this IP to enable WLAN operating detection - search for WLAN_check in GroveWeatherPi.py
# modify this IP to enable WLAN operating detection - search for WLAN_check in SkyWeather.py
enable_WLAN_Detection = True
PingableRouterAddress = "192.168.1.1"

Expand Down Expand Up @@ -92,6 +93,7 @@
WXLink_Present = False
Sunlight_Present = False
TSL2591_Present = False
DustSensor_Present = True

# set Sunlight High Gain (indoors - 1) or Low Gain (outdoors - 0)
Sunlight_Gain = 0
Expand All @@ -103,3 +105,5 @@

# Pin definitions
pixelPin = 21

DustSensorPin = 19
2 changes: 2 additions & 0 deletions state.py
Expand Up @@ -31,6 +31,7 @@

Indoor_AirQuality_Sensor_Value = 101
Outdoor_AirQuality_Sensor_Value = 101
Hour24_Outdoor_AirQuality_Sensor_Value = 101



Expand Down Expand Up @@ -117,6 +118,7 @@ def printState():
print "pastBarometricReading = ", pastBarometricReading

print "Outdoor_AirQuality_Sensor_Value = ", Outdoor_AirQuality_Sensor_Value
print "Hour24_Outdoor_AirQuality_Sensor_Value = ", Hour24_Outdoor_AirQuality_Sensor_Value
print "Indoor_AirQuality_Sensor_Value = ", Indoor_AirQuality_Sensor_Value

print "-------------"
Expand Down
Binary file modified static/skycamera.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit ae8a939

Please sign in to comment.