예제 #1
0
def blynkStateUpdate():

    try:
        put_header = {"Content-Type": "application/json"}

        # set last sample time

        put_header = {"Content-Type": "application/json"}
        val = time.strftime("%Y-%m-%d %H:%M:%S")
        put_body = json.dumps([val])
        if (DEBUGBLYNK):
            print "blynkEventUpdate:", val
        r = requests.put(config.BLYNK_URL + config.BLYNK_AUTH + '/update/V44',
                         data=put_body,
                         headers=put_header)
        if (DEBUGBLYNK):
            print "blynkEventUpdate:POST:r.status_code:", r.status_code

        # do the graphs

        val = state.AirQuality_Sensor_Value
        put_body = json.dumps([val])
        if (DEBUGBLYNK):
            print "blynkStateUpdate:Pre:put_body:", put_body
        r = requests.put(config.BLYNK_URL + config.BLYNK_AUTH + '/update/V7',
                         data=put_body,
                         headers=put_header)
        if (DEBUGBLYNK):
            print "blynkStateUpdate:POST:r.status_code:", r.status_code

        val = util.returnTemperatureCF(state.currentOutsideTemperature)
        tval = "{0:0.1f} ".format(val) + util.returnTemperatureCFUnit()
        put_body = json.dumps([tval])
        r = requests.put(config.BLYNK_URL + config.BLYNK_AUTH + '/update/V0',
                         data=put_body,
                         headers=put_header)

        val = util.returnTemperatureCF(state.currentOutsideTemperature)
        put_body = json.dumps([val])
        r = requests.put(config.BLYNK_URL + config.BLYNK_AUTH + '/update/V10',
                         data=put_body,
                         headers=put_header)

        val = state.currentOutsideHumidity
        put_body = json.dumps(["{0:0.1f}%".format(val)])
        r = requests.put(config.BLYNK_URL + config.BLYNK_AUTH + '/update/V1',
                         data=put_body,
                         headers=put_header)

        val = state.currentOutsideHumidity
        put_body = json.dumps([val])
        r = requests.put(config.BLYNK_URL + config.BLYNK_AUTH + '/update/V11',
                         data=put_body,
                         headers=put_header)

        val = util.returnTemperatureCF(state.currentInsideTemperature)
        tval = "{0:0.1f} ".format(val) + util.returnTemperatureCFUnit()
        put_body = json.dumps([tval])
        r = requests.put(config.BLYNK_URL + config.BLYNK_AUTH + '/update/V21',
                         data=put_body,
                         headers=put_header)

        val = state.currentInsideHumidity
        put_body = json.dumps(["{0:0.1f}%".format(val)])
        r = requests.put(config.BLYNK_URL + config.BLYNK_AUTH + '/update/V13',
                         data=put_body,
                         headers=put_header)

        #wind
        val = util.returnWindSpeed(state.ScurrentWindSpeed)
        tval = "{0:0.1f}".format(val) + util.returnWindSpeedUnit()
        put_body = json.dumps([tval])
        r = requests.put(config.BLYNK_URL + config.BLYNK_AUTH + '/update/V9',
                         data=put_body,
                         headers=put_header)

        #wind
        val = util.returnWindSpeed(state.ScurrentWindSpeed)
        put_body = json.dumps([val])
        r = requests.put(config.BLYNK_URL + config.BLYNK_AUTH + '/update/V19',
                         data=put_body,
                         headers=put_header)

        #wind direction
        val = "{0:0.0f}/".format(
            state.ScurrentWindDirection) + util.returnWindDirection(
                state.ScurrentWindDirection)
        put_body = json.dumps([val])
        r = requests.put(config.BLYNK_URL + config.BLYNK_AUTH + '/update/V2',
                         data=put_body,
                         headers=put_header)

        #rain
        val = "{0:0.2f}".format(state.currentTotalRain)
        if (state.EnglishMetric == 1):
            tval = "{0:0.2f}mm".format(state.currentTotalRain)
        else:
            tval = "{0:0.2f}in".format(state.currentTotalRain / 25.4)
        put_body = json.dumps([tval])
        r = requests.put(config.BLYNK_URL + config.BLYNK_AUTH + '/update/V3',
                         data=put_body,
                         headers=put_header)

        #Sunlight
        val = "{0:0.0f}".format(state.currentSunlightVisible)
        put_body = json.dumps([val])
        r = requests.put(config.BLYNK_URL + config.BLYNK_AUTH + '/update/V4',
                         data=put_body,
                         headers=put_header)

        #barometric Pressure
        if (state.EnglishMetric == 1):
            tval = "{0:0.2f}KPa".format(state.currentBarometricPressure)
        else:
            tval = "{0:0.2f}in".format(state.currentSeaLevel * 0.2953)
        put_body = json.dumps([tval])
        r = requests.put(config.BLYNK_URL + config.BLYNK_AUTH + '/update/V40',
                         data=put_body,
                         headers=put_header)

        #barometric Pressure graph
        if (state.EnglishMetric == 1):
            tval = "{0:0.2f}".format(state.currentBarometricPressure)
        else:
            tval = "{0:0.2f}".format(state.currentSeaLevel * 0.2953)
        put_body = json.dumps([tval])
        r = requests.put(config.BLYNK_URL + config.BLYNK_AUTH + '/update/V41',
                         data=put_body,
                         headers=put_header)

        #solar data

        val = "{0:0.2f}".format(state.solarVoltage)
        put_body = json.dumps([val])
        r = requests.put(config.BLYNK_URL + config.BLYNK_AUTH + '/update/V50',
                         data=put_body,
                         headers=put_header)

        val = "{0:0.1f}".format(state.solarCurrent)
        put_body = json.dumps([val])
        r = requests.put(config.BLYNK_URL + config.BLYNK_AUTH + '/update/V51',
                         data=put_body,
                         headers=put_header)

        val = "{0:0.2f}".format(state.batteryVoltage)
        put_body = json.dumps([val])
        r = requests.put(config.BLYNK_URL + config.BLYNK_AUTH + '/update/V52',
                         data=put_body,
                         headers=put_header)

        val = "{0:0.1f}".format(state.batteryCurrent)
        put_body = json.dumps([val])
        r = requests.put(config.BLYNK_URL + config.BLYNK_AUTH + '/update/V53',
                         data=put_body,
                         headers=put_header)

        val = "{0:0.2f}".format(state.loadVoltage)
        put_body = json.dumps([val])
        r = requests.put(config.BLYNK_URL + config.BLYNK_AUTH + '/update/V54',
                         data=put_body,
                         headers=put_header)

        val = "{0:0.1f}".format(state.loadCurrent)
        put_body = json.dumps([val])
        r = requests.put(config.BLYNK_URL + config.BLYNK_AUTH + '/update/V55',
                         data=put_body,
                         headers=put_header)

        val = "{0:0.1f}W".format(state.batteryPower)
        put_body = json.dumps([val])
        r = requests.put(config.BLYNK_URL + config.BLYNK_AUTH + '/update/V60',
                         data=put_body,
                         headers=put_header)

        val = "{0:0.1f}W".format(state.solarPower)
        put_body = json.dumps([val])
        r = requests.put(config.BLYNK_URL + config.BLYNK_AUTH + '/update/V61',
                         data=put_body,
                         headers=put_header)

        val = "{0:0.1f}W".format(state.loadPower)
        put_body = json.dumps([val])
        r = requests.put(config.BLYNK_URL + config.BLYNK_AUTH + '/update/V62',
                         data=put_body,
                         headers=put_header)

        val = "{0:0.1f}%".format(state.batteryCharge)
        put_body = json.dumps([val])
        r = requests.put(config.BLYNK_URL + config.BLYNK_AUTH + '/update/V56',
                         data=put_body,
                         headers=put_header)

        # LEDs

        if (state.barometricTrend):  #True is up, False is down
            r = requests.get(config.BLYNK_URL + config.BLYNK_AUTH +
                             '/update/V42?color=%2300FF00')  # Green
            if (DEBUGBLYNK):
                print "blynkAlarmUpdate:OTHER:r.status_code:", r.status_code
        else:
            r = requests.get(config.BLYNK_URL + config.BLYNK_AUTH +
                             '/update/V42?color=%23FF0000')  # red

        if (state.currentAs3935LastLightningTimeStamp <
                time.clock() + 1800):  #True is lightning, False is none
            r = requests.get(config.BLYNK_URL + config.BLYNK_AUTH +
                             '/update/V43?color=%2300FF00')  # Green
            if (DEBUGBLYNK):
                print "blynkAlarmUpdate:OTHER:r.status_code:", r.status_code
        else:
            r = requests.get(config.BLYNK_URL + config.BLYNK_AUTH +
                             '/update/V43?color=%23FF0000')  # red

        return 1
    except Exception as e:
        print "exception in blynkStateUpdate"
        print(e)
        return 0
