Commit 1b21d78e authored by Tom Hartley's avatar Tom Hartley

Merge pull request #6 from Nocturnal42/master

AirPi Config File
parents dc31a344 ea0a1b5a
[AirPi]
Watchdog = False
I2CBus = 0
LCD = True
Debug = True
NetRestart = True
NetRetries = 15
Frequency = 2
[Cosm]
Enabled = False
APIKEY = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
FEEDID = xxxxxx
[ADC]
ADC = MCP3008
MOSI = 23
MISO = 24
CLK = 18
CS = 25
[DHT22]
Enabled = True
DHTPin = 4
[BMP085]
Enabled = True
Altitude = 35
MSLP = True
[UVI-01]
Enabled = True
ADCPin = 4
[LDR]
Enabled = True
ADCPin = 0
[TGS2600]
Enabled = True
PullUp = 22000
ADCPin = 1
[MICS-2710]
Enabled = True
ADCPin = 2
PullUp = 10000
Resistance = 90000
[MICS-5525]
Enabled = True
ADCPin = 3
PullUp = 100000
Resistance = 190000
#!/usr/bin/python
from time import sleep
from sys import exit
import ConfigParser
import os.path
import datetime
import eeml
import eeml.datastream
......@@ -24,17 +27,29 @@ class DataPoint():
formatString = '{0:.' + str(self.decimals) + 'f}'
return formatString.format(self.value)
def mainUpload(stdscr):
WDOGON = 0
# Load the config file if it exists
if not os.path.isfile('AirPi.cfg'):
print "Unable to access config file : AirPi.cfg"
exit(1)
config = ConfigParser.ConfigParser()
print config.read('AirPi.cfg')
WDOGON = config.getboolean("AirPi", "Watchdog")
if WDOGON:
sleep(1)
wdog = os.open('/dev/watchdog',os.O_RDWR)
try:
bus = 0
LCDENABLED = 1
DEBUG = 1
LOGGER = 1
# Get basic options from config file
bus = config.getint("AirPi", "I2CBus")
LCDENABLED = config.getboolean("AirPi", "LCD")
DEBUG = config.getboolean("AirPi", "Debug")
LOGGER = config.getboolean("Cosm", "Enabled")
FREQUENCY = config.getint("AirPi", "Frequency")
NETRESTART = config.getboolean("AirPi", "NetRestart")
NETRETRIES = config.getint("AirPi", "NetRetries")
if LCDENABLED:
lcd = Adafruit_CharLCDPlate.Adafruit_CharLCDPlate(busnum=bus)
......@@ -50,39 +65,79 @@ def mainUpload(stdscr):
except:
pass
DHTPin = 4
if not DEBUG:
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(22,GPIO.OUT)
GPIO.setup(21,GPIO.OUT)
SPIMOSI = 23
SPIMISO = 24
SPICLK = 18
SPICS = 25
AQADC = 1
LightADC = 0
NO2ADC = 2
COADC = 3
UVADC = 4
dht = DHT22.DHT22(DHTPin)
bmp = BMP085.BMP085(bus=bus)
adc = MCP3008.MCP3008(SPIMOSI,SPIMISO,SPICLK,SPICS)
airSensor = AQSensor.AQSensor(adc,AQADC,pullup=22000)
lightSensor = LightSensor.LightSensor(adc,LightADC)
uvSensor = LightSensor.LightSensor(adc,UVADC)
no2Sensor = AQSensor.AQSensor(adc,NO2ADC,90000,10000)
coSensor = AQSensor.AQSensor(adc,COADC,190000,100000)
API_KEY = 'YOURAPIKEY'
FEED = 00000
# Get the ADC details from the config
SPIMOSI = config.getint("ADC", "MOSI")
SPIMISO = config.getint("ADC", "MISO")
SPICLK = config.getint("ADC", "CLK")
SPICS = config.getint("ADC", "CS")
adc = config.get("ADC", "ADC").lower()
if adc == 'mcp3008':
adc = MCP3008.MCP3008(SPIMOSI,SPIMISO,SPICLK,SPICS)
elif adc == 'mcp3208':
adc = MCP3208.MCP3208(SPIMOSI,SPIMISO,SPICLK,SPICS)
else:
print "You must specify a valid ADC in AirPi.cfg"
exit(1)
# Get the DHT22 details from the config
DHTEn = config.getboolean("DHT22", "Enabled")
if DHTEn:
DHTPin = config.getint("DHT22", "DHTPin")
dht = DHT22.DHT22(DHTPin)
# Get the BMP085 details from the config
BMPEn = config.getboolean("BMP085", "Enabled")
if BMPEn:
bmp = BMP085.BMP085(bus=bus)
BMPMSLP = config.getboolean("BMP085", "MSLP")
BMPALT = config.getint("BMP085", "Altitude")
# Get the UVI-01 details from the config
UVIEn = config.getboolean("UVI-01", "Enabled")
if UVIEn:
UVADC = config.getint("UVI-01", "ADCPin")
uvSensor = LightSensor.LightSensor(adc,UVADC)
# Get the LDR details from the config
LDREn = config.getboolean("LDR", "Enabled")
if LDREn:
LightADC = config.getint("LDR", "ADCPin")
lightSensor = LightSensor.LightSensor(adc,LightADC)
# Get the TGS2600 details from the config
TGSEn = config.getboolean("TGS2600", "Enabled")
if TGSEn:
AQADC = config.getint("TGS2600", "ADCPin")
pullup = config.getint("TGS2600", "PullUp")
airSensor = AQSensor.AQSensor(adc,AQADC,pullup)
# Get the MICS-2710 details from the config
NO2En = config.getboolean("MICS-2710", "Enabled")
if NO2En:
NO2ADC = config.getint("MICS-2710", "ADCPin")
pullup = config.getint("MICS-2710", "PullUp")
resist = config.getint("MICS-2710", "Resistance")
no2Sensor = AQSensor.AQSensor(adc,NO2ADC,resist,pullup)
# Get the MICS-5525 details from the config
COEn = config.getboolean("MICS-5525", "Enabled")
if COEn:
COADC = config.getint("MICS-5525", "ADCPin")
pullup = config.getint("MICS-5525", "PullUp")
resist = config.getint("MICS-5525", "Resistance")
coSensor = AQSensor.AQSensor(adc,COADC,resist,pullup)
API_URL = '/v2/feeds/{feednum}.xml' .format(feednum=FEED)
if LOGGER:
API_KEY = config.get("Cosm", "APIKEY", 1)
FEED = config.getint("Cosm", "FEEDID")
API_URL = '/v2/feeds/{feednum}.xml' .format(feednum=FEED)
failCount = 0
currentDisplay = 0
......@@ -91,21 +146,31 @@ def mainUpload(stdscr):
if WDOGON:
os.write(wdog,"0")
datas = []
dht.get_data()
d = DataPoint(dht.temp(),"Temp-DHT","C",1,-1)
if d.value != False:
datas.append(d)
datas.append(DataPoint(dht.humidity(),"Humidity","%",1,1,"Humidity"))
datas.append(DataPoint(airSensor.get_quality(),"Air Quality"," ",2,2,"AQ"))
datas.append(DataPoint(lightSensor.get_light_level(),"Light Level","Lux",2,3,"Light"))
datas.append(DataPoint(uvSensor.get_uv_level(),"UV Level","UVI",2,9,"UV"))
datas.append(DataPoint(bmp.readTemperature(),"Temp-BMP","C",1,0,"Temp"))
datas.append(DataPoint(bmp.readPressure(),"Pressure","Pa",1,4,"Pres"))
datas.append(DataPoint(bmp.readAltitude(),"Altitude","m",1,-1))
datas.append(DataPoint(no2Sensor.get_NO2(),"NO2","ppm",3,6,"NO2"))
datas.append(DataPoint(coSensor.get_CO(),"CO","ppm",3,5,"CO"))
datas.append(DataPoint(no2Sensor.get_quality(),"NO2 ohms","ohms",1,8))
datas.append(DataPoint(coSensor.get_quality(),"CO ohms","ohms",1,7))
if DHTEn:
dht.get_data()
d = DataPoint(dht.temp(),"Temp-DHT","C",1,-1)
if d.value != False:
datas.append(d)
datas.append(DataPoint(dht.humidity(),"Humidity","%",1,1,"Humidity"))
if TGSEn:
datas.append(DataPoint(airSensor.get_quality(),"Air Quality"," ",2,2,"AQ"))
if LDREn:
datas.append(DataPoint(lightSensor.get_light_level(),"Light Level","Lux",2,3,"Light"))
if UVIEn:
datas.append(DataPoint(uvSensor.get_uv_level(),"UV Level","UVI",2,9,"UV"))
if BMPEn:
datas.append(DataPoint(bmp.readTemperature(),"Temp-BMP","C",1,0,"Temp"))
if BMPMSLP:
datas.append(DataPoint(bmp.readMSLPressure(BMPALT),"Pressure","Pa",1,4,"Pres"))
else:
datas.append(DataPoint(bmp.readPressure(),"Pressure","Pa",1,4,"Pres"))
datas.append(DataPoint(bmp.readAltitude(),"Altitude","m",1,-1))
if NO2En:
datas.append(DataPoint(no2Sensor.get_NO2(),"NO2","ppm",3,6,"NO2"))
datas.append(DataPoint(no2Sensor.get_quality(),"NO2 ohms","ohms",1,8))
if COEn:
datas.append(DataPoint(coSensor.get_CO(),"CO","ppm",3,5,"CO"))
datas.append(DataPoint(coSensor.get_quality(),"CO ohms","ohms",1,7))
if DEBUG and (stdscr == None):
for dp in datas:
print dp.name + ":\t" + dp.roundedValue() + " " + dp.unit
......@@ -138,10 +203,11 @@ def mainUpload(stdscr):
if LCDENABLED:
lcd.backlight(lcd.ON)
print "Unable to upload data at " + str(datetime.datetime.now()) + ". Check your connection?"
failCount+=1
if failCount>15:
subprocess.Popen(["sudo", "/etc/init.d/networking", "restart"])
failCount=0
if NETRESTART:
failCount+=1
if failCount>NETRETRIES:
subprocess.Popen(["sudo", "/etc/init.d/networking", "restart"])
failCount=0
if LCDENABLED:
usedValues = []
......@@ -152,7 +218,7 @@ def mainUpload(stdscr):
data2 = usedValues[currentDisplay*2 + 1]
lcd.clear()
lcd.message(data1.sName + ": " + data1.roundedValue() + " " + data1.unit + "\n" + data2.sName + ": " + data2.roundedValue() + " " + data2.unit)
sleep(1.5)
sleep(FREQUENCY-1)
GPIO.output(22, False)
GPIO.output(21, False)
currentDisplay+=1
......
#!/usr/bin/python
#!/usr/bin/python
import time
import math
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment