Example #1
0
    def connect(self, ssid, psk):
        ip = getIP('wlan0')
        if ip:
            print('WiFi is already connected, skip')
            print("IP: %s" % ip)
            return True
        print("Connecting to \"{}\"...".format(ssid))
        message = self.message.format(self.country, ssid, psk)
        with open("/etc/wpa_supplicant/wpa_supplicant.conf", "w") as f:
            f.write(message)

        for i in range(6):
            if i != 0:
                print('Timeout, retry ({})...'.format(i))
            self.run_command("wpa_cli -i wlan0 reconfigure")
            time.sleep(1)
            time_start = time.time()
            while True:
                ip = getIP('wlan0')
                if ip:
                    print("IP: %s" % ip)
                    print('WiFi connect success')
                    return True

                time_end = time.time()
                if time_end - time_start > 10:
                    print('WiFi connect failed')
                    break
                time.sleep(0.1)
        return False
Example #2
0
 def start(self): 
     self.ip = getIP()
     print("server starts at %s:%s" % (self.ip, self.port))
     self.address = (self.ip, self.port)
     streaming_handler = create_handler(self.output)
     self.server = StreamingServer(self.address, streaming_handler)
     self.t = Thread(target=self.server.serve_forever)
     self.t.start()
Example #3
0
 def start(self):
     self.ip = getIP()
     print("server starts at %s:%s" % (self.ip, self.port))
     self.mjpgServer.camera = self.camera
     self.server = HTTPServer((self.ip, self.port), self.mjpgServer)
     self.server.socket = ssl.wrap_socket(
         self.server.socket,
         server_side=True,
         certfile='/opt/ezblock/ssl/ca.pem',
         ssl_version=ssl.PROTOCOL_TLSv1)
     self.server.serve_forever()
Example #4
0
 def get(self):
     self._check_info_file()
     ip = getIP()
     if ip:
         self.set("ip", ip)
     self.debug("get info")
     with open('%s/.info' % self.file_dir, 'r') as f:
         lines = f.readlines()
     for line in lines:
         if ": " in line:
             line = line.strip().split(": ")
             arg = line[0]
             val = line[1]
             if arg in self.info:
                 if isinstance(self.info[arg], list):
                     self.info[arg].append(val)
                 else:
                     self.info[arg] = val
     self.debug(self.info)
     return self.info
Example #5
0
                        raise Exception('Error, camera not setup')
                    if not ret:
                        print('no image from camera')
                        time.sleep(1)
                        continue

                    ret, jpg = cv2.imencode('.jpg', img)
                    self.wfile.write("--jpgboundary".encode())
                    self.send_header('Content-type', 'image/jpeg')
                    self.send_header('Content-length', str(jpg.size))
                    self.end_headers()
                    self.wfile.write(jpg.tostring())
                    time.sleep(1.0 / freq)
            else:
                print('error', self.path)
                self.send_response(404)
                self.send_header('Content-type', 'text/html'.encode())
                self.end_headers()
                self.wfile.write('<html><head></head><body>'.encode())
                self.wfile.write('<h1>{0!s} not found</h1>'.format(
                    self.path).encode())
                self.wfile.write('</body></html>'.encode())


if __name__ == '__main__':
    try:
        print(getIP()[0])
        Camera(0).start()
    except KeyboardInterrupt:
        print('KeyboardInterrupt')