예제 #2
0
def takeSkyPicture():

    if (config.SWDEBUG):
        print("--------------------")
        print("SkyCam Picture Taken")
        print("--------------------")
    camera = picamera.PiCamera()

    camera.exposure_mode = "auto"
    try:
        camera.rotation = 180
        #camera.rotation = 270
        camera.resolution = (1920, 1080)
        # Camera warm-up time
        time.sleep(2)

        camera.capture('static/skycamera.jpg')

        # now add timestamp to jpeg
        pil_im = Image.open('static/skycamera.jpg')

        draw = ImageDraw.Draw(pil_im)

        # Choose a font
        font = ImageFont.truetype(
            "/usr/share/fonts/truetype/freefont/FreeSans.ttf", 25)

        # set up units
        #wind
        val = util.returnWindSpeed(state.ScurrentWindSpeed)
        WindStval = "{0:0.1f}".format(val) + util.returnWindSpeedUnit()
        val = util.returnWindSpeed(state.ScurrentWindGust)
        WindGtval = "{0:0.1f}".format(val) + util.returnWindSpeedUnit()
        val = util.returnTemperatureCF(state.currentOutsideTemperature)
        OTtval = "{0:0.1f} ".format(val) + util.returnTemperatureCFUnit()

        myText = "SkyWeather %s Wind Speed: %s Wind Gust: %s Temp: %s " % (
            dt.datetime.now().strftime('%d-%b-%Y %H:%M:%S'), WindStval,
            WindGtval, OTtval)

        # Draw the text
        color = 'rgb(255,255,255)'
        #draw.text((0, 0), myText,fill = color, font=font)

        # get text size
        text_size = font.getsize(myText)

        # set button size + 10px margins
        button_size = (text_size[0] + 20, text_size[1] + 10)

        # create image with correct size and black background
        button_img = Image.new('RGBA', button_size, "black")

        # put text on button with 10px margins
        button_draw = ImageDraw.Draw(button_img)
        button_draw.text((10, 5), myText, fill=color, font=font)

        # put button on source image in position (0, 0)

        pil_im.paste(button_img, (0, 0))
        bg_w, bg_h = pil_im.size
        # WeatherSTEM logo in lower left
        size = 64
        WSLimg = Image.open("static/WeatherSTEMLogoSkyBackground.png")
        WSLimg.thumbnail((size, size), Image.ANTIALIAS)
        pil_im.paste(WSLimg, (0, bg_h - size))

        # SkyWeather log in lower right
        SWLimg = Image.open("static/SkyWeatherLogoSymbol.png")
        SWLimg.thumbnail((size, size), Image.ANTIALIAS)
        pil_im.paste(SWLimg, (bg_w - size, bg_h - size))

        # Save the image
        pil_im.save('static/skycamera.jpg', format='JPEG')
        pil_im.save('static/skycameraprocessed.jpg', format='JPEG')

        time.sleep(2)

    except:
        if (config.SWDEBUG):
            print(traceback.format_exc())
            print("--------------------")
            print("SkyCam Picture Failed")
            print("--------------------")

    finally:
        try:
            camera.close()
        except:
            if (config.SWDEBUG):
                print("--------------------")
                print("SkyCam Close Failed ")
                print("--------------------")

    if (config.USEWEATHERSTEM == True):
        sendSkyWeather()
