Ejemplo n.º 1
0
    if len(sys.argv) > 1:
        startName = sys.argv[1]
    if len(sys.argv) > 2:
        startState = sys.argv[2]

    sel = selectors.DefaultSelector()

    #variables that simulate the actual state of the light
    currentActualState = startState
    currentActualName = startName
    currentActualTime = 0

    #initialStateList is in the format [initial actualState, actualName, actualCurrentTime]
    initialStateList = [currentActualState, currentActualName, 0]

    wifiComm = multiconnClientClass2.wifiCommunicator(sel, initialStateList)

    context = "IDLE"

    timerTestAlreadyDone = False
    motionTime = 10
    motionEndTime = 40

    while True:
        wifiComm.checkWifi()  #check wifi signals
        #now can check wifiComm.lightModuleDict to see what the wifi is instructing the light to do
        #print(wifiComm.getState())
        wifiState = wifiComm.getState(
        )  #format [connectionStatus ("CONNECTED"/"NOTYETCONNECTED"/"DISCONNECTED"), wifiState ("ON"/"OFF"), wifiName (string), resetTime (bool)]
        #if the wif-commanded state or name has changed, then simulate changing the actual name and state of the light
        '''
Ejemplo n.º 2
0
    def pre_cycle(self):
        """ 
        Check WIFI and update from wifi.
        """
        '''
        if (self.state==DETECT):
            print ("Connected")
            self.state=IDLE
        '''
        if (self.state==DETECT):
            #initialize wifi
            #initialStateList is in the format [initial actualState, actualName, actualCurrentTime]
            self.state=IDLE
            if self.state == ACTIVE:
                initialStateList = ["ON", self.wifiName, 0]
            else:
                initialStateList = ["OFF", self.wifiName, 0]                

            self.wifi = multiconnClientClass2.wifiCommunicator(sel, initialStateList)
            print ("Connected")

        if (self.state==IDLE):
            #wifistate = int (input("State IDLE, turn on? [1/0]?"))
            #if (wifistate==1):
            #    self.state = INITIAL
            pass




        # Connection = False 
        # wifiState  = 0
        # resetTimer = True
        
        #---------- Simulation only ----------------#
        #Connection = True 
        #wifiState  = 1
        #wifiName = "Test"
        #resetTimer = False
        #-------------------------------------------#

        # Check connection
        self.wifi.checkWifi() # This updates the internal memory

        # Fetch updated data from checkwifi()
        (Connection, wifiState, self.wifiName, resetTimer) = self.wifi.getState()

        if (Connection=="CONNECTED"):
            # Only change state when there is a connection
            if (wifiState=="ON"):
                print ("Connection true, lampON: ", self.lampON)
                if (self.lampON==0 and self.timer.period==-1):
                    # Lamp off and timer not set
                    self.state = INITIAL
                else:
                    # Lamp off and timer was set:
                    # Resume disinfection
                    self.state = ACTIVE
            else:
                self.state = IDLE

            if (resetTimer==True):
                # Reset time should be effective whether lamp on (turn off, reset time), 
                # or lamp off (simply reset time to -1)
                self.state = IDLE
                self.timer.reset()  # Resets timer time to -1
        else:
            self.state = IDLE
            print("Not connected to base station.")


        # Detect human
        self.seeHuman = self.motionSensor.getReadings()
        if (self.seeHuman):
            self.state = IDLE       # If human detect, go to IDLE


        return 0