Esempio n. 1
0
    def _return_json(self):

        display = self._agent.view()

        mesh_data = grid.call("/mesh/data")
        mesh_peers = grid.peers()
        messages = grid.inbox()

        total_messages = len(messages)
        unread_messages = len([m for m in messages if m['seen_at'] is None])

        peers = []
        for peer in mesh_peers:
            peers.append({
                "identity": peer["advertisement"]["identity"],
                "name": peer["advertisement"]["name"],
                "face": peer["advertisement"]["face"],
                "pwnd_run": peer["advertisement"]["pwnd_run"],
                "pwnd_tot": peer["advertisement"]["pwnd_tot"],
            })

        result = {
            "identity": mesh_data["identity"],
            "epoch": mesh_data["epoch"],
            "status": display.get('status'),
            "channel_text": display.get('channel'),
            "aps_text": display.get('aps'),
            "apt_tot": self._agent.get_total_aps(),
            "aps_on_channel": self._agent.get_aps_on_channel(),
            "channel": self._agent.get_current_channel(),
            "uptime": display.get('uptime'),
            "mode": display.get('mode'),
            "name": mesh_data["name"],
            "face": mesh_data["face"],
            "num_peers": len(mesh_peers),
            "peers": peers,
            "total_messages": total_messages,
            "unread_messages": unread_messages,
            "friend_face_text": display.get('friend_face'),
            "friend_name_text": display.get('friend_name'),
            "pwnd_run": mesh_data["pwnd_run"],
            "pwnd_tot": mesh_data["pwnd_tot"],
            "version": pwnagotchi.version,
            "memory": pwnagotchi.mem_usage(),  # Scale 0-1
            "cpu": pwnagotchi.cpu_load(),  # Scale 0-1
            "temperature": pwnagotchi.temperature()  # Degrees C
        }

        return jsonify(result)
Esempio n. 2
0
    def _adv_poller(self):
        # give the system a few seconds to start the first time so that any expressions
        # due to nearby units will be rendered properly
        time.sleep(20)
        while True:
            try:
                logging.debug("polling pwngrid-peer for peers ...")

                grid_peers = grid.peers()
                new_peers = {}

                self._closest_peer = None
                for obj in grid_peers:
                    peer = Peer(obj)
                    new_peers[peer.identity()] = peer
                    if self._closest_peer is None:
                        self._closest_peer = peer

                # check who's gone
                to_delete = []
                for ident, peer in self._peers.items():
                    if ident not in new_peers:
                        to_delete.append(ident)

                for ident in to_delete:
                    self._on_lost_peer(self._peers[ident])
                    del self._peers[ident]

                for ident, peer in new_peers.items():
                    # check who's new
                    if ident not in self._peers:
                        self._peers[ident] = peer
                        self._on_new_peer(peer)
                    # update the rest
                    else:
                        self._peers[ident].update(peer)

            except Exception as e:
                logging.warning("error while polling pwngrid-peer: %s" % e)
                logging.debug(e, exc_info=True)

            time.sleep(3)
Esempio n. 3
0
    def _adv_poller(self):
        while True:
            logging.debug("polling pwngrid-peer for peers ...")

            try:
                grid_peers = grid.peers()
                new_peers = {}

                self._closest_peer = None
                for obj in grid_peers:
                    peer = Peer(obj)
                    new_peers[peer.identity()] = peer
                    if self._closest_peer is None:
                        self._closest_peer = peer

                # check who's gone
                to_delete = []
                for ident, peer in self._peers.items():
                    if ident not in new_peers:
                        self._view.on_lost_peer(peer)
                        plugins.on('peer_lost', self, peer)
                        to_delete.append(ident)

                for ident in to_delete:
                    del self._peers[ident]

                for ident, peer in new_peers.items():
                    # check who's new
                    if ident not in self._peers:
                        self._peers[ident] = peer
                        self._view.on_new_peer(peer)
                        plugins.on('peer_detected', self, peer)
                    # update the rest
                    else:
                        self._peers[ident].update(peer)

            except Exception as e:
                logging.exception("error while polling pwngrid-peer")

            time.sleep(1)
Esempio n. 4
0
    def _adv_poller(self):
        while True:
            try:
                logging.debug("polling pwngrid-peer for peers ...")

                grid_peers = grid.peers()
                new_peers = {}

                self._closest_peer = None
                for obj in grid_peers:
                    peer = Peer(obj)
                    new_peers[peer.identity()] = peer
                    if self._closest_peer is None:
                        self._closest_peer = peer

                # check who's gone
                to_delete = []
                for ident, peer in self._peers.items():
                    if ident not in new_peers:
                        to_delete.append(ident)

                for ident in to_delete:
                    self._on_lost_peer(self._peers[ident])
                    del self._peers[ident]

                for ident, peer in new_peers.items():
                    # check who's new
                    if ident not in self._peers:
                        self._peers[ident] = peer
                        self._on_new_peer(peer)
                    # update the rest
                    else:
                        self._peers[ident].update(peer)

            except Exception as e:
                logging.warning("error while polling pwngrid-peer: %s" % e)
                logging.debug(e, exc_info=True)

            time.sleep(3)