def main(): global lastRecTime if lastRecTime == None: if os.path.isfile(PWSHome + '/LastRecTime.pkl'): lastRecTime = pickle.load(open(PWSHome + '/LastRecTime.pkl', 'rb')) else: lastRecTime = 0 outData = allGetSQL.dataGrab() rawrectime = outData[12] if rawrectime > lastRecTime: # logger.info('This record is new: ' + str(rawrectime)) inchRain = allGetSQL.inchRainGrab() inchRain = "{:.2f}".format(inchRain) recTime = outData[0] pressure = outData[1] pressNA = "{:.2f}".format(0.0295300 * pressure) outTemp = "{:.1f}".format(outData[2]) outHum = int(outData[4]) outHumidity = str(outHum) windSpeed = "{:.1f}".format(outData[5]) windGust = "{:.1f}".format(outData[17]) winddir = str(outData[6]) rawRecTime = outData[12] rain = str(outData[13]) if outData[13] > 0: logger.info('rain: ' + rain + ' | inchRain: ' + inchRain) url = config.get('PWS_Service', 'Service_URL') PID = config.get('PWS_Service', 'PWSID') PPW = config.get('PWS_Service', 'PWSPassword') softwaretype = 'custom_python' recordTime = time.strftime("%Y-%m-%d+%H:%M:%S", time.gmtime(rawRecTime)) data_string = str(url + '?ID=' + PID + '&PASSWORD='******'&dateutc=' + recordTime + '&winddir=' + winddir + '&windspeedmph=' + windSpeed + '&windgustmph=' + windGust + '&tempf=' + outTemp + '&baromin=' + pressNA + '&humidity=' + outHumidity + '&dailyrainin=' + inchRain + '&softwaretype=' + softwaretype + '&action=updateraw') # data_string = str(url+'?ID='+PID+'&PASSWORD='******'&dateutc='+recordTime+'&winddir='+winddir+'&windspeedmph='+windSpeed+'&tempf='+outTemp+'&baromin='+pressNA+'&humidity='+outHumidity+'&softwaretype='+softwaretype+'&action=updateraw') # logger.info(data_string) try: with request.urlopen(data_string) as response: gotBack = response.read() if b'posted' in gotBack: resp = 'Data logged and posted.' else: resp = 'Data NOT logged and posted.' if float(rain) > 0: logger.info(resp) # logger.info(resp) except urllib.error.URLError as e: ResponseData = e.reason logger.info('Error: ' + str(ResponseData)) pass lastRecTime = rawrectime pickle.dump(lastRecTime, open(PWSHome + '/LastRecTime.pkl', 'wb+'), pickle.HIGHEST_PROTOCOL) sleep(10)
def main(): global mainTD # Retrieve previous state settings from the .pkl file made by loadStatus = pickle.load( open(allAppHome + '/CurrentStatus.pkl', 'rb')) # this .pkl has pin status data in it. recStat = str( loadStatus[1] ['state']) # Was recording left on when main.html was last seen? ohdSBP = str( loadStatus[2] ['state']) # Was ohdSoftBypass left on when main.html was last seen? outData = allGetSQL.dataGrab() # Grab the bulk of the current data inchRain = allGetSQL.inchRainGrab() shopTemp, shopHumidity, shopCPU = allGetSQL.shopDataGrab() recTime = outData[0] outTemp = outData[2] wsM = outData[5] windDir = outData[7] outHumidity = outData[4] rainRate = outData[14] presTrend = outData[15] humTrend = outData[16] poolTempIn, poolTempOut = allGetSQL.poolDataGrab(0) # Put our variables into the template data dictionary: templateData = { 'recTime': recTime, 'outTemp': outTemp, 'outHumidity': outHumidity, 'wsM': wsM, 'windDir': windDir, 'inchRain': inchRain, 'poolTempIn': poolTempIn, 'poolTempOut': poolTempOut, 'shopTemp': shopTemp, 'shopHumidity': shopHumidity, 'shopCPU': shopCPU, 'rainRate': rainRate, 'presTrend': presTrend, 'humTrend': humTrend, 'recStat': recStat, 'ohdSBP': ohdSBP } mainTD = templateData # Pass the template data into the template main.html and show it to the user return render_template('main.html', **templateData)
def outstats(): recTime, pressure, outTemp, outTempC, outHumidity, windSpeed, winddir, wdirStr, extraHumid1, cpuTemp, recNum, fan1, rawRecTime, rain, rainRate, presTrend, humTrend = allGetSQL.dataGrab( ) inchRain = allGetSQL.inchRainGrab() #fanSpd = pickle.load(open(outHome + '/fanSpd.pkl', 'rb')) pressNA = 0.0295300 * pressure # Put it into the template data dictionary: templateData = { 'bmpTempC': outTempC, 'bmpTempF': outTemp, 'bmpPressRaw': pressure, 'bmpPressNA': pressNA, # NA stands for North America, fyi. 'bmpHumid': outHumidity, 'bmpPreHum': extraHumid1, 'windDir': wdirStr, 'windDeg': winddir, 'wsM': windSpeed, 'inchRain': inchRain, 'rainRate': rainRate, 'presTrend': presTrend, 'humTrend': humTrend, 'cpuTemp': cpuTemp, # 'fanSpd' : fanSpd, 'recNum': recNum, 'fan1': fan1, 'capTime': recTime } # # Pass the template data into the template outStats.html and return it to the user return render_template('outStats.html', **templateData)