コード例 #1
0
ファイル: Compare.py プロジェクト: jozzee/SmartGarden-Python
def onExceptWater(timeStamp, errorCode,
                  isConn):  # 1 is water false, 2 is arae flase
    global wErrCount
    wErrCount += 1
    print(" count error: " + str(wErrCount))
    if (int(wErrCount) > int(errorCount)):
        print(" has exception!! Water")
        wErrCount = 0
        if (isConn):
            body = json.dumps({"time": timeStamp, "errorCode": errorCode})
            noti = gcm.setData("except", str(body))
            gcm.pushNotification(noti)
        else:
            print("not pushNotification because no internet connection")
        return int(timeStamp) + int(exceptStamp)
    else:
        return 0
コード例 #2
0
ファイル: Compare.py プロジェクト: jozzee/SmartGarden-Python
def onExceptShower(
        timeStamp, errorCode,
        isConn):  # 3 is water false, 4 temp not declete after working
    global sErrCount
    sErrCount += 1
    print(" count error: " + str(sErrCount))
    if (int(sErrCount) > int(errorCount)):
        print("has exception!! Shower")
        sErrCount = 0
        if (isConn):
            body = json.dumps({"time": timeStamp, "errorCode": errorCode})
            noti = gcm.setData("except", str(body))
            gcm.pushNotification(noti)
        else:
            print("not pushNotification because no internet connection")
        return int(timeStamp) + int(exceptStamp)
    else:
        return 0
コード例 #3
0
def MainFunction():
    inputs.setSensorPoint(sensorPoint)
    while True:
        print("")
        alarmClock.getAlarmList()
        have, body = alarmClock.haveAlarmClock()
        if (have and isConn):
            gear.onRefreshRawData()
            gear.publisLogDataList()
            gear.publisSlatStatus(sp.get(slatStatus))
            noti = gcm.setData("alarm", str(body))
            gcm.pushNotification(noti)
        else:
            print("not alarm clock")

        timeStamp = int(time.time())
        print(
            str(timeStamp) + " (" + str(t.timeStampToDateTime(timeStamp)) +
            ") " + getNetStatus())

        if (gear.isHasReload()):
            reload()

        mosObj = json.loads(inputs.getMoistureObject())
        temObj = json.loads(inputs.getTempObject())
        ligObj = json.loads(inputs.getLightObject())

        if (sp.get(autoMode)):
            global stSlat
            stSlat = getSlatStatus(ligObj["light_in"], ligObj["light_out"])
        else:
            stSlat = sp.get("slatStatus")

        if (mosObj["average"] > 0):
            for i in range(0, int(sensorPoint)):
                print(" moisture at point " + str(i + 1) + ": " +
                      str(mosObj[("point" + str(i + 1))]) + " %")
        else:
            print(" moisture sensors error!")
        if (temObj["average"] > 0):
            for i in range(0, int(sensorPoint)):
                print(" temp at point     " + str(i + 1) + ":   " +
                      str(temObj[("point" + str(i + 1))]) + " *C")
        else:
            print(" temp sensors error!")
        print(" lightIn:          " + str(ligObj["light_in"]) + " Lux")
        print(" lightOut:         " + str(ligObj["light_out"]) + " Lux")
        print(" slat status:      " + str(stSlat))
        print("")

        print("  mosStd: " + str(sp.get(mosStd)))
        print("  tmpStd: " + str(sp.get(tmpStd)))
        print("  ligStd: " + str(sp.get(ligStd)))
        print("  fqPData: " + str(sp.get(fqPData)))
        print("  fqPImage: " + str(sp.get(fqPImage)))
        print("  fqIData: " + str(sp.get(fqIData)))
        print("  fqShower: " + str(sp.get(fqShower)))
        print("  ageData: " + str(sp.get(ageData)))
        print("  lastUpdate: " + str(sp.get(lastUpdate)))
        print("  autoMode: " + str(sp.get(autoMode)))
        print("")

        global isConn
        global nextTimePubData
        global nextTimePubImage
        global nextTimeInsertData
        global lastTimePubImage

        if (int(timeStamp) >= int(nextTimePubData)):
            if (isConn):
                payload = "{\"time\":" + str(
                    timeStamp) + ",\"moisture\":" + str(
                        json.dumps(mosObj)) + ",\"temp\":" + str(
                            json.dumps(temObj) + ",\"light\":" +
                            str(json.dumps(ligObj))) + "}"
                result, nextTime = gear.publishRawData(str(payload),
                                                       sp.get(fqPData),
                                                       timeStamp)
                if (result):
                    nextTimePubData = nextTime
        if (int(timeStamp) >= int(nextTimePubImage)):
            if (isConn):
                result, nextTime = gear.publishImage(sp.get(fqPImage),
                                                     timeStamp)
                if (result):
                    nextTimePubImage = nextTime
                    lastTimePubImage = timeStamp
        if (int(timeStamp) >= int(nextTimeInsertData)):
            reult, nextTime = db.insertRawData(timeStamp, mosObj, temObj,
                                               ligObj)
            if (reult):
                nextTimeInsertData = nextTime
                if (isConn):
                    gear.publisRawDataList()

        print("")
        print(" nextTimePubData: " +
              str(t.timeStampToDateTime(nextTimePubData)))
        print(" nextTimePubImage: " +
              str(t.timeStampToDateTime(nextTimePubImage)))
        print(" nextTimeInsertData: " +
              str(t.timeStampToDateTime(nextTimeInsertData)))
        print("")

        #Compare and validate
        global timeExceptWater
        global timeExceptShower

        if (sp.get(autoMode)):
            print("\nOn Work in Auto Mode...")
            if (t.isDay()):
                #-----------------------------------------------

                if (int(timeStamp) > int(timeExceptWater)):
                    result, timeExcept = compare.compareMosture(
                        timeStamp, mosObj, isConn)
                    if (result):
                        if (isConn):
                            gear.publisLogDataList()
                        timeExceptWater = 0
                    else:
                        if (int(timeExcept) > 0):
                            timeExceptWater = timeExcept
                else:
                    print("wait to " +
                          str(t.timeStampToDateTime(timeExceptWater)) +
                          " for water agains ")

                #-----------------------------------------------

                global lastTimeShower
                if (int(timeStamp) > int(timeExceptShower)):
                    result, timeExcept = compare.compareTemp(
                        timeStamp, temObj, lastTimeShower, isConn, mosObj,
                        stSlat, ligObj)
                    if (result):
                        if (isConn):
                            gear.publisLogDataList()
                        timeExceptShower = 0
                        lastTimeShower = timeStamp
                        sp.put("lastTimeShower", lastTimeShower)
                    else:
                        if (int(timeExcept) > 0):
                            timeExceptShower = timeExcept
                else:
                    print("wait to " +
                          str(t.timeStampToDateTime(timeExceptShower)) +
                          " for shower agains")

                #------------------------------------------------

                result, st = compare.compareLight(timeStamp, ligObj, stSlat,
                                                  isConn)
                if (result):
                    if (isConn):
                        gear.publisSlatStatus(st)

                #-------------------------------------------------

            else:
                print(" But this time is a nigth!...")
        else:
            print("manual mode....")

        checkNet(timeStamp)
        print("----------------------------------------------------\n")

        time.sleep(10)
