Get number of satellites example

Hello,

I’m trying to get current number of satellites the ANAFI sees pre-flight via olympe and I tried the following:

import olympe
from olympe.messages.ardrone3.PilotingState import PositionChanged
from olympe.messages.ardrone3.GPSSettingsState import GPSFixStateChanged
from olympe.messages.ardrone3.Piloting import TakeOff
from olympe.messages.ardrone3.GPSSettingsState import HomeChanged
from olympe.messages.ardrone3.GPSState import NumberOfSatelliteChanged
drone= olympe.Drone("192.168.42.1", loglevel=1)
drone.connection()    

# Wait for GPS fix
drone(GPSFixStateChanged(_policy = 'wait'))

print("GPS position before take-off :", drone.get_state(HomeChanged))
print("GPS number of satellites changed: ", drone.get_state(NumberOfSatelliteChanged))

This is the relevant part of the log, that says that GPSState.NumberofSatelliteChanged State is uninitialized. Is it only initialized after it gets a fix?

RuntimeError: Unknown message id 2432696335
GPS position before take-off : OrderedDict([('latitude', 500.0), ('longitude', 500.0), ('altitude', 500.0)])
Traceback (most recent call last):
  File "ref_guiTest.py", line 152, in <module>
    print("GPS number of satellites changed: ", drone.get_state(NumberOfSatelliteChanged))
  File "/home/marcel/code/parrot-groundsdk/packages/olympe/src/olympe/arsdkng/drone.py", line 1424, in get_state
    return self._get_message(message.id).state()
  File "/home/marcel/code/parrot-groundsdk/packages/olympe/src/olympe/arsdkng/messages.py", line 950, in state
    raise RuntimeError("{} state is uninitialized".format(self.fullName))
RuntimeError: ardrone3.GPSState.NumberOfSatelliteChanged state is uninitialized

@Jerome @ndessart can you suggest what to about the State is uninitialised error? How do we solve it?

@hellowtisch can you upload the whole console output?
By any chance are the following or similar lines present in the console before the error that you have showed above.

I arsdkctrl: discovery 'net': remove device name='ANAFI-0000000' id='000000000000000000'
I arsdkctrl: internally disconnect device name='ANAFI-0000000' type=ANAFI4K id='000000000000000000'
I arsdkctrl: discovery 'net': stop

Also Can you try running the following script instead and sharing if it worked for you.

import olympe
from olympe.messages.ardrone3.PilotingState import PositionChanged
from olympe.messages.ardrone3.GPSSettingsState import GPSFixStateChanged
from olympe.messages.ardrone3.Piloting import TakeOff
from olympe.messages.ardrone3.GPSSettingsState import HomeChanged
from olympe.messages.ardrone3.GPSState import NumberOfSatelliteChanged
drone= olympe.Drone("192.168.42.1", loglevel=1)
drone.connection()    

# Wait for GPS fix
drone(GPSFixStateChanged(_policy = 'wait'))
while True:
  print("GPS position before take-off :", drone.get_state(HomeChanged))
  print("GPS number of satellites changed: ", drone.get_state(NumberOfSatelliteChanged)["numberOfSatellite"])

@cPabz: thanks, your script worked.
The connection was not disconnected before!