Exemplo n.º 1
0
 def base_st_connect(self):
     """
     Sends a confirmation message to Base Station to acknowledge connection. If it receives and ACK from Base Station, starts up the Sensor_thread.
     """
     self.tried = 0
     while(self.tried<=5):
         LOGMSG("Checking if base station is responding...")
         self.tried += 1
         msg = pack('8sBBB','SLIPCC11',kelvin.DISPATCH,kelvin.CMD | kelvin.CONN_REQ, 0)
         self.write(msg)
         time.sleep(2)
         rsp = self.read()
         if(rsp != b''):
             break
                 
     if(self.tried > 5):
         LOGMSG("Base station currently unreachable. Please try later.")
         LOGMSG("The server will now close...")
         self.close()
         
     else:    
         LOGMSG("Connected to base station.")
         
         #Start a thread which will handle all sensor data extraction
         self.sensor = Sensor(self)
         self.sensor.start()