fix: supporting channels greater than 140 for 5g (closes #583)

This commit is contained in:
Simone Margaritelli 2019-11-13 01:32:05 +01:00
parent 9dcc647656
commit a8c07ba997
3 changed files with 39 additions and 28 deletions

View File

@ -4,9 +4,15 @@ import pwnagotchi.mesh.wifi as wifi
MAX_EPOCH_DURATION = 1024 MAX_EPOCH_DURATION = 1024
histogram_size = wifi.NumChannels
shape = (1, def describe(extended=False):
if not extended:
histogram_size = wifi.NumChannels
else:
# see https://github.com/evilsocket/pwnagotchi/issues/583
histogram_size = wifi.NumChannelsExt
return histogram_size, (1,
# aps per channel # aps per channel
histogram_size + histogram_size +
# clients per channel # clients per channel

View File

@ -34,10 +34,14 @@ class Environment(gym.Env):
self._epoch_num = 0 self._epoch_num = 0
self._last_render = None self._last_render = None
channels = agent.supported_channels() # see https://github.com/evilsocket/pwnagotchi/issues/583
self._supported_channels = agent.supported_channels()
self._extended_spectrum = any(ch > 140 for ch in self._supported_channels)
self._histogram_size, self._observation_shape = featurizer.describe(self._extended_spectrum)
Environment.params += [ Environment.params += [
Parameter('_channel_%d' % ch, min_value=0, max_value=1, meta=ch + 1) for ch in Parameter('_channel_%d' % ch, min_value=0, max_value=1, meta=ch + 1) for ch in
range(featurizer.histogram_size) if ch + 1 in channels range(self._histogram_size) if ch + 1 in self._supported_channels
] ]
self.last = { self.last = {
@ -50,7 +54,7 @@ class Environment(gym.Env):
} }
self.action_space = spaces.MultiDiscrete([p.space_size() for p in Environment.params if p.trainable]) self.action_space = spaces.MultiDiscrete([p.space_size() for p in Environment.params if p.trainable])
self.observation_space = spaces.Box(low=0, high=1, shape=featurizer.shape, dtype=np.float32) self.observation_space = spaces.Box(low=0, high=1, shape=self._observation_shape, dtype=np.float32)
self.reward_range = reward.range self.reward_range = reward.range
@staticmethod @staticmethod
@ -118,7 +122,7 @@ class Environment(gym.Env):
return self.last['state_v'] return self.last['state_v']
def _render_histogram(self, hist): def _render_histogram(self, hist):
for ch in range(featurizer.histogram_size): for ch in range(self._histogram_size):
if hist[ch]: if hist[ch]:
logging.info(" CH %d: %s" % (ch + 1, hist[ch])) logging.info(" CH %d: %s" % (ch + 1, hist[ch]))

View File

@ -1,4 +1,5 @@
NumChannels = 140 NumChannels = 140
NumChannelsExt = 165 # see https://github.com/evilsocket/pwnagotchi/issues/583
def freq_to_channel(freq): def freq_to_channel(freq):