예제 #3
0
def takeSkyPicture():

    if (config.SWDEBUG):
        print ("--------------------")
        print ("SkyCam Picture Taken")
        print ("--------------------")
    camera = picamera.PiCamera()

    camera.exposure_mode = "auto"
    try:
        camera.rotation = config.Camera_Rotation
        
        camera.resolution = (1920, 1080)
        # Camera warm-up time
        time.sleep(2)

        camera.capture('static/skycamera.jpg')

        # now add timestamp to jpeg
        pil_im = Image.open('static/skycamera.jpg')
      
        draw = ImageDraw.Draw(pil_im)
        
        # Choose a font
        font = ImageFont.truetype("/usr/share/fonts/truetype/freefont/FreeSans.ttf", 25)

        # set up units
        #wind
        val = util.returnWindSpeed(state.WindSpeed)
        WindStval = "{0:0.1f}".format(val) + util.returnWindSpeedUnit()
        val = util.returnWindSpeed(state.WindGust)
        WindGtval = "{0:0.1f}".format(val) + util.returnWindSpeedUnit()
        val = util.returnTemperatureCF(state.OutdoorTemperature)
        OTtval = "{0:0.1f} ".format(val) + util.returnTemperatureCFUnit()

        myText = "SkyWeather2 V%s %s Wind Speed: %s Wind Gust: %s Temp: %s " % (config.SWVERSION,dt.datetime.now().strftime('%d-%b-%Y %H:%M:%S'),WindStval, WindGtval, OTtval)
        print("mySkyCameraText=", myText)

        # Draw the text
        color = 'rgb(255,255,255)'
        #draw.text((0, 0), myText,fill = color, font=font)

        # get text size
        text_size = font.getsize(myText)

        # set button size + 10px margins
        button_size = (text_size[0]+20, text_size[1]+10)

        # create image with correct size and black background
        button_img = Image.new('RGBA', button_size, "black")
     
        # put text on button with 10px margins
        button_draw = ImageDraw.Draw(button_img)
        button_draw.text((10, 5), myText, fill = color, font=font)

        # put button on source image in position (0, 0)

        pil_im.paste(button_img, (0, 0))
        bg_w, bg_h = pil_im.size 
        # WeatherSTEM logo in lower left
        size = 64
        WSLimg = Image.open("static/WeatherSTEMLogoSkyBackground.png")
        WSLimg.thumbnail((size,size),Image.ANTIALIAS)
        pil_im.paste(WSLimg, (0, bg_h-size))

        # SkyWeather log in lower right
        SWLimg = Image.open("static/SkyWeatherLogoSymbol.png")
        SWLimg.thumbnail((size,size),Image.ANTIALIAS)
        pil_im.paste(SWLimg, (bg_w-size, bg_h-size))

        # Save the image
        pil_im.save('dash_app/assets/skycamera.jpg', format= 'JPEG')
        pil_im.save('static/skycamera.jpg', format= 'JPEG')
        pil_im.save('static/skycameraprocessed.jpg', format= 'JPEG')

        cameraID = "SkyCamPi"
        currentpicturefilename = "static/CurrentPicture/"+cameraID+".jpg"
        currentpicturedashfilename = "dash_app/assets/"+cameraID+"_1.jpg"
        for name in glob.glob("dash_app/assets/"+cameraID+"_*.jpg"):
            os.remove(name)
        
        # put together the file name
        fileDate = datetime.datetime.now().strftime("%Y-%m-%d-%H-%M-%S")
        fileDay = datetime.datetime.now().strftime("%Y-%m-%d")

        singlefilename =cameraID+"_1_"+fileDate+".jpg"
        dirpathname="static/SkyCam/" + cameraID+ "/"+fileDay

        os.makedirs(dirpathname, exist_ok=True)
        os.makedirs("static/CurrentPicture", exist_ok=True)
        filename = dirpathname+"/"+singlefilename


        pil_im.save(filename, format= 'JPEG')
        pil_im.save(currentpicturefilename, format= 'JPEG')
        pil_im.save(currentpicturedashfilename, format= 'JPEG')

        FileSize =os.path.getsize(currentpicturefilename)

        if (config.enable_MySQL_Logging == True):
            # open mysql database
            # write log
            # commit
            # close
            try:
    
                con = mdb.connect(
                    "localhost",
                    "root",
                    config.MySQL_Password,
                    "WeatherSenseWireless" 
                )

                cur = con.cursor()
    
                fields = "cameraID, picturename, picturesize, messageID, resends,resolution"

                values = "\'%s\', \'%s\', %d, %d, %d, %d" % (cameraID, singlefilename, FileSize, 1, 0, 0)  
                query = "INSERT INTO SkyCamPictures (%s) VALUES(%s )" % (fields, values)
                print("query=", query)
                cur.execute(query)
                con.commit()
            except mdb.Error as e:
                traceback.print_exc()
                print("Error %d: %s" % (e.args[0], e.args[1]))
                con.rollback()
                # sys.exit(1)
    
            finally:
                cur.close()
                con.close()
    
                del cur
                del con


        time.sleep(2)

    except:
            if (config.SWDEBUG):
                print(traceback.format_exc()) 
                print ("--------------------")
                print ("SkyCam Picture Failed")
                print ("--------------------")


    finally:
        try:
            camera.close()
        except:
            if (config.SWDEBUG):
                print ("--------------------")
                print ("SkyCam Close Failed ")
                print ("--------------------")


    if (config.USEWEATHERSTEM == True):
        sendSkyWeather()
