def next(self): if self.any_activity is False and self.did_handshakes is False: self.inactive_for += 1 self.active_for = 0 else: self.active_for += 1 self.inactive_for = 0 now = time.time() cpu = pwnagotchi.cpu_load() mem = pwnagotchi.mem_usage() temp = pwnagotchi.temperature() self.epoch_duration = now - self.epoch_started # cache the state of this epoch for other threads to read self._epoch_data = { 'duration_secs': self.epoch_duration, 'slept_for_secs': self.num_slept, 'blind_for_epochs': self.blind_for, 'inactive_for_epochs': self.inactive_for, 'active_for_epochs': self.active_for, 'missed_interactions': self.num_missed, 'num_hops': self.num_hops, 'num_deauths': self.num_deauths, 'num_associations': self.num_assocs, 'num_handshakes': self.num_shakes, 'cpu_load': cpu, 'mem_usage': mem, 'temperature': temp } self._epoch_data['reward'] = self._reward(self.epoch + 1, self._epoch_data) self._epoch_data_ready.set() logging.info( "[epoch %d] duration=%s slept_for=%s blind=%d inactive=%d active=%d hops=%d missed=%d " "deauths=%d assocs=%d handshakes=%d cpu=%d%% mem=%d%% temperature=%dC reward=%s" % (self.epoch, core.secs_to_hhmmss( self.epoch_duration), core.secs_to_hhmmss( self.num_slept), self.blind_for, self.inactive_for, self.active_for, self.num_hops, self.num_missed, self.num_deauths, self.num_assocs, self.num_shakes, cpu * 100, mem * 100, temp, self._epoch_data['reward'])) self.epoch += 1 self.epoch_started = now self.did_deauth = False self.num_deauths = 0 self.did_associate = False self.num_assocs = 0 self.num_missed = 0 self.did_handshakes = False self.num_shakes = 0 self.num_hops = 0 self.num_slept = 0 self.any_activity = False
def _update_uptime(self, s): secs = time.time() - self._started_at self._view.set('uptime', core.secs_to_hhmmss(secs)) self._view.set('epoch', '%04d' % self._epoch.epoch)