def handle_getimg(self, client_stream, req, headers, content):
     if self.debug:
         print("handle_getimg", end="")
     try:
         if self.img_compressed is None:
             client_stream.write(
                 captive_portal.default_reply_header(
                     content_type="image/jpeg", content_length=0))
             client_stream.close()
             if self.debug:
                 print(" no image")
             return
         sz = self.img_compressed.size()
         client_stream.write(
             captive_portal.default_reply_header(content_type="image/jpeg",
                                                 content_length=sz))
         sent = client_stream.write(self.img_compressed)
         client_stream.close()
         if self.debug:
             print(" sent %u" % sent)
     except KeyboardInterrupt:
         raise
     except Exception as exc:
         s = exclogger.log_exception(exc)
         self.reply_ok(client_stream, sts=False, err=s)
Esempio n. 2
0
 def reply_ok(self, stream, sts = True, err = None):
     x = {}
     x.update({"time": self.time_mgr.get_sec()})
     x.update({"status": sts})
     x.update({"err": err})
     json_str = ujson.dumps(x)
     stream.write(captive_portal.default_reply_header(content_type = "application/json", content_length = len(json_str)) + json_str)
     stream.close()
Esempio n. 3
0
 def handle_getsettings(self, client_stream, req, headers, content):
     if self.debug:
         print("handle_getsettings")
     self.kill_imgstreamer()
     self.kill_websocket()
     json_str = ujson.dumps(self.settings)
     client_stream.write(captive_portal.default_reply_header(content_type = "application/json", content_length = len(json_str)) + json_str)
     client_stream.close()
     return True
Esempio n. 4
0
 def handle_getstate(self, client_stream, req, headers, content):
     if self.debug:
         print("handle_getstate")
     self.handle_query(client_stream, req, reply = False, save = False)
     state = self.fill_state()
     json_str = ujson.dumps(state)
     client_stream.write(captive_portal.default_reply_header(content_type = "application/json", content_length = len(json_str)) + json_str)
     client_stream.close()
     if self.use_leds:
         red_led.on()
     return True
    def handle_getstate(self, client_stream, req, headers, content):
        if self.debug:
            print("handle_getstate")
        self.handle_query(client_stream, req, reply=False, save=False)
        state = {}
        state.update({"time": self.time_mgr.get_sec()})
        if self.img is not None and self.cam_err == False:
            state.update({"expo_code": self.expo_code})
        elif self.img is None:
            state.update({"expo_code": star_finder.EXPO_NO_IMG})
        elif self.cam_err:
            state.update({"expo_code": star_finder.EXPO_CAMERA_ERR})
        if self.stars is not None:
            state.update({"stars": blobstar.to_jsonobj(self.stars)})

        state.update({"max_stars": self.max_stars})

        # diagnostic info
        state.update({"frm_cnt": self.frm_cnt})
        if self.debug:
            state.update({"diag_cnt": self.diag_cnt})
            state.update({"diag_dur_all": self.dur_all})
            state.update({"diag_mem_alloc": gc.mem_alloc()})
            state.update({"diag_mem_free": gc.mem_free()})
        if self.img_stats is not None:
            state.update({"img_mean": self.img_stats.mean()})
            state.update({"img_stdev": self.img_stats.stdev()})
            state.update({"img_max": self.img_stats.max()})
            state.update({"img_min": self.img_stats.min()})

        json_str = ujson.dumps(state)
        client_stream.write(
            captive_portal.default_reply_header(
                content_type="application/json", content_length=len(json_str))
            + json_str)
        client_stream.close()
        if self.use_leds:
            red_led.on()
    def handle_getstate(self, client_stream, req, headers, content):
        if self.debug:
            print("handle_getstate")
        self.handle_query(client_stream, req, reply=False, save=False)
        state = {}
        state.update({"time": self.time_mgr.get_sec()})
        state.update({"packjpeg": self.packjpeg})
        state.update({"daymode": self.daymode})
        if self.img is not None and self.cam_err == False:
            state.update({"expo_code": self.expo_code})
        elif self.img is None:
            state.update({"expo_code": star_finder.EXPO_NO_IMG})
        elif self.cam_err:
            state.update({"expo_code": star_finder.EXPO_CAMERA_ERR})
        stable_solution = self.stable_solution()
        if stable_solution is not None:
            stable_solution.get_pole_coords()  # update time
            state.update({"solution": stable_solution.to_jsonobj()})
            state.update({"star_x": stable_solution.Polaris.cx})
            state.update({"star_y": stable_solution.Polaris.cy})
            state.update({"pole_x": stable_solution.x})
            state.update({"pole_y": stable_solution.y})
            state.update({"rotation": stable_solution.get_rotation()})
            state.update({
                "polaris_ra":
                (stable_solution.polaris_ra_dec[0] * 360.0) / 24.0
            })
            state.update({"pix_per_deg": stable_solution.pix_per_deg})
        else:
            state.update({"solution": False})
        if self.stars is not None:
            star_list = self.stars
            if len(star_list) > 50:
                star_list = blobstar.sort_brightness(star_list)[0:50]
            state.update({"stars": blobstar.to_jsonobj(star_list)})
        state.update({"polar_clock": self.time_mgr.get_angle()})

        state.update({"max_stars": self.max_stars})

        # diagnostic info
        state.update({"frm_cnt": self.frm_cnt})
        if self.debug:
            state.update({"diag_cnt": self.diag_cnt})
            state.update({"diag_dur_all": self.dur_all})
            state.update({"diag_dur_sol": self.solu_dur})
            state.update({"diag_mem_alloc": gc.mem_alloc()})
            state.update({"diag_mem_free": gc.mem_free()})
        if self.img_stats is not None:
            state.update({"img_mean": self.img_stats.mean()})
            state.update({"img_stdev": self.img_stats.stdev()})
            state.update({"img_max": self.img_stats.max()})
            state.update({"img_min": self.img_stats.min()})

        json_str = ujson.dumps(state)
        client_stream.write(
            captive_portal.default_reply_header(
                content_type="application/json", content_length=len(json_str))
            + json_str)
        client_stream.close()
        if self.use_leds:
            red_led.on()