Using Olympe connect with real drone to run the hello example

Hi, I have a error when running this code

import logging
import olympe
import olympe.log
import os
import pprint
from olympe.controller import Disconnected
from olympe.messages.common.Common import Reboot
from olympe.messages import mission

DRONE_IP = os.environ.get("DRONE_IP", "192.168.42.1")
ELLO_MISSION_URL = os.environ.get("HELLO_MISSION_URL", "/home/domo/code/airsdk-samples/hello/.airsdk/out/hello-classic/images/com.parrot.missions.samples.hello.tar.gz")

olympe.log.update_config({"loggers": {"olympe": {"level": "INFO"}}})
logger = logging.getLogger("olympe")


def test_hello_mission():
drone = olympe.Drone(DRONE_IP)
with drone.mission.from_path(HELLO_MISSION_URL).open() as hello:
    # Mission messages modules are now available from the Python path
    from olympe.airsdk.messages.parrot.missions.samples.hello.Command import Say, Hold
    from olympe.airsdk.messages.parrot.missions.samples.hello.Event import count

    # Mission messages are also available under the Mission.messages dictionary
    assert hello.messages["parrot.missions.samples.hello"].Command.Say is Say
    assert hello.messages["parrot.missions.samples.hello"].Event.count is count

    # Install the 'hello' mission and reboot the drone
    assert drone.connect()
    assert hello.install(allow_overwrite=True)
    logger.info("Mission list: " + pprint.pformat(drone.mission.list_remote()))
    assert drone(Reboot() >> Disconnected()).wait()

    # Connect to the drone after reboot, load and activate the 'hello' mission
    assert drone.connect(retry=5)
    assert hello.wait_ready(5)

    # wait for the current mission to be activated
    mission_activated = drone(mission.state(state="active"))
    assert mission_activated.wait(), mission_activated.explain()

    logger.info("Mission list: " + pprint.pformat(drone.mission.list_remote()))

    # load and activate the hello mission
    mission_activated = drone(
        mission.load(uid=hello.uid)
        >> mission.activate(uid=hello.uid)
    )
    assert mission_activated.wait(), mission_activated.explain()

    # Make the drone say hello (nod its gimbal)
    assert drone(Say()).wait()
    counter = None

    # Wait for 3 nod of the drone gimbal
    for i in range(3):
        if counter is None:
            expectation = drone(count(_policy="wait")).wait(_timeout=10)
            assert expectation, expectation.explain()
            counter = expectation.received_events().last().args["value"]
        else:
            counter += 1
            expectation = drone(count(value=counter)).wait(_timeout=10)
            assert expectation, expectation.explain()

    # Stop and disconnect
    assert drone(Hold()).wait()
    expectation = drone(count(_policy="wait", _timeout=15)).wait()
    assert not expectation, expectation.explain()
    assert drone(count(value=counter, _policy="check"))
    assert drone.disconnect()

if __name__ == "__main__":
    test_hello_mission()

Here is the log message:

2023-09-06 01:25:04,664 [INFO] 	olympe.backend - _create_pomp_loop - Creating pomp loop
2023-09-06 01:25:04,665 [INFO] 	olympe.backend - _do_create - device callbacks have been added to arsdk_ctrl
2023-09-06 01:25:04,666 [INFO] 	olympe.scheduler - _create_pomp_loop - Creating pomp loop
2023-09-06 01:25:04,671 [INFO] 	olympe.media - _create_pomp_loop - Creating pomp loop
2023-09-06 01:25:04,786 [INFO] 	olympe.missions - _open - Opening mission 'com.parrot.missions.samples.hello' multiple times
2023-09-06 01:25:04,812 [INFO] 	olympe.backend - _device_added_cb - DiscoveryNet: New device has been detected: 'ANAFI Ai 002107'
2023-09-06 01:25:04,815 [INFO] 	olympe.drone - _connecting_cb - Connecting to device: ANAFI Ai 002107
2023-09-06 01:25:04,815 [INFO] 	olympe.drone - _connect_impl - Connection in progress...
2023-09-06 01:25:04,832 [INFO] 	olympe.drone.ANAFI Ai 002107 - _aconnected_cb - Connected to device: ANAFI Ai 002107
2023-09-06 01:25:04,832 [INFO] 	olympe.drone.ANAFI Ai 002107 - _aconnected_cb - {'c2d_port': 2233,
 'c2d_update_port': 51,
 'c2d_user_port': 21,
 'proto_v': 3,
 'qos_mode': 0,
 'status': 0}
