dodo5522 / solar_monitor

TS-MPPT-60 logger application
2 stars 0 forks source link

keenioへのデータアップロードが止まる #25

Open dodo5522 opened 8 years ago

dodo5522 commented 8 years ago

おそらく、KeenIoHandlerクラスのinitでのみKeenClientをオープンしているため、一度切断されると再接続できないことが原因。

    def __init__(self, project_id, write_key, q_max=5):                                                                        
        IEventHandler.__init__(self, q_max=q_max)

        self.client_ = KeenClient(
            project_id=project_id,
            write_key=write_key)

    def _run(self, data):
        """ Procedure to run when data received from trigger thread.

        Args:
            data: Pass to the registered event handlers.
        """
        data_source = data["source"]
        at = data["at"]

        upload_items = []
        for label, datum in data["data"].items():
            upload_item = datum
            upload_item["label"] = label
            upload_item["source"] = data_source
            upload_item["keen"] = {"timestamp": "{}Z".format(at.isoformat())}
            upload_items.append(upload_item)

        self.client_.add_events({"offgrid": upload_items})
dodo5522 commented 8 years ago