Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drone.core.connection_state() cycles between returns multiple incorrect values #738

Open
rgreenaus opened this issue Dec 5, 2024 · 0 comments
Labels

Comments

@rgreenaus
Copy link

I am under the impression drone.core.connection_state() returns a ConnectionState object which contains a single boolean variable is_connected which will be true if there is an active telemetry connection to the drone, and false otherwise.

I am writing a class to abstract away some of the telemetry code and need a member variable to indicate whether there is an active connection. e.g. the following code:

async def connect_to_drone(self):
    self.drone = System()
    await self.drone.connect(system_address=self.system_address) 
    self.logger.info('connected to telemetry via serial')
    while True:
        async for state in self.drone.core.connection_state():
            if state.is_connected:
                self.logger.info('drone metrics object connected to drone')
                self.is_connected = True
            if not state.is_connected:
                self.logger.info('drone metrics object disconnected to drone')
                self.is_connected = False
        await asyncio.sleep(1)

My expectation is this code would check the connection state at a rate of ~once per second, and the self.is_connected variable would remain true as long as there is a maintained connection. Instead the logs show the response from drone.core.connection_state() repeatedly flips even when maintaining a stable connection:

INFO : drone_api : drone metrics object connected to telemetry via serial : 2024-12-05 17:42:59,852
INFO : drone_api : drone metrics object connected to drone : 2024-12-05 17:42:59,864
INFO : drone_api : drone metrics object disconnected to drone : 2024-12-05 17:42:59,870
INFO : drone_api : drone metrics object disconnected to drone : 2024-12-05 17:42:59,874
INFO : drone_api : drone metrics object connected to drone : 2024-12-05 17:42:59,878
INFO : drone_api : drone metrics object disconnected to drone : 2024-12-05 17:42:59,882
INFO : drone_api : drone metrics object disconnected to drone : 2024-12-05 17:42:59,886
INFO : drone_api : drone metrics object disconnected to drone : 2024-12-05 17:43:03,357
INFO : drone_api : drone metrics object disconnected to drone : 2024-12-05 17:43:03,361
INFO : drone_api : drone metrics object disconnected to drone : 2024-12-05 17:43:03,364
INFO : drone_api : drone metrics object connected to drone : 2024-12-05 17:43:06,140
INFO : drone_api : drone metrics object disconnected to drone : 2024-12-05 17:43:06,147
INFO : drone_api : drone metrics object disconnected to drone : 2024-12-05 17:43:06,151
INFO : drone_api : drone metrics object disconnected to drone : 2024-12-05 17:43:09,148
INFO : drone_api : drone metrics object disconnected to drone : 2024-12-05 17:43:09,152
INFO : drone_api : drone metrics object disconnected to drone : 2024-12-05 17:43:09,156
INFO : drone_api : drone metrics object connected to drone : 2024-12-05 17:43:09,327
INFO : drone_api : drone metrics object disconnected to drone : 2024-12-05 17:43:09,335
INFO : drone_api : drone metrics object disconnected to drone : 2024-12-05 17:43:09,339
INFO : drone_api : drone metrics object disconnected to drone : 2024-12-05 17:43:20,152
INFO : drone_api : drone metrics object disconnected to drone : 2024-12-05 17:43:20,156
INFO : drone_api : drone metrics object disconnected to drone : 2024-12-05 17:43:20,160
INFO : drone_api : drone metrics object connected to drone : 2024-12-05 17:43:21,154
INFO : drone_api : drone metrics object disconnected to drone : 2024-12-05 17:43:21,160
....

It appears like the iterative returned by drone.core.connection_state() when there is an active connection contains 6 boolean values in the sequence [False, False, False, True, False, False]

This doesn't seem like the intended functionality.

@julianoes julianoes added the bug label Dec 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants