Beispiel #1
0
    def scanDevices(self):

        # look up our data
        data = {}
        data['bots'] = hive.scanBots()
        data['cameras'] = camera_control.scanCameras()

        scanData = json.dumps(data)
        if scanData != self.lastScanData or (self.lastImageTime + 60 <
                                             time.time()):
            self.lastScanData = scanData

            camera_files = []
            if len(data['cameras']):
                for idx, camera in enumerate(data['cameras']):
                    outfile = camera['name'] + '.jpg'
                    try:
                        if camera_control.takePicture(camera['device'],
                                                      watermark=None,
                                                      output=outfile):
                            self.lastImageTime = time.time()
                            fullImgPath = hive.getImageDirectory(outfile)
                            camera_files.append(fullImgPath)
                    except Exception as ex:
                        self.log.exception(ex)

            # now update the main site
            self.api.sendDeviceScanResults(data, camera_files)
Beispiel #2
0
    def scanDevices(self):

        # look up our data
        data = {}
        data['bots'] = hive.scanBots()
        data['cameras'] = camera_control.scanCameras()

        scanData = json.dumps(data)
        if scanData != self.lastScanData or (self.lastImageTime + 60 < time.time()):
            self.lastScanData = scanData

            camera_files = []
            if len(data['cameras']):
                for idx, camera in enumerate(data['cameras']):
                    outfile = camera['name'] + '.jpg'
                    try:
                        if camera_control.takePicture(camera['device'], watermark=None, output=outfile):
                            self.lastImageTime = time.time()
                            fullImgPath = hive.getImageDirectory(outfile)
                            camera_files.append(fullImgPath)
                    except Exception as ex:
                        self.log.exception(ex)

            # now update the main site
            self.api.sendDeviceScanResults(data, camera_files)
Beispiel #3
0
    def updateHomeBase(self, latest, temps):
        self.info("print: %0.2f%%" % float(latest))
        outputName = "bot-%s.jpg" % self.data['id']

        if self.takePicture(outputName):
            fullImgPath = hive.getImageDirectory(outputName)
            self.api.webcamUpdate(fullImgPath,
                                  job_id=self.data['job']['id'],
                                  progress="%0.5f" % float(latest),
                                  temps=temps)
        else:
            self.api.updateJobProgress(self.data['job']['id'], "%0.5f" % float(latest), temps)
Beispiel #4
0
def takePicture(device, watermark=None, output="webcam.jpg", brightness=50, contrast=50):
    output = hive.getImageDirectory(output)
    with mutex:
        log = logging.getLogger('botqueue')

        try:
            # what os are we using
            myos = hive.determineOS()
            if myos == "osx":
                imagesnap = os.path.dirname(os.path.realpath(__file__)) + os.sep + "imagesnap"
                command = "%s -q -d '%s' -w 2.0 '%s' && " \
                          "sips --resampleWidth 640" \
                          " --padToHeightWidth 480 640" \
                          " --padColor FFFFFF -s formatOptions 60%% '%s' 2>/dev/null" % (
                              imagesnap,
                              device,
                              output,
                              output
                          )
                # log.info("Webcam Command: %s" % command)
                return __run_picture_command(command, log)
            elif myos == "raspberrypi" or myos == "linux":
                if device == "Rasberry Pi Camera":
                    import picamera

                    try:
                        with picamera.PiCamera() as camera:
                            camera.capture(output, resize=(640, 480))
                            camera.close()
                            return True
                    except picamera.exc.PiCameraError as ex:
                        # No need to log an exception here
                        return False
                else:
                    command = "exec /usr/bin/fswebcam" \
                              " -q --jpeg 60 -d '%s'" \
                              " -r 640x480 --title '%s'" \
                              " --set brightness=%s%%" \
                              " --set contrast=%s%% '%s'" % (
                                  device,
                                  watermark,
                                  brightness,
                                  contrast,
                                  output
                              )
                    # log.info("Webcam Command: %s" % command)
                    return __run_picture_command(command, log)
            else:
                raise Exception("Webcams are not supported on your OS (%s)." % myos)

        except Exception as ex:
            log.exception(ex)
            return False
Beispiel #5
0
    def run(self):
        # sleep for a random time to avoid contention
        time.sleep(random.random())

        lastWebcamUpdate = time.time()
        try:
            # okay, we're off!
            self.running = True
            while self.running:

                # see if there are any messages from the motherbee
                self.checkMessages()

                # did we get a shutdown notice?
                if not self.running:
                    break

                # slicing means we need to slice our job.
                if self.data['status'] == 'slicing':
                    if self.data['job']['slicejob']['status'] == 'slicing' and self.config['can_slice']:
                        self.sliceJob()
                # working means we need to process a job.
                elif self.data['status'] == 'working':
                    self.processJob()
                    # self.getOurInfo() # if there was a problem with the job,
                    # we'll find it by pulling in a new bot state and looping again.
                    self.debug("Bot finished @ state %s" % self.data['status'])

                # upload a webcam pic every so often.
                if time.time() - lastWebcamUpdate > 60:
                    outputName = "bot-%s.jpg" % self.data['id']
                    if self.takePicture(outputName):
                        fullImgPath = hive.getImageDirectory(outputName)
                        self.api.webcamUpdate(fullImgPath, bot_id=self.data['id'])
                    lastWebcamUpdate = time.time()

                time.sleep(self.sleepTime)  # sleep for a bit to not hog resources
        except Exception as ex:
            self.exception(ex)
            self.driver.stop()
            raise ex

        self.debug("Exiting.")