コード例 #4
0
ファイル: example.py プロジェクト: heart2426/Python34-GCM
	def __init__(self):
		self.gcm = GCM()
コード例 #5
0
ファイル: example.py プロジェクト: heart2426/Python34-GCM
class Test(object):
	def __init__(self):
		self.gcm = GCM()

	def sendGCM(self, registration_ids, message):
		return self.gcm.sendMessage(registration_ids, message)
コード例 #6
0
ファイル: Compare.py プロジェクト: jozzee/SmartGarden-Python
def compareLight(timeStamp, ligObj, st, isConn):
    result = False
    std = float(sp.get(ligStd))
    ligIn = float(ligObj["light_in"])
    ligOut = float(ligObj["light_out"])

    print("Compare, check light...")

    if ((ligIn > 0) and (ligOut > 0)):
        if ((ligIn > std) and (ligOut > std)):
            print(" light more than standard")
            if (st != 0):
                if (ctrl.closeSlat()):  #if can close slat
                    time.sleep(10)
                    newLigObj = json.loads(inputs.getLightObject())
                    if (float(newLigObj["light_in"]) > float(ligIn)):
                        print("  but new light value not decrease")
                        if (isConn):
                            noti = gcm.setData("except", str(7))
                            gcm.pushNotification(noti)
                db.insertLogData(
                    timeStamp, 4, 1, float(ligIn),
                    float(newLigObj["light_in"]))  #insert log to database
                sp.put(slatStatus, str("0"))
                result = True
                st = 0
            else:
                print(" but slat is closed (0)")
        elif ((ligIn < std) and (ligOut < std)):
            print(" light lessthan standard")
            if (st != 1):
                if (ctrl.openSlat()):  #if can open slat
                    time.sleep(10)
                    newLigObj = json.loads(inputs.getLightObject())
                    db.insertLogData(
                        timeStamp, 3, 1, float(ligIn),
                        float(newLigObj["light_in"]))  #insert log to database
                    sp.put(slatStatus, int(1))
                    result = True
                    st = 1
            else:
                print(" but slat is opened (1)")
    elif (float(ligObj["light_in"]) > 0):
        print(" light out error, Compare in one sensor mode")
        if (ligIn > std):  #close slat
            print(" light more than standard")
            if (st != 0):
                if (ctrl.closeSlat()):  #if can close slat
                    time.sleep(10)
                    newLigObj = json.loads(inputs.getLightObject())
                    if (float(newLigObj["light_in"]) > float(ligIn)):
                        print("  but new light value not decrease")
                        if (isConn):
                            noti = gcm.setData("except", str(5))
                            gcm.pushNotification(noti)
                db.insertLogData(
                    timeStamp, 4, 1, float(ligIn),
                    float(newLigObj["light_in"]))  #insert log to database
                sp.put(slatStatus, str("0"))
                result = True
                st = 0
            else:
                print(" but slat is closed (0)")

        elif ((std - ligIn) > 2000):  #open slat
            print(" light lessthan standard ever 2,000 lux")
            if (st != 1):
                if (ctrl.openSlat()):  #if can open slat
                    time.sleep(10)
                    newLigObj = json.loads(inputs.getLightObject())
                    db.insertLogData(
                        timeStamp, 3, 1, float(ligIn),
                        float(newLigObj["light_in"]))  #insert log to database
                    sp.put(slatStatus, int(1))
                    result = True
                    st = 1
            else:
                print(" but slat is opened (1)")

    else:
        print(" light sensor error!!")
    return result, st