예제 #4
0
def blynkStateUpdate():

    try:

        blynkUpdateImage()

        put_header = {"Content-Type": "application/json"}

        # set last sample time

        put_header = {"Content-Type": "application/json"}
        val = time.strftime("%Y-%m-%d %H:%M:%S")
        put_body = json.dumps([val])
        if (DEBUGBLYNK):
            print "blynkEventUpdate:", val
        r = requests.put(config.BLYNK_URL + config.BLYNK_AUTH + '/update/V44',
                         data=put_body,
                         headers=put_header,
                         timeout=20)
        if (DEBUGBLYNK):
            print "blynkEventUpdate:POST:r.status_code:", r.status_code

        # do the graphs

        val = state.Outdoor_AirQuality_Sensor_Value
        put_body = json.dumps([val])
        if (DEBUGBLYNK):
            print "blynkStateUpdate:Pre:put_body:", put_body
        r = requests.put(config.BLYNK_URL + config.BLYNK_AUTH + '/update/V7',
                         data=put_body,
                         headers=put_header,
                         timeout=10)
        if (DEBUGBLYNK):
            print "blynkStateUpdate:POST:r.status_code:", r.status_code

        val = util.returnTemperatureCF(state.currentOutsideTemperature)
        tval = "{0:0.1f} ".format(val) + util.returnTemperatureCFUnit()
        put_body = json.dumps([tval])
        r = requests.put(config.BLYNK_URL + config.BLYNK_AUTH + '/update/V0',
                         data=put_body,
                         headers=put_header,
                         timeout=10)

        val = util.returnTemperatureCF(state.currentOutsideTemperature)
        put_body = json.dumps([val])
        r = requests.put(config.BLYNK_URL + config.BLYNK_AUTH + '/update/V10',
                         data=put_body,
                         headers=put_header,
                         timeout=10)

        val = state.currentOutsideHumidity
        put_body = json.dumps(["{0:0.1f}%".format(val)])
        r = requests.put(config.BLYNK_URL + config.BLYNK_AUTH + '/update/V1',
                         data=put_body,
                         headers=put_header,
                         timeout=10)

        val = state.currentOutsideHumidity
        put_body = json.dumps([val])
        r = requests.put(config.BLYNK_URL + config.BLYNK_AUTH + '/update/V11',
                         data=put_body,
                         headers=put_header,
                         timeout=10)

        val = util.returnTemperatureCF(state.currentInsideTemperature)
        tval = "{0:0.1f} ".format(val) + util.returnTemperatureCFUnit()
        put_body = json.dumps([tval])
        r = requests.put(config.BLYNK_URL + config.BLYNK_AUTH + '/update/V21',
                         data=put_body,
                         headers=put_header,
                         timeout=10)

        val = util.returnTemperatureCF(state.currentInsideTemperature)
        tval = "{0:0.1f}".format(val)
        put_body = json.dumps([val])
        r = requests.put(config.BLYNK_URL + config.BLYNK_AUTH + '/update/V120',
                         data=put_body,
                         headers=put_header,
                         timeout=10)

        val = state.currentInsideHumidity
        put_body = json.dumps(["{0:0.1f}%".format(val)])
        r = requests.put(config.BLYNK_URL + config.BLYNK_AUTH + '/update/V13',
                         data=put_body,
                         headers=put_header,
                         timeout=10)

        val = state.currentInsideHumidity
        put_body = json.dumps(["{0:0.1f}".format(val)])
        r = requests.put(config.BLYNK_URL + config.BLYNK_AUTH + '/update/V121',
                         data=put_body,
                         headers=put_header,
                         timeout=10)

        dewpoint = state.currentOutsideTemperature - (
            (100.0 - state.currentOutsideHumidity) / 5.0)
        put_body = json.dumps([
            "{0:0.1f}".format(util.returnTemperatureCF(dewpoint)) +
            util.returnTemperatureCFUnit()
        ])
        r = requests.put(config.BLYNK_URL + config.BLYNK_AUTH + '/update/V12',
                         data=put_body,
                         headers=put_header,
                         timeout=10)

        if (state.fanState == False):
            val = 0
        else:
            val = 1
        put_body = json.dumps([val])
        r = requests.put(config.BLYNK_URL + config.BLYNK_AUTH + '/update/V122',
                         data=put_body,
                         headers=put_header,
                         timeout=10)

        #wind
        val = util.returnWindSpeed(state.ScurrentWindSpeed)
        tval = "{0:0.1f}".format(val) + util.returnWindSpeedUnit()
        put_body = json.dumps([tval])
        r = requests.put(config.BLYNK_URL + config.BLYNK_AUTH + '/update/V9',
                         data=put_body,
                         headers=put_header,
                         timeout=10)

        #now humiidyt
        #val = util.returnWindSpeed(state.ScurrentWindSpeed)
        val = state.currentOutsideHumidity
        put_body = json.dumps([val])
        r = requests.put(config.BLYNK_URL + config.BLYNK_AUTH + '/update/V19',
                         data=put_body,
                         headers=put_header,
                         timeout=10)

        # outdoor Air Quality
        val = state.Outdoor_AirQuality_Sensor_Value
        put_body = json.dumps([val])
        r = requests.put(config.BLYNK_URL + config.BLYNK_AUTH + '/update/V20',
                         data=put_body,
                         headers=put_header,
                         timeout=10)

        #wind direction
        val = "{0:0.0f}/".format(
            state.ScurrentWindDirection) + util.returnWindDirection(
                state.ScurrentWindDirection)
        put_body = json.dumps([val])
        r = requests.put(config.BLYNK_URL + config.BLYNK_AUTH + '/update/V2',
                         data=put_body,
                         headers=put_header,
                         timeout=10)

        #rain
        # val = "{0:0.2f}".format(state.currentTotalRain)
        if (state.EnglishMetric == 1):
            tval = "{0:0.2f}mm".format(state.currentTotalRain)
        else:
            tval = "{0:0.2f}in".format(state.currentTotalRain / 25.4)
        put_body = json.dumps([tval])
        r = requests.put(config.BLYNK_URL + config.BLYNK_AUTH + '/update/V3',
                         data=put_body,
                         headers=put_header,
                         timeout=10)

        #rain last hour
        # val = "{0:0.2f}".format(state.currentRain60Minutes)
        if (state.EnglishMetric == 1):
            tval = "{0:0.2f}mm".format(state.currentRain60Minutes)
        else:
            tval = "{0:0.2f}in".format(state.currentRain60Minutes / 25.4)
        put_body = json.dumps([tval])
        r = requests.put(config.BLYNK_URL + config.BLYNK_AUTH + '/update/V14',
                         data=put_body,
                         headers=put_header,
                         timeout=10)

        #rain rate
        # val = "{0:0.2f}".format(state.currentRain60Minutes)
        if (state.EnglishMetric == 1):
            tval = "{0:0.2f}mm".format(state.currentRainRate)
        else:
            tval = "{0:0.2f}in".format(state.currentRainRate / 25.4)
        put_body = json.dumps([tval])
        r = requests.put(config.BLYNK_URL + config.BLYNK_AUTH + '/update/V15',
                         data=put_body,
                         headers=put_header,
                         timeout=10)

        #Sunlight
        val = "{0:0.0f}".format(state.currentSunlightVisible)
        #print ("Sunlight Val = ", state.currentSunlightVisible)
        put_body = json.dumps([val])
        r = requests.put(config.BLYNK_URL + config.BLYNK_AUTH + '/update/V4',
                         data=put_body,
                         headers=put_header,
                         timeout=10)

        #barometric Pressure
        if (state.EnglishMetric == 1):
            tval = "{0:0.2f}hPa".format(state.currentSeaLevel)
        else:
            tval = "{0:0.2f}in".format((state.currentSeaLevel * 0.2953) / 10.0)
        put_body = json.dumps([tval])
        r = requests.put(config.BLYNK_URL + config.BLYNK_AUTH + '/update/V40',
                         data=put_body,
                         headers=put_header,
                         timeout=10)

        #barometric Pressure graph
        if (state.EnglishMetric == 1):
            tval = "{0:0.2f}".format(state.currentSeaLevel)
        else:
            tval = "{0:0.2f}".format((state.currentSeaLevel * 0.2953) / 10.0)
        put_body = json.dumps([tval])
        r = requests.put(config.BLYNK_URL + config.BLYNK_AUTH + '/update/V41',
                         data=put_body,
                         headers=put_header,
                         timeout=10)

        #solar data

        val = "{0:0.2f}".format(state.solarVoltage)
        put_body = json.dumps([val])
        r = requests.put(config.BLYNK_URL + config.BLYNK_AUTH + '/update/V50',
                         data=put_body,
                         headers=put_header,
                         timeout=10)

        val = "{0:0.1f}".format(state.solarCurrent)
        put_body = json.dumps([val])
        r = requests.put(config.BLYNK_URL + config.BLYNK_AUTH + '/update/V51',
                         data=put_body,
                         headers=put_header,
                         timeout=10)

        val = "{0:0.2f}".format(state.batteryVoltage)
        put_body = json.dumps([val])
        r = requests.put(config.BLYNK_URL + config.BLYNK_AUTH + '/update/V52',
                         data=put_body,
                         headers=put_header,
                         timeout=10)

        val = "{0:0.1f}".format(state.batteryCurrent)
        put_body = json.dumps([val])
        r = requests.put(config.BLYNK_URL + config.BLYNK_AUTH + '/update/V53',
                         data=put_body,
                         headers=put_header,
                         timeout=10)

        val = "{0:0.2f}".format(state.loadVoltage)
        put_body = json.dumps([val])
        r = requests.put(config.BLYNK_URL + config.BLYNK_AUTH + '/update/V54',
                         data=put_body,
                         headers=put_header,
                         timeout=10)

        val = "{0:0.1f}".format(state.loadCurrent)
        put_body = json.dumps([val])
        r = requests.put(config.BLYNK_URL + config.BLYNK_AUTH + '/update/V55',
                         data=put_body,
                         headers=put_header,
                         timeout=10)

        val = "{0:0.1f}W".format(state.batteryPower)
        put_body = json.dumps([val])
        r = requests.put(config.BLYNK_URL + config.BLYNK_AUTH + '/update/V60',
                         data=put_body,
                         headers=put_header,
                         timeout=10)

        val = "{0:0.1f}W".format(state.solarPower)
        put_body = json.dumps([val])
        r = requests.put(config.BLYNK_URL + config.BLYNK_AUTH + '/update/V61',
                         data=put_body,
                         headers=put_header,
                         timeout=10)

        val = "{0:0.1f}W".format(state.loadPower)
        put_body = json.dumps([val])
        r = requests.put(config.BLYNK_URL + config.BLYNK_AUTH + '/update/V62',
                         data=put_body,
                         headers=put_header,
                         timeout=10)

        if (config.SolarMAX_Present == True):

            val = util.returnTemperatureCF(state.SolarMaxInsideTemperature)
            tval = "{0:0.1f} ".format(val) + util.returnTemperatureCFUnit()
            put_body = json.dumps([tval])
            r = requests.put(config.BLYNK_URL + config.BLYNK_AUTH +
                             '/update/V76',
                             data=put_body,
                             headers=put_header,
                             timeout=10)

            val = "{0:0.1f}%".format(state.SolarMaxInsideHumidity)
            put_body = json.dumps([val])
            r = requests.put(config.BLYNK_URL + config.BLYNK_AUTH +
                             '/update/V77',
                             data=put_body,
                             headers=put_header,
                             timeout=10)

        val = "{0:0.1f}".format(state.batteryCharge)
        put_body = json.dumps([val])
        r = requests.put(config.BLYNK_URL + config.BLYNK_AUTH + '/update/V56',
                         data=put_body,
                         headers=put_header,
                         timeout=10)

        val = "{0:0.1f}".format(state.batteryCharge)
        put_body = json.dumps([val])
        r = requests.put(config.BLYNK_URL + config.BLYNK_AUTH + '/update/V127',
                         data=put_body,
                         headers=put_header,
                         timeout=10)

        delta = util.returnTemperatureCF(
            state.currentInsideTemperature) - util.returnTemperatureCF(
                state.currentOutsideTemperature)

        val = "{0:0.1f}".format(delta)
        put_body = json.dumps([val])
        r = requests.put(config.BLYNK_URL + config.BLYNK_AUTH + '/update/V128',
                         data=put_body,
                         headers=put_header,
                         timeout=10)

        # LEDs

        if (DEBUGBLYNK):
            print "BarometricTrend: ", state.barometricTrend
            #if (state.barometricTrend):   #True is up, False is down
        if (state.barometricTrend == 0):
            r = requests.get(config.BLYNK_URL + config.BLYNK_AUTH +
                             '/update/V42?color=%23FFFFFF',
                             timeout=10)  #  White
        elif (state.barometricTrend == 1):
            r = requests.get(config.BLYNK_URL + config.BLYNK_AUTH +
                             '/update/V42?color=%2300FF00',
                             timeout=10)  # Green
        else:
            r = requests.get(config.BLYNK_URL + config.BLYNK_AUTH +
                             '/update/V42?color=%23FF0000',
                             timeout=10)  # red

        if (DEBUGBLYNK):
            print "blynkBarometricTrendUpdate:OTHER:r.status_code:", r.status_code

        print "lightning at: ", state.currentAs3935LastLightningTimeStamp, " time: ", time.time(
        ) - state.currentAs3935LastLightningTimeStamp
        if (time.time() - state.currentAs3935LastLightningTimeStamp > 1800):
            print "time elasped since last strike"
            state.currentAs3935LastLightningTimeStamp = 0

        if (state.currentAs3935LastLightningTimeStamp == 0
            ):  #True is lightning, False is none
            r = requests.get(config.BLYNK_URL + config.BLYNK_AUTH +
                             '/update/V43?color=%2300FF00',
                             timeout=10)  # Green
            if (DEBUGBLYNK):
                print "blynkAlarmUpdate:OTHER:r.status_code:", r.status_code
        else:
            r = requests.get(config.BLYNK_URL + config.BLYNK_AUTH +
                             '/update/V43?color=%23FF0000',
                             timeout=10)  # red

        return 1
    except Exception as e:
        print "exception in blynkStateUpdate"
        print(traceback.format_exc())
        print(e)
        return 0
