Esempio n. 1
0
def publishStateToPubNub():

    if (config.DEBUG):
        print('Publishing Data to PubNub time: %s' % datetime.now())

    myMessage = {}
    myMessage["SmartPlantPi_Visible"] = "{:4.2f}".format(state.Sunlight_Vis)
    myMessage["SmartPlantPi_IR"] = "{:4.2f}".format(state.Sunlight_IR)
    myMessage["SmartPlantPi_UVIndex"] = "{:4.2f}".format(
        state.Sunlight_UVIndex)
    myMessage["SmartPlantPi_MoistureHumidity"] = "{:4.1f}".format(
        state.Moisture_Humidity)
    myMessage["SmartPlantPi_AirQuality_Sensor_Value"] = "{}".format(
        state.AirQuality_Sensor_Value)
    myMessage["SmartPlantPi_AirQuality_Sensor_Number"] = "{}".format(
        state.AirQuality_Sensor_Number)
    myMessage["SmartPlantPi_AirQuality_Sensor_Text"] = "{}".format(
        state.AirQuality_Sensor_Text)
    myMessage["SmartPlantPi_Temperature"] = "{:4.1f} {}".format(
        util.returnTemperatureCF(state.Temperature),
        util.returnTemperatureCFUnit())
    myMessage["SmartPlantPi_Humidity"] = "{:4.1f}".format(state.Humidity)
    myMessage["SmartPlantPi_CurrentStatus"] = "{}".format(
        state.SGS_Values[state.SGS_State])
    myMessage["SmartPlantPi_Moisture_Threshold"] = '{:4.1f}'.format(
        state.Moisture_Threshold)
    myMessage["SmartPlantPi_Version"] = '{}'.format(SGSVERSION)
    myMessage["TimeStamp"] = '{}'.format(
        datetime.now().strftime("%m/%d/%Y %H:%M:%S"))
    myMessage["SmartPlantPi_Last_Event"] = "{}".format(state.Last_Event)
    if (state.Pump_Water_Full == 0):
        myMessage["SmartPlantPi_Water_Full_Text"] = "{}".format("Empty")
        myMessage["SmartPlantPi_Water_Full_Direction"] = "{}".format("180")
    else:
        myMessage["SmartPlantPi_Water_Full_Text"] = "{}".format("Full")
        myMessage["SmartPlantPi_Water_Full_Direction"] = "{}".format("0")

    if (config.DEBUG):
        print myMessage

    #pubnub.publish().channel('SmartPlantPi_Data').message(myMessage).async(publish_callback)
    pubnub.publish().channel('SmartPlantPi_Data').message(myMessage)
    #pubnub.publish().channel('SmartPlantPi_Alexa').message(myMessage).async(publish_callback)
    pubnub.publish().channel('SmartPlantPi_Alexa').message(myMessage)

    blinkLED(0, Color(0, 255, 255), 3, 0.200)
Esempio n. 2
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
Esempio n. 3
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()
def blynkStateUpdate():
    try:
        put_header = {"Content-Type": "application/json"}

        if (DEBUGBLYNK):
            print("blynkStateUpdate:")
        blynkEventUpdate()

        # do our percentage active
        wirelessJSON = readJSON.getJSONValue("WirelessDeviceJSON")

        active = 0
        for single in wirelessJSON:
            if (state.deviceStatus[single['id']] == True):
                active = active + 1
        myPercent = 100.0 * active / len(state.deviceStatus)
        # do the graphs
        val = "{:4.1f}".format(myPercent)
        put_body = json.dumps([val])
        r = requests.put(config.BLYNK_URL + config.BLYNK_AUTH + '/update/V1',
                         data=put_body,
                         headers=put_header)

        if (state.lastMainReading != "Never"):
            val = state.Hour24_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/V11',
                             data=put_body,
                             headers=put_header)
            if (DEBUGBLYNK):
                print("blynkStateUpdate:POST:r.status_code:", r.status_code)

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

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

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

        # do the boxes

        val = "{:4.1f}%".format(psutil.cpu_percent())
        put_body = json.dumps([val])
        r = requests.put(config.BLYNK_URL + config.BLYNK_AUTH + '/update/V2',
                         data=put_body,
                         headers=put_header)

        val = "{:4.1f}%".format(psutil.virtual_memory().percent)
        put_body = json.dumps([val])
        r = requests.put(config.BLYNK_URL + config.BLYNK_AUTH + '/update/V3',
                         data=put_body,
                         headers=put_header)

        myValue = psutil.disk_usage('/')
        myDPercent = myValue[3]
        myDPercent = 100.0 - myDPercent

        val = "{:4.1f}%".format(myDPercent)
        put_body = json.dumps([val])
        r = requests.put(config.BLYNK_URL + config.BLYNK_AUTH + '/update/V4',
                         data=put_body,
                         headers=put_header)

        # page 2 SensorsLevels
        myID = ""
        myName = "No Wireless Unit Selected"
        PlantIPAddress = ""
        if (state.WirelessDeviceSelectorPlant > 0):
            myJSONWireless = readJSON.getJSONValue("WirelessDeviceJSON")
            i = 0
            if (len(myJSONWireless) > state.WirelessDeviceSelectorPlant):
                myName = str(i) + ":" + "No Wireless Unit Selected"
                myID = ""
            for single in myJSONWireless:
                i = i + 1
                if (state.WirelessDeviceSelectorPlant == i):
                    myName = str(i) + ": " + str(
                        single["id"]
                    ) + "/" + single["name"] + "/" + single["ipaddress"]
                    PlantIPAddress = single["ipaddress"]
                    myID = single["id"]
            if (myID != ""):
                print("setting Valves by Plant")
                blynkSetValves(myID, 29)

            # now have ID, so can find sensor values
            if (len(state.moistureSensorStates) > 0):
                for singleSensor in state.moistureSensorStates:
                    if (str(singleSensor["id"]) == str(myID)):
                        updateVirtual = "V" + str(
                            int(singleSensor["sensorNumber"]) + 21)
                        val = "{:4.1f}%".format(
                            float(singleSensor["sensorValue"]))
                        put_body = json.dumps([val])
                        r = requests.put(config.BLYNK_URL + config.BLYNK_AUTH +
                                         '/update/' + updateVirtual,
                                         data=put_body,
                                         headers=put_header)

        if (state.WirelessDeviceSelectorControl > 0):
            myJSONWireless = readJSON.getJSONValue("WirelessDeviceJSON")
            if (len(myJSONWireless) > state.WirelessDeviceSelectorControl):
                myID = ""
                i = 0
                for single in myJSONWireless:
                    i = i + 1
                    if (state.WirelessDeviceSelectorControl == i):
                        myID = single["id"]
                if (myID != ""):
                    print("setting Valves by Control")
                    blynkSetValves(myID, 49)

        return 1
    except Exception as e:
        print(traceback.format_exc())
        print("exception in blynkStateUpdate")
        print(e)
        return 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