コード例 #7
0
ファイル: Compare.py プロジェクト: jozzee/SmartGarden-Python
def compareTemp(timeStamp, temObj, lastTimeShower, isConn, mosObj, stSlat,
                ligObj):
    result = False
    timeExceptShower = 0
    print("Compare, check temp...")
    if (float(temObj["point1"]) > 0):  # chamge point1 to average
        if (float(temObj["average"]) > float(
                sp.get(tmpStd))):  # chamge point1 to average
            fq = sp.get(fqShower)
            if (fq == 0):
                fq = t.getFqShower(
                )  #get ferquency from system (fq in minute *60) minStamp
            print(" ferquency: " + str(fq) + " minute")
            if (int(timeStamp) >=
                (int(lastTimeShower) + (int(fq) * int(minStamp)))):
                if (float(mosObj["average"]) <= float(
                        sp.get(mosStd))):  #dgfbndgfnhdgnmhjmk
                    if (ctrl.shower()):
                        time.sleep(30)  #wait 30 seccond
                        newTemObj = json.loads(inputs.getTempObject())
                        print(
                            " old temp: " +
                            str(temObj["average"]))  # chamge point1 to average
                        print(" new temp: " + str(
                            newTemObj["average"]))  # chamge point1 to average
                        if (float(newTemObj["point1"]) <= float(
                                temObj["average"])
                            ):  # chamge point1 to average
                            print(" All success")
                            db.insertLogData(
                                timeStamp, 2, 1, float(temObj["average"]),
                                float(newTemObj["average"])
                            )  #insert log to database # chamge point1 to average
                            result = True
                        else:
                            print(" Error! temp not decrease after shower")
                            timeExceptShower = onExceptShower(
                                timeStamp, 3, isConn)
                    else:
                        print(" Error! water not flows")
                        timeExceptShower = onExceptShower(timeStamp, 1, isConn)
                else:
                    if (int(stSlat) == 1):  #close slat
                        ligIn = float(ligObj["light_in"])
                        ligOut = float(ligObj["light_out"])
                        if (ctrl.closeSlat()):  #if can close slat
                            time.sleep(10)
                            newLigObj = json.loads(inputs.getLightObject())
                            if (float(newLigObj["light_in"]) > float(ligIn)):
                                print("  but new light value not decrease")
                                if (isConn):
                                    noti = gcm.setData("except", str(7))
                                    gcm.pushNotification(noti)
                            db.insertLogData(timeStamp, 4, 1, float(ligIn),
                                             float(newLigObj["light_in"])
                                             )  #insert log to database
                            sp.put(slatStatus, str("0"))
                            result = True
                    else:
                        if (ctrl.shower()):
                            time.sleep(30)  #wait 30 seccond
                            newTemObj = json.loads(inputs.getTempObject())
                            print(" old temp: " + str(
                                temObj["average"]))  # chamge point1 to average
                            print(" new temp: " + str(newTemObj["average"])
                                  )  # chamge point1 to average
                            if (float(newTemObj["point1"]) <= float(
                                    temObj["average"])
                                ):  # chamge point1 to average
                                print(" All success")
                                db.insertLogData(
                                    timeStamp, 2, 1, float(temObj["average"]),
                                    float(newTemObj["average"])
                                )  #insert log to database # chamge point1 to average
                                result = True
                            else:
                                print(" Error! temp not decrease after shower")
                                timeExceptShower = onExceptShower(
                                    timeStamp, 3, isConn)
                        else:
                            print(" Error! water not flows")
                            timeExceptShower = onExceptShower(
                                timeStamp, 1, isConn)
            else:
                print(" not time to shower, Working again at " +
                      t.timeStampToDateTime((int(lastTimeShower) +
                                             (int(fq) * int(minStamp)))))
        else:
            print(" no working...")
    else:
        print(" temp sensor error!!")

    return result, timeExceptShower
コード例 #8
0
ファイル: example.py プロジェクト: KenLin114/Python34-GCM
 def __init__(self):
     self.gcm = GCM()
コード例 #9
0
ファイル: example.py プロジェクト: KenLin114/Python34-GCM
class Test(object):
    def __init__(self):
        self.gcm = GCM()

    def sendGCM(self, registration_ids, message):
        return self.gcm.sendMessage(registration_ids, message)