예제 #5
0
def blynkStateUpdate():

    try:
     # do not blynk if no main reading yet
     if (state.lastMainReading != "Never"):
        
        blynkUpdateImage()
        
        put_header={"Content-Type": "application/json"}

        # set last sample time 
        
        put_header={"Content-Type": "application/json"}
        val = time.strftime("%Y-%m-%d %H:%M:%S")  
        put_body = json.dumps([val])
        if (DEBUGBLYNK):
          print("blynkEventUpdate:",val)
        r = requests.put(config.BLYNK_URL+config.BLYNK_AUTH+'/update/V44', data=put_body, headers=put_header)
        if (DEBUGBLYNK):
            print("blynkEventUpdate:POST:r.status_code:",r.status_code)

        # do the graphs


        if (config.USEWSAQI):
            val = state.WS_AQI
        else:
            val = state.AQI 
        put_body = json.dumps([val])
        if (DEBUGBLYNK):
            print("blynkStateUpdate:Pre:put_body:",put_body)
        r = requests.put(config.BLYNK_URL+config.BLYNK_AUTH+'/update/V7', data=put_body, headers=put_header)
        if (DEBUGBLYNK):
            print("blynkStateUpdate:POST:r.status_code:",r.status_code)
    

        val = util.returnTemperatureCF(state.OutdoorTemperature)
        tval = "{0:0.1f} ".format(val) + util.returnTemperatureCFUnit()
        put_body = json.dumps([tval])
        r = requests.put(config.BLYNK_URL+config.BLYNK_AUTH+'/update/V0', data=put_body, headers=put_header)

        val = util.returnTemperatureCF(state.OutdoorTemperature)
        put_body = json.dumps([val])
        r = requests.put(config.BLYNK_URL+config.BLYNK_AUTH+'/update/V10', data=put_body, headers=put_header)

        val = state.OutdoorHumidity 
        put_body = json.dumps(["{0:0.1f}%".format(val)])
        r = requests.put(config.BLYNK_URL+config.BLYNK_AUTH+'/update/V1', data=put_body, headers=put_header)

        val = state.OutdoorHumidity 
        put_body = json.dumps([val])
        r = requests.put(config.BLYNK_URL+config.BLYNK_AUTH+'/update/V11', data=put_body, headers=put_header)

        val = util.returnTemperatureCF(state.IndoorTemperature)
        tval = "{0:0.1f} ".format(val) + util.returnTemperatureCFUnit()
        put_body = json.dumps([tval])
        r = requests.put(config.BLYNK_URL+config.BLYNK_AUTH+'/update/V21', data=put_body, headers=put_header)

        val = util.returnTemperatureCF(state.IndoorTemperature)
        tval = "{0:0.1f}".format(val) 
        put_body = json.dumps([val])
        r = requests.put(config.BLYNK_URL+config.BLYNK_AUTH+'/update/V120', data=put_body, headers=put_header)

        val = state.IndoorHumidity 
        put_body = json.dumps(["{0:0.1f}%".format(val)])
        r = requests.put(config.BLYNK_URL+config.BLYNK_AUTH+'/update/V13', data=put_body, headers=put_header)

        val = state.IndoorHumidity 
        put_body = json.dumps(["{0:0.1f}".format(val)])
        r = requests.put(config.BLYNK_URL+config.BLYNK_AUTH+'/update/V121', data=put_body, headers=put_header)

        if (state.fanState == False):
            val = 0
        else:
            val = 1
        put_body = json.dumps([val])
        r = requests.put(config.BLYNK_URL+config.BLYNK_AUTH+'/update/V122', data=put_body, headers=put_header)


        #wind
        val = util.returnWindSpeed(state.WindSpeed)
        tval = "{0:0.1f}".format(val) + util.returnWindSpeedUnit()
        put_body = json.dumps([tval])
        r = requests.put(config.BLYNK_URL+config.BLYNK_AUTH+'/update/V9', data=put_body, headers=put_header)

        #now humiidyt
        #val = util.returnWindSpeed(state.WindSpeed)
        val = state.OutdoorHumidity
        put_body = json.dumps([val])
        r = requests.put(config.BLYNK_URL+config.BLYNK_AUTH+'/update/V19', data=put_body, headers=put_header)

        # outdoor Air Quality
        if (config.USEWSAQI):
            val = state.WS_AQI
        else:
            val = state.AQI 
        put_body = json.dumps([val])
        r = requests.put(config.BLYNK_URL+config.BLYNK_AUTH+'/update/V20', data=put_body, headers=put_header)
        
        #wind direction
        val = "{0:0.0f}/".format(state.WindDirection) + util.returnWindDirection(state.WindDirection)
        put_body = json.dumps([val])
        r = requests.put(config.BLYNK_URL+config.BLYNK_AUTH+'/update/V2', data=put_body, headers=put_header)

        #rain 
        val = "{0:0.2f}".format(state.TotalRain) 
        if (config.English_Metric == 1):
            tval = "{0:0.2f}mm".format(state.TotalRain) 
        else:
            tval = "{0:0.2f}in".format(state.TotalRain / 25.4) 
        put_body = json.dumps([tval])
        r = requests.put(config.BLYNK_URL+config.BLYNK_AUTH+'/update/V3', data=put_body, headers=put_header)

        #Sunlight 
        val = "{0:0.0f}".format(state.SunlightVisible) 
        #print ("Sunlight Val = ", state.SunlightVisible)
        put_body = json.dumps([val])
        r = requests.put(config.BLYNK_URL+config.BLYNK_AUTH+'/update/V4', data=put_body, headers=put_header)

        #Sunlight  for Graph
        val = "{0:0.0f}".format(state.SunlightVisible) 
        #print ("Sunlight Val = ", state.SunlightVisible)
        put_body = json.dumps([val])
        r = requests.put(config.BLYNK_URL+config.BLYNK_AUTH+'/update/V130', data=put_body, headers=put_header)

        #barometric Pressure 
        if (config.English_Metric == 1):
            tval = "{0:0.2f}hPa".format(state.BarometricPressureSeaLevel*10.0)
        else:
            tval = "{0:0.2f}in".format((state.BarometricPressureSeaLevel * 0.2953)) 
        put_body = json.dumps([tval])
        r = requests.put(config.BLYNK_URL+config.BLYNK_AUTH+'/update/V40', data=put_body, headers=put_header)

        #barometric Pressure graph
        if (config.English_Metric == 1):
            tval = "{0:0.2f}".format(state.BarometricPressureSeaLevel) 
        else:
            tval = "{0:0.2f}".format((state.BarometricPressureSeaLevel * 0.2953)) 
        put_body = json.dumps([tval])
        r = requests.put(config.BLYNK_URL+config.BLYNK_AUTH+'/update/V41', data=put_body, headers=put_header)

        #solar data

        val = "{0:0.2f}".format(state.solarVoltage) 
        put_body = json.dumps([val])
        r = requests.put(config.BLYNK_URL+config.BLYNK_AUTH+'/update/V50', data=put_body, headers=put_header)

        val = "{0:0.1f}".format(state.solarCurrent) 
        put_body = json.dumps([val])
        r = requests.put(config.BLYNK_URL+config.BLYNK_AUTH+'/update/V51', data=put_body, headers=put_header)

        val = "{0:0.2f}".format(state.batteryVoltage) 
        put_body = json.dumps([val])
        r = requests.put(config.BLYNK_URL+config.BLYNK_AUTH+'/update/V52', data=put_body, headers=put_header)

        val = "{0:0.1f}".format(state.batteryCurrent) 
        put_body = json.dumps([val])
        r = requests.put(config.BLYNK_URL+config.BLYNK_AUTH+'/update/V53', data=put_body, headers=put_header)

        val = "{0:0.2f}".format(state.loadVoltage) 
        put_body = json.dumps([val])
        r = requests.put(config.BLYNK_URL+config.BLYNK_AUTH+'/update/V54', data=put_body, headers=put_header)

        val = "{0:0.1f}".format(state.loadCurrent) 
        put_body = json.dumps([val])
        r = requests.put(config.BLYNK_URL+config.BLYNK_AUTH+'/update/V55', data=put_body, headers=put_header)

        val = "{0:0.1f}W".format(state.batteryPower) 
        put_body = json.dumps([val])
        r = requests.put(config.BLYNK_URL+config.BLYNK_AUTH+'/update/V60', data=put_body, headers=put_header)
        
        val = "{0:0.1f}W".format(state.solarPower) 
        put_body = json.dumps([val])
        r = requests.put(config.BLYNK_URL+config.BLYNK_AUTH+'/update/V61', data=put_body, headers=put_header)
        
        val = "{0:0.1f}W".format(state.loadPower) 
        put_body = json.dumps([val])
        r = requests.put(config.BLYNK_URL+config.BLYNK_AUTH+'/update/V62', data=put_body, headers=put_header)


        
        if (config.SolarMAX_Present == True):
            
            blynkSolarMAXLine(state.SolarMAXLastReceived)
            if (state.SolarMAXLastReceived != "Never"): 
                val = util.returnTemperatureCF(state.SolarMaxInsideTemperature)
                tval = "{0:0.1f} ".format(val) + util.returnTemperatureCFUnit()
                put_body = json.dumps([tval])
                r = requests.put(config.BLYNK_URL+config.BLYNK_AUTH+'/update/V76', data=put_body, headers=put_header)

                val = "{0:0.1f}%".format(state.SolarMaxInsideHumidity) 
                put_body = json.dumps([val])
                r = requests.put(config.BLYNK_URL+config.BLYNK_AUTH+'/update/V77', data=put_body, headers=put_header)

        
        
        val = "{0:0.1f}".format(state.batteryCharge) 
        put_body = json.dumps([val])
        r = requests.put(config.BLYNK_URL+config.BLYNK_AUTH+'/update/V56', data=put_body, headers=put_header)
        
        val = "{0:0.1f}".format(state.batteryCharge) 
        put_body = json.dumps([val])
        r = requests.put(config.BLYNK_URL+config.BLYNK_AUTH+'/update/V127', data=put_body, headers=put_header)
        
        delta = util.returnTemperatureCF(state.IndoorTemperature)- util.returnTemperatureCF(state.OutdoorTemperature)
        
        val = "{0:0.1f}".format(delta) 
        put_body = json.dumps([val])
        r = requests.put(config.BLYNK_URL+config.BLYNK_AUTH+'/update/V128', data=put_body, headers=put_header)
        
        
        # LEDs 


        if (state.barometricTrend):   #True is up, False is down
                        r = requests.get(config.BLYNK_URL+config.BLYNK_AUTH+'/update/V42?color=%2300FF00') # Green
                        if (DEBUGBLYNK):
                            print("blynkAlarmUpdate:OTHER:r.status_code:",r.status_code)
        else:
                        r = requests.get(config.BLYNK_URL+config.BLYNK_AUTH+'/update/V42?color=%23FF0000') # red



        return 1
    except Exception as e:
        print("exception in blynkStateUpdate")
        print(traceback.format_exc())
        print (e)
        return 0