2023-09-06 01:25:04,832 [INFO] 	olympe.drone.ANAFI Ai 002107 - _create_command_interface - Command interface has been created
2023-09-06 01:25:04,835 [INFO] 	olympe.drone.ANAFI Ai 002107 - _send_command_impl - common.Common.CurrentDateTime(datetime='20230906T012504-0700') has been sent to the device
2023-09-06 01:25:04,846 [INFO] 	olympe.drone.ANAFI Ai 002107 - _send_command_impl - common.Common.AllStates() has been sent to the device
2023-09-06 01:25:05,349 [WARNING] 	olympe.drone.ANAFI Ai 002107 - _on_sync_done - Time synchronization failed for b'192.168.42.1'
2023-09-06 01:25:09,833 [INFO] 	olympe.drone.ANAFI Ai 002107 - _link_quality_cb - Link quality: tx=0, rx=-1, rx_useful=-1
2023-09-06 01:25:10,794 [ERROR] 	olympe.drone.ANAFI Ai 002107 - connect - '192.168.42.1 connection timed out
2023-09-06 01:25:10,795 [ERROR] 	olympe.drone.ANAFI Ai 002107 - _cmd_itf_cmd_send_status_cb - Command send status cancel/timeout: common.Common.CurrentDateTime ARSDK_CMD_ITF_CMD_SEND_STATUS_CANCELED, done: True
2023-09-06 01:25:10,796 [ERROR] 	olympe.drone.ANAFI Ai 002107 - _cmd_itf_cmd_send_status_cb - Command send status cancel/timeout: common.Common.AllStates ARSDK_CMD_ITF_CMD_SEND_STATUS_CANCELED, done: True
2023-09-06 01:25:10,796 [INFO] 	olympe.drone.ANAFI Ai 002107 - _disconnected_cb - Disconnected from device: ANAFI Ai 002107
2023-09-06 01:25:10,798 [ERROR] 	olympe.drone.ANAFI Ai 002107 - _do_connect - '192.168.42.1 connection retries failed
2023-09-06 01:25:10,801 [INFO] 	olympe.drone.ANAFI Ai 002107 - _on_device_removed - <olympe.arsdkng.cmd_itf.DisconnectedEvent object at 0x7f995a7dd580>
2023-09-06 01:25:10,802 [INFO] 	olympe.media - _websocket_event_reader - websocket closed
2023-09-06 01:25:10,803 [INFO] 	olympe.drone.ANAFI Ai 002107 - disconnect - Disconnection with the device OK. IP: b'192.168.42.1'
Traceback (most recent call last):
  File "/home/domo/code/airsdk-samples/hello/hello.py", line 77, in <module>
    test_hello_mission()
  File "/home/domo/code/airsdk-samples/hello/hello.py", line 31, in test_hello_mission
    assert drone.connect()
AssertionError
2023-09-06 01:25:10,843 [INFO] 	olympe.drone.ANAFI Ai 002107 - _on_device_removed - <olympe.arsdkng.cmd_itf.DisconnectedEvent object at 0x7f9973bdaaf0>
2023-09-06 01:25:10,844 [ERROR] 	olympe.media - _get_all_media - Unhandled exception
Traceback (most recent call last):
  File "/home/domo/code/parrot-olympe/out/olympe-linux/staging/usr/lib/python/site-packages/olympe/concurrent/_task.py", line 132, in step
    result = self._coro.send(None)
StopIteration: ConnectionClosed()

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/domo/code/parrot-olympe/out/olympe-linux/staging/usr/lib/python/site-packages/olympe/media.py", line 2041, in _get_all_media
    data = await response.json()
  File "/home/domo/code/parrot-olympe/out/olympe-linux/staging/usr/lib/python/site-packages/olympe/http.py", line 196, in json
    return json.loads(await self.text())
  File "/home/domo/code/parrot-olympe/out/olympe-linux/pyenv_root/versions/3.9.5/lib/python3.9/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
  File "/home/domo/code/parrot-olympe/out/olympe-linux/pyenv_root/versions/3.9.5/lib/python3.9/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/home/domo/code/parrot-olympe/out/olympe-linux/pyenv_root/versions/3.9.5/lib/python3.9/json/decoder.py", line 353, in raw_decode
    obj, end = self.scan_once(s, idx)
json.decoder.JSONDecodeError: Expecting ':' delimiter: line 1 column 1461 (char 1460)
2023-09-06 01:25:10,844 [WARNING] 	olympe.media - aconnect - Media are not yet indexed
2023-09-06 01:25:10,845 [INFO] 	olympe.scheduler - _destroy_pomp_loop - Pomp loop has been destroyed: subscribers_thread
2023-09-06 01:25:11,046 [INFO] 	olympe.backend - _destroy_pomp_loop - Pomp loop has been destroyed: Thread-3
2023-09-06 01:25:12,805 [INFO] 	olympe.media - _destroy_pomp_loop - Pomp loop has been destroyed: Thread-4

Is there any way to fix the problem? Thanks for your help.

Can you ping 192.168.42.1?

There are 2 ways to connect. Direct wifi with ip 192.168.42.1 and via SkyController with ip 192.168.53.1. Which one you used?

If you are using direct wifi check in ubuntu if you see the connection symbol in Networks. You need a password for connection.

Yes, I can ping 192.168.42.1.

image

