예제 #1
0
 def setCycleOff(self, fanNumber):
     self.cleanProcess(fanNumber)
     pin = getattr(self, 'pin_'+str(fanNumber))
     proc = subprocess.Popen(['nohup','python',utils.getContextPath()+'/bin/scripts/fan/off.py',str(pin),'&'])
     utils.fwrite(utils.getContextPath()+'/bin/scripts/fan/pid_'+str(fanNumber),proc.pid)
     print("Fan PID: "+str(proc.pid))
     print("FanController is now OFF")
     return
예제 #2
0
 def setCycle(self,dutyR,dutyB):
     self.cleanProcess()
     procR = subprocess.Popen(['nohup','python',utils.getContextPath()+'/bin/scripts/led/on.py',str(self.channel_0),str(dutyR),'&'])
     procB = subprocess.Popen(['nohup','python',utils.getContextPath()+'/bin/scripts/led/on.py',str(self.channel_1),str(dutyB),'&'])
     utils.fwrite(utils.getContextPath()+'/bin/scripts/led/pid_0',procR.pid)
     utils.fwrite(utils.getContextPath()+'/bin/scripts/led/pid_1',procB.pid)
     print("Red channel PID: "+str(procR.pid)+", Blue channel PID: "+str(procB.pid))
     print("LedController cycle running")
     return
예제 #3
0
 def cleanProcess(self,fanNumber):
     try:
         pid = utils.fread(utils.getContextPath()+'/bin/scripts/fan/pid_'+str(fanNumber))
         subprocess.call(["sudo","kill",str(pid)])
         print("Process "+str(pid)+" killed")
     except:
         print("No process found")
예제 #4
0
    def runPwm(self): 

        confPath = utils.getContextPath()+'/conf'
        pwm_data = {}
        with open(confPath+'/pwm_conf.json') as data_file:    
            data = json.load(data_file)
                  
        for key, value in data.iteritems():           
            #if (key[:4]=='Grow' or key[:3] == 'FanController' or key[:14] == 'IndicatorPanel') and value["flag"]==1 and value["duty"] >= 0.0 and value["duty"] <=4095.0:
            if (key[:8] == 'FrontLED' ): 
                if(value["flag"]==1):
                    print(key,value)
                    self.pwm.set_pwm(value["channel"], 0, value["duty"])
                    pwm_data.update({key : {"channel":value["channel"],"duty":value["duty"],"flag":0}})
                else:
                    pass
            elif key[:3] == 'Fan':
                if(value["flag"]==1):
                    print(key,value)
                    self.pwm.set_pwm(value["channel"], 0, value["duty"])
                    pwm_data.update({key : {"channel":value["channel"],"duty":value["duty"],"flag":0,"timeout":value["timeout"]}})
                else:
                    pass
                

        self.register(pwm_data)
예제 #5
0
 def capture(self):
     with picamera.PiCamera() as camera:
         camera.sharpness = 0
         camera.contrast = 0
         camera.brightness = 50
         camera.saturation = 0
         camera.ISO = 0
         camera.video_stabilization = False
         camera.exposure_compensation = 0
         camera.exposure_mode = 'auto'
         camera.meter_mode = 'average'
         camera.awb_mode = 'auto'
         camera.image_effect = 'none'
         camera.color_effects = None
         camera.rotation = 0
         camera.hflip = self.option_snapshot_hflip
         camera.vflip = self.option_snapshot_vflip
         camera.crop = (0.0, 0.0, 1.0, 1.0)
         photosPath = utils.getContextPath()+"/data/photos"
         tstamp = time.time()
         dtstr = datetime.datetime.fromtimestamp(tstamp).strftime('%Y%m%d%H%M%S')
         camera.capture(photosPath+'/snapshot_'+str(dtstr)+'.jpg')
         camera.close()
         del(camera)
         return photosPath+'/snapshot_'+str(dtstr)+'.jpg'
예제 #6
0
 def stopRPiCWI(self):
     print("Trying to Stop Camera with RPi Cam Web Interface...")
     utils.log("Trying to Stop Camera with RPi Cam Web Interface...")
     libPackPath = utils.getContextPath()+"/lib/RPi_Cam_Web_Interface"
     subprocess.call(["sudo", "chmod", "+x", libPackPath+"/stop.sh"])
     subprocess.call(["sudo", libPackPath+"/stop.sh"])
     self.isOn = False
     self.persistInRam({'camera_is_on':False})
예제 #7
0
 def cleanProcess(self):
     try:
         pidRedPath = utils.getContextPath() + '/bin/scripts/led/pid_red'
         pidBluePath = utils.getContextPath() + '/bin/scripts/led/pid_blue'
         if os.path.exists(pidRedPath) and os.path.isfile(pidRedPath):
             pidRed = utils.fread(utils.getContextPath() +
                                  '/bin/scripts/led/pid_red')
             if pidRed != None:
                 subprocess.call(["sudo", "kill", str(pidRed)])
                 print("Process " + str(pidRed) + " killed")
         if os.path.exists(pidBluePath) and os.path.isfile(pidBluePath):
             pidBlue = utils.fread(utils.getContextPath() +
                                   '/bin/scripts/led/pid_blue')
             if pidBlue != None:
                 subprocess.call(["sudo", "kill", str(pidBlue)])
                 print("Process " + str(pidBlue) + " killed")
     except:
         print("No process found")
