diff --git a/pokemongo_bot/__init__.py b/pokemongo_bot/__init__.py index 8d6f49a705..426877a329 100644 --- a/pokemongo_bot/__init__.py +++ b/pokemongo_bot/__init__.py @@ -112,6 +112,7 @@ def __init__(self, db, config): self.heartbeat_threshold = self.config.heartbeat_threshold self.heartbeat_counter = 0 self.last_heartbeat = time.time() + self.hb_locked = False # lock hb on snip self.capture_locked = False # lock catching while moving to VIP pokemon @@ -919,6 +920,7 @@ def login(self): level='info', formatted="Login successful." ) + self.heartbeat() def get_encryption_lib(self): if _platform == "Windows" or _platform == "win32": @@ -1263,7 +1265,7 @@ def heartbeat(self): in self.fort_timeouts.iteritems() if timeout >= now * 1000} - if now - self.last_heartbeat >= self.heartbeat_threshold: + if now - self.last_heartbeat >= self.heartbeat_threshold and not self.hb_locked: self.last_heartbeat = now request = self.api.create_request() request.get_player() @@ -1307,6 +1309,8 @@ def heartbeat(self): except Queue.Full: pass + threading.Timer(self.heartbeat_threshold, self.heartbeat).start() + def update_web_location_worker(self): while True: self.web_update_queue.get() diff --git a/pokemongo_bot/cell_workers/move_to_map_pokemon.py b/pokemongo_bot/cell_workers/move_to_map_pokemon.py index 4a4ece400a..e00183b8d2 100644 --- a/pokemongo_bot/cell_workers/move_to_map_pokemon.py +++ b/pokemongo_bot/cell_workers/move_to_map_pokemon.py @@ -276,7 +276,7 @@ def snipe(self, pokemon): pokemon: Pokemon to snipe. """ last_position = self.bot.position[0:2] - self.bot.heartbeat() + self.bot.hb_locked = True self._teleport_to(pokemon) catch_worker = PokemonCatchWorker(pokemon, self.bot, self.config) api_encounter_response = catch_worker.create_encounter_api_call() @@ -284,7 +284,7 @@ def snipe(self, pokemon): self._teleport_back(last_position) self.bot.api.set_position(last_position[0], last_position[1], self.alt, False) time.sleep(self.config.get('snipe_sleep_sec', 2)) - self.bot.heartbeat() + self.bot.hb_locked = False catch_worker.work(api_encounter_response) self.add_caught(pokemon) return WorkerResult.SUCCESS diff --git a/pokemongo_bot/cell_workers/random_alive_pause.py b/pokemongo_bot/cell_workers/random_alive_pause.py index 02c417d745..eb054e6e83 100644 --- a/pokemongo_bot/cell_workers/random_alive_pause.py +++ b/pokemongo_bot/cell_workers/random_alive_pause.py @@ -136,7 +136,6 @@ def _sleep(self): self._last_call = now return False - self.bot.heartbeat() if self.bot.config.replicate_gps_xy_noise or self.bot.config.replicate_gps_z_noise: # Adding some noise lat, lng, alt = self.bot.api.get_position() self.bot.api.set_position(lat, lng, alt) # Just set the same _actual_ values. set_position will add noise itself diff --git a/pokemongo_bot/walkers/step_walker.py b/pokemongo_bot/walkers/step_walker.py index 24aa6ea0a9..d92d7982ee 100644 --- a/pokemongo_bot/walkers/step_walker.py +++ b/pokemongo_bot/walkers/step_walker.py @@ -71,7 +71,6 @@ def step(self): 'distance_unit': '' } ) - self.bot.heartbeat() # This step is implicitlly teleporting... # and since now we have variable speeds it can be quite often that self.dist < self.speed # especially for the polyline @@ -95,7 +94,6 @@ def step(self): 'distance_unit': '' } ) - self.bot.heartbeat() sleep(1) # sleep one second plus a random delta # self._work_at_position(