Esempio n. 6
0
def updateState():

  if (config.DEBUG):
      print "Attempt UpdateStateLock acquired"
  UpdateStateLock.acquire()
  if (config.DEBUG):
      print "UpdateStateLock acquired"


  # catch Exceptions and MAKE SURE THE LOCK is released!
  try:
    if (state.SGS_State == state.SGS_States.Monitor):  
            state.SGS_State =state.SGS_States.Sampling
            if (config.USEBLYNK):
                updateBlynk.blynkStatusUpdate()
	    if (config.DEBUG):
            	print "----------------- "
            	print "Update State"
            	print "----------------- "
            if (config.Sunlight_Present == True):
        			if (config.DEBUG):
                                	print " Sunlight Vi/state.Sunlight_IR/UV Sensor"
            else:
        			if (config.DEBUG):
                                	print " Sunlight Vi/state.Sunlight_IR/UV Sensor Not Present"
            if (config.DEBUG):
            	print "----------------- "
    
            if (config.Sunlight_Present == True):
                    ################
                    state.Sunlight_Vis = SI1145Lux.SI1145_VIS_to_Lux(Sunlight_Sensor.readVisible())
                    state.Sunlight_IR = SI1145Lux.SI1145_IR_to_Lux(Sunlight_Sensor.readIR())
                    state.Sunlight_UV = Sunlight_Sensor.readUV()
                    state.Sunlight_UVIndex = state.Sunlight_UV / 100.0

            	    if (config.DEBUG):
                    	print 'Sunlight Visible:  ' + str(state.Sunlight_Vis)
                    	print 'Sunlight state.Sunlight_IR:       ' + str(state.Sunlight_IR)
                    	print 'Sunlight UV Index (RAW): ' + str(state.Sunlight_UV)
                    	print 'Sunlight UV Index: ' + str(state.Sunlight_UVIndex)
                    ################
    
    
            if (config.ADS1115_Present):
                state.Moisture_Humidity  = extendedPlants.readExtendedMoisture(1, None, ads1115, None, None) 
                state.Moisture_Humidity_Array[0] =  state.Moisture_Humidity 

                for i in range(2,config.plant_number+1):     
                    state.Moisture_Humidity_Array[i-1] = extendedPlants.readExtendedMoisture(i,GDE_Ext1, ads1115_ext1, GDE_Ext2, ads1115_ext2)

                if (config.DEBUG):
                    print ("From Moisture Array")
                    for i in range(0,config.plant_number):     
                        print "plant #%i: Moisture: %0.2f" % (i+1, state.Moisture_Humidity_Array[i])
                    print ("From RAW Moisture Array")
                    for i in range(0,config.plant_number):     
                        print "plant #%i: Moisture: %0.2f" % (i+1, state.Raw_Moisture_Humidity_Array[i])

                state.AirQuality_Sensor_Value =  AirQualitySensorLibrary.readAirQualitySensor(ads1115)
    
                sensorList = AirQualitySensorLibrary.interpretAirQualitySensor(state.AirQuality_Sensor_Value)
            	if (config.DEBUG):
                	print "Sensor Value=%i --> %s  | %i"% (state.AirQuality_Sensor_Value, sensorList[0], sensorList[1])

                state.AirQuality_Sensor_Number = sensorList[1] 
                state.AirQuality_Sensor_Text = sensorList[0] 

            # update water Level
            percentFull = ultrasonicRanger.returnPercentFull()
            # check for abort
            if (percentFull < 0.0):
                if (config.DEBUG):
                    print "---->Bad Measurement from Ultrasonic Sensor for Tank Level"
                # leave the previous value
            else:
                state.Tank_Percentage_Full = percentFull
        
            if (state.Tank_Percentage_Full > config.Tank_Pump_Level):
                state.Pump_Water_Full = True
            else:
                state.Pump_Water_Full = False

            # read temp humidity
   
            if (config.hdc1000_Present):
                state.Temperature= hdc1000.readTemperature()
                state.Humidity = hdc1000.readHumidity()
    
           	if (config.DEBUG):
            		print 'Temp             = {0:0.3f} deg C'.format(state.Temperature)
            		print 'Humidity         = {0:0.2f} %'.format(state.Humidity)
    
            state.SGS_State =state.SGS_States.Monitor
            if (config.USEBLYNK):
                updateBlynk.blynkStatusUpdate()

            if (config.USE_MQTT):
                try:
                    updateMqtt.updateMqtt(
                        moisture=state.Moisture_Humidity,
                        temperature=util.returnTemperatureCF(state.Temperature),
                        humidity=state.Humidity,
                        air_quality=state.AirQuality_Sensor_Value,
                        light=state.Sunlight_Vis
                    )
                except Exception as e:
                    print('Could not publish to MQTT: ' + e.message)
          

            if (config.OLED_Present) and (state.SGS_State == state.SGS_States.Monitor) :


                    if (config.DEBUG):
                          print "Attempt OLEDLock acquired"
		    OLEDLock.acquire()
                    if (config.DEBUG):
                          print "OLEDLock acquired"
                    Scroll_SSD1306.addLineOLED(display,  ("----------"))
                    Scroll_SSD1306.addLineOLED(display,  ("Plant #1 Moisture = \t%0.2f %%")%(state.Moisture_Humidity))
                    Scroll_SSD1306.addLineOLED(display,  ("Temperature = \t%0.2f %s")%(util.returnTemperatureCF(state.Temperature), util.returnTemperatureCFUnit()))
                    Scroll_SSD1306.addLineOLED(display,  ("Humidity =\t%0.2f %%")%(state.Humidity))
                    Scroll_SSD1306.addLineOLED(display,  ("Air Qual = %d/%s")%(state.AirQuality_Sensor_Value, state.AirQuality_Sensor_Text))
                    Scroll_SSD1306.addLineOLED(display,  ("Sunlight = \t%0.2f Lux")%(state.Sunlight_Vis))
                    # Now display other plants
                    if (config.plant_number >1):
                        # print 2-4
                        time.sleep(2.0)
                        Scroll_SSD1306.addLineOLED(display,  ("----------"))
                        Scroll_SSD1306.addLineOLED(display,  ("Plant #2 Moisture = \t%0.2f %%")%(state.Moisture_Humidity_Array[1]))
                        Scroll_SSD1306.addLineOLED(display,  ("Plant #3 Moisture = \t%0.2f %%")%(state.Moisture_Humidity_Array[2]))
                        Scroll_SSD1306.addLineOLED(display,  ("Plant #4 Moisture = \t%0.2f %%")%(state.Moisture_Humidity_Array[3]))
                        Scroll_SSD1306.addLineOLED(display,  ("Plant #5 Moisture = \t%0.2f %%")%(state.Moisture_Humidity_Array[4]))
                        if (config.plant_number >5):
                            time.sleep(2.0)
                            Scroll_SSD1306.addLineOLED(display,  ("----------"))
                            Scroll_SSD1306.addLineOLED(display,  ("Plant #6 Moisture = \t%0.2f %%")%(state.Moisture_Humidity_Array[5]))
                            Scroll_SSD1306.addLineOLED(display,  ("Plant #7 Moisture = \t%0.2f %%")%(state.Moisture_Humidity_Array[6]))
                            Scroll_SSD1306.addLineOLED(display,  ("Plant #8 Moisture = \t%0.2f %%")%(state.Moisture_Humidity_Array[7]))
                            Scroll_SSD1306.addLineOLED(display,  ("Plant #9 Moisture = \t%0.2f %%")%(state.Moisture_Humidity_Array[8]))
                        
                    if (config.DEBUG):
                        print "Attempt OLEDLock released"
		    OLEDLock.release()
                    if (config.DEBUG):
 
                        print "OLEDLock released"

  except Exception as e:
    if (config.DEBUG):
        print "Exception Raised in Update State"
    print e 
    traceback.print_exc(file=sys.stdout)
  finally:
    pass 
  if (config.DEBUG):
    print "Attempt UpdateStateLock released"
  UpdateStateLock.release()
  if (config.DEBUG):
          print "UpdateStateLock released"
          print ">>>>>>>>>>>>>>"
          print "Exiting Update State"
          print ">>>>>>>>>>>>>>"

  if (config.USEBLYNK):
     updateBlynk.blynkStateUpdate()
Esempio n. 7
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()
Esempio n. 8
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