예제 #8
0
 def capture(self):
     photosPath = utils.getContextPath() + "/data/photos"
     tstamp = time.time()
     dtstr = datetime.datetime.fromtimestamp(tstamp).strftime(
         '%Y%m%d%H%M%S')
     subprocess.call([
         "fswebcam", "-r", "1280x720", "--no-banner",
         photosPath + '/snapshot_' + str(dtstr) + '.jpg'
     ])
     return photosPath + '/snapshot_' + str(dtstr) + '.jpg'
예제 #9
0
    def setCycleOn(self):
        self.cleanProcess()
        procB = subprocess.Popen([
            'nohup', 'python',
            utils.getContextPath() + '/bin/scripts/led/on.py',
            str(self.pin_blue), '&'
        ])
        procR = subprocess.Popen([
            'nohup', 'python',
            utils.getContextPath() + '/bin/scripts/led/on.py',
            str(self.pin_red), '&'
        ])
        utils.fwrite(utils.getContextPath() + '/bin/scripts/led/pid_red',
                     procR.pid)
        utils.fwrite(utils.getContextPath() + '/bin/scripts/led/pid_blue',
                     procB.pid)
        print("Red pin PID: " + str(procR.pid) + ", Blue pin PID: " +
              str(procB.pid))

        print("LedController is now ON")
        return
예제 #10
0
 def cleanUpRepository(self,doRemove=False):
     tstamp = time.time()
     dtstr = datetime.datetime.fromtimestamp(tstamp).strftime('%Y%m%d%H%M%S')
     photosPath = utils.getContextPath()+"/data/photos"
     print("Starting Camera Repository CleanUp... path: "+photosPath)
     utils.log("Starting Camera Repository CleanUp... path: "+photosPath)
     for file in os.listdir(photosPath):
         if file.endswith(".jpg") :
             #print(file[9:][0:8])
             if int(file[9:][0:8]) < int(dtstr[0:8])-2 :
                 if doRemove :
                     print("Removing "+photosPath+os.path.sep+file+"...")
                     utils.log("Removing "+photosPath+os.path.sep+file+"...")
                     os.remove(photosPath+os.path.sep+file)
                 else :
                     print("Marked for removal: "+photosPath+os.path.sep+file)
                     utils.log("Marked for removal: "+photosPath+os.path.sep+file)
예제 #11
0
 def runPwm(self):
     import Adafruit_PCA9685
     self.pwm = Adafruit_PCA9685.PCA9685()
     self.pwm.set_pwm_freq(1000)
     confPath = utils.getContextPath() + '/conf'
     with open(confPath + '/pwm_conf.json') as data_file:
         data = json.load(data_file)
     for key, value in data.iteritems():
         print(value["value"])
         if value["flag"] == 1 and value["value"] >= 0 and value[
                 "value"] <= 4095:
             self.pwm.set_pwm(value["channel"], 0, value["value"])
             self.register(
                 {key: {
                     "channel": channel,
                     "value": duty,
                     "flag": 1
                 }})
예제 #12
0
 def execute(self):
     s = 0
     confPath = utils.getContextPath()+'/conf'
     with open(confPath+'/growLED_pwm_conf.json') as data_file:    
         pwmdata = json.load(data_file)
     
     for key, value in pwmdata.iteritems():
         if (key[:7] == 'GrowLED'):
             s += value["duty"]
     
     s = float(s)/4095.0*100.0/6.0        
     print('current LED output',s)
     if s<10.0:
         self.setAllOff()
     elif s> 10.0 and s<80.0:   
         print('case 2')
         with open(confPath+'/pwm_conf.json') as data_file:    
             pwmdata = json.load(data_file)
         for key, value in pwmdata.iteritems():
             if key[:13]== 'FanController':
                 if value["duty"] > 4000.0 :
                     print('timeout=','value["timeout"]')
                     if value["timeout"] <  time.time():
                         self.setOff('front')
                         self.setOff('back')
                         self.setOff('led')
                     else:
                         print('still on, wait = ' + str(value["timeout"] -  time.time()))
                         pass
                 else:
                     if value["timeout"] <  time.time():
                         self.setOn('front')
                         self.setOn('back')
                         self.setOn('led')
                     else:
                         print('still off, wait = ' + str(value["timeout"] -  time.time()))
                         pass
     else:
         self.setOn('led')
예제 #13
0
 def register(self, data):
     confPath = utils.getContextPath() + '/conf'
     utils.updateJSONFile(confPath + '/pwm_conf.json', data)