I used direct wifi with ip 192.168.42.1.

Also I’m using Ubuntu in VMware, will this matter?

I have no personal experience with parrot via vmware but this seems to be a similar problem. Maybe @jinwandou can help you more.

https://forum.developer.parrot.com/t/connect-to-physical-anafi-via-olympe-on-ubuntu16-04-installed-on-vmware-failed/9702/6

Solution changed network from “NAT” to “bridged”

1 Like

Thanks for the information, it works for me.

Then, I got another error is about too many ping failures.

2023-09-07 22:32:54,842 [INFO] 	olympe.drone.ANAFI Ai 002107 - _send_command_impl - common.Common.Reboot() has been sent to the device
2023-09-07 22:32:55,036 [INFO] 	olympe.drone.ANAFI Ai 002107 - _recv_cmd_cb - common.NetworkEvent.Disconnection(cause='unknown')
2023-09-07 22:32:59,200 [INFO] 	olympe.drone.ANAFI Ai 002107 - _link_quality_cb - Link quality: tx=50, rx=100, rx_useful=100
2023-09-07 22:32:59,427 [ERROR] 	ulog - pomp - read(fd=25) err=110(Connection timed out)
2023-09-07 22:32:59,428 [INFO] 	olympe.media - _websocket_event_reader - websocket closed
2023-09-07 22:33:03,037 [ERROR] 	ulog - arsdk - net Too many ping failures
2023-09-07 22:33:03,037 [INFO] 	olympe.drone.ANAFI Ai 002107 - _link_status_cb - Link status: 0
2023-09-07 22:33:03,037 [INFO] 	olympe.pdraw.ANAFI Ai 002107 - _destroy_pomp_loop - Pomp loop has been destroyed: Thread-5
2023-09-07 22:33:03,038 [INFO] 	olympe.drone.ANAFI Ai 002107 - _disconnected_cb - Disconnected from device: ANAFI Ai 002107
2023-09-07 22:33:03,039 [INFO] 	olympe.drone.ANAFI Ai 002107 - _on_device_removed - <olympe.arsdkng.cmd_itf.DisconnectedEvent object at 0x7f05efcf4ac0>
2023-09-07 22:33:03,040 [INFO] 	olympe.drone.ANAFI Ai 002107 - _on_device_removed - <olympe.arsdkng.cmd_itf.DisconnectedEvent object at 0x7f05ee22afa0>
2023-09-07 22:33:23,045 [INFO] 	olympe.drone.ANAFI Ai 002107 - _async_discover_device - Net discovery failed for b'192.168.42.1'
2023-09-07 22:33:23,045 [INFO] 	olympe.drone.ANAFI Ai 002107 - _async_discover_device - Trying 'NetRaw' discovery for b'192.168.42.1' ...
2023-09-07 22:33:26,797 [INFO] 	olympe.drone.ANAFI Ai 002107 - _async_get_device - Unable to discover the device: b'192.168.42.1'
2023-09-07 22:33:33,041 [ERROR] 	olympe.drone.ANAFI Ai 002107 - connect - '192.168.42.1 connection timed out
2023-09-07 22:33:33,042 [INFO] 	olympe.drone.ANAFI Ai 002107 - disconnect - Disconnection with the device OK. IP: b'192.168.42.1'
Traceback (most recent call last):
  File "/home/domo/code/airsdk-samples/hello/hello.py", line 77, in <module>
    test_hello_mission()
  File "/home/domo/code/airsdk-samples/hello/hello.py", line 37, in test_hello_mission
    assert drone.connect(retry=5)
AssertionError
2023-09-07 22:33:33,080 [INFO] 	olympe.drone.ANAFI Ai 002107 - _on_device_removed - <olympe.arsdkng.cmd_itf.DisconnectedEvent object at 0x7f060370c070>
2023-09-07 22:33:33,081 [INFO] 	olympe.scheduler - _destroy_pomp_loop - Pomp loop has been destroyed: subscribers_thread
2023-09-07 22:33:33,253 [ERROR] 	olympe.backend - _cleanup - Deferred cleanup action are still pending after 3.0s
2023-09-07 22:33:33,253 [WARNING] 	olympe.backend - _cleanup - Futures still running: 1
2023-09-07 22:33:33,254 [INFO] 	olympe.backend - _destroy_pomp_loop - Pomp loop has been destroyed: Thread-3
2023-09-07 22:33:33,383 [INFO] 	olympe.media - _destroy_pomp_loop - Pomp loop has been destroyed: Thread-4

Is there any solution? Thanks for your help.

I’ve figured out the reason, because the hello mission will restart the drone, so I have to reconnect the wifi in time.

Then, the hello mission works!

Hopes this message can help other people who use VMware.

1 Like

Yes, some people hat similar problems with docker too.

if you are waiting for reestablishing of network you can raise the time for waiting after reboot here.

 assert hello.wait_ready(5)

or raise the number of retries here.

    assert drone.connect(retry=5)
1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.