damiafuentes / DJITelloPy

DJI Tello drone python interface using the official Tello SDK. Feel free to contribute!

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Strange connection errors with TelloEDU from LInux Debian 9 container on Chromebook laptop

abixadamj opened this issue · comments

I have ChromeOS:

112.0.5615.62 (Oficjalna wersja) (64-bitowa) 

And when I run scripts in Python from Pycharm:

from tello_solectric_pl import TelloEDU
import logging

print("Początek testów... tworzymy obiekt i próbujemy połączyć się, a potem pobrać podstawowe informacje...")
dron = TelloEDU(True)
TelloEDU.LOGGER.setLevel(logging.DEBUG)

if dron.connect(wait_for_state=False):
    print("Połączenie udane - rozpoczynam...")
    state = dron.get_current_state()
    print(f"{state=}")
    battery = dron.get_battery()
    temp = dron.get_temperature()
    print(f"Status: Bateria: {battery}% / Temperatura: {temp} C")
else:
    print("Połączenie nieudane - nic nie testujemy...")

print("Koniec testu")

I have created my own wrapper module tello-solectric-pl with modified :

   def connect(self, wait_for_state=True) -> bool:
        connection_success = False
        hardware_ok = False
        hardware_probe = "xxxx"

        try:
            super().connect(wait_for_state=wait_for_state)
            connection_success = True
        except Exception as e:
            print(f"Błąd przy wywołaniu CONNECT: {e}")
            return False

        hardware_probe = self.query_hardware()
        if self.hardware_type == hardware_probe:
            hardware_ok = True
            print(f"Połączono z dronem typu {self.hardware_type}")
        else:
            print(f"Otrzymano: {repr(hardware_probe)} -> nie pasuje do {self.hardware_type}")

        return connection_success and hardware_ok

I have an error:
Screenshot 2023-04-21 10 41 48

/home/adasiek/PycharmProjects/first-fly/venv/bin/python /home/adasiek/PycharmProjects/first-fly/dron_telloedu_00_logging.py 
Twoja wersja Pythona (3.9.2 (default, Feb 28 2021, 17:03:44) 
[GCC 10.2.1 20210110]) jest OK.
Początek testów... tworzymy obiekt i próbujemy połączyć się, a potem pobrać podstawowe informacje...
[INFO] tello.py - 122 - Tello instance was initialized. Host: '192.168.10.1'. Port: '8889'.
[DEBUG] tello.py - 434 - Waiting 0.016504764556884766 seconds to execute command: command...
[INFO] tello.py - 437 - Send command: 'command'
[DEBUG] tello.py - 145 - Data received from 192.168.10.1 at client_socket
[INFO] tello.py - 461 - Response command: 'ok'
[DEBUG] tello.py - 434 - Waiting 0.0003879070281982422 seconds to execute command: hardware?...
[INFO] tello.py - 437 - Send command: 'hardware?'
[DEBUG] tello.py - 145 - Data received from 192.168.10.1 at client_socket
Połączono z dronem typu TelloEDU
Połączenie udane - rozpoczynam...
state={}
[INFO] tello.py - 461 - Response hardware?: 'unknown command: hardware?'
Traceback (most recent call last):
  File "/home/adasiek/PycharmProjects/first-fly/dron_telloedu_00_logging.py", line 12, in <module>
    battery = dron.get_battery()
  File "/home/adasiek/PycharmProjects/first-fly/venv/lib/python3.9/site-packages/djitellopy/enforce_types.py", line 54, in wrapper
    return func(*args, **kwargs)
  File "/home/adasiek/PycharmProjects/first-fly/venv/lib/python3.9/site-packages/djitellopy/tello.py", line 388, in get_battery
    return self.get_state_field('bat')
  File "/home/adasiek/PycharmProjects/first-fly/venv/lib/python3.9/site-packages/djitellopy/enforce_types.py", line 54, in wrapper
    return func(*args, **kwargs)
  File "/home/adasiek/PycharmProjects/first-fly/venv/lib/python3.9/site-packages/djitellopy/tello.py", line 233, in get_state_field
    raise Exception('Could not get state property: {}'.format(key))
Exception: Could not get state property: bat

Process finished with exit code 1

It looks like there is something with connection, but I can ping 192.168.10.1from my linux containter. I think that isuue can be somewhere on a network traffic, but I don't know Chromeos so well.

An ideas and sulutiona will be as a rain on desert ;-)
Adam

The get_XXX functions use the Tello state protocol. The Tello sends UDP packets with some meta information after you have called dron.connect().

Normally the library waits for the first state packet when calling connect, but you have this disabled this using the wait_for_state=False option.
Does your program work when enabling this option?

Otherwise this might be a firewall problem with ChromeOS. You need to allow incoming UDP traffic on port 8890.
I do not have access to any ChromeOS device, but this code i found on google does not make me assume UDP traffic is allowed by default.
Your probably have to add an iptables rule manually. Maybe this stackoverflow thread helps

OK, I have resolved the issue. - the solution is to make port forwarding for UDP/8890.
Otherwise this might be a firewall problem with ChromeOS. You need to allow incoming UDP traffic on port 8890.

image