Jump to content
Sign in to follow this  
pty1973cm

Axis and Ohs Web API question

Recommended Posts

Hi!

To better understand whats going on especially with the new LVARS and XML Gauges, I am trying to do a basic variable interrogation loop.

(I am using Powershell for now, I may switch to something fancier later if needed).

This is the request I am trying initially:

http://x.y.z.79:9080/webapi?json={"getvars": [{"var": "AUTOPILOT_AIRSPEED_HOLD_VAR","value": 0.0}]}

And this is the response I am getting:

$result = Invoke-WebRequest -Uri "$($myUrl)" -UseBasicParsing
$result.Content

{"buttons":null,"triggers":null,"getvars":[{"var":"AUTOPILOT_AIRSPEED_HOLD_VAR","value":0.0}],"setvars":null}

I have tried with various syntax on the JSON request object... with '_' instead of spaces, and even "(A:AUTOPILOT AIRSPEED HOLD VAR, Knots)" without much success.

Two questions:

1. Is there a sub-status for the request reflecting wether the sim query itself was hit or miss, and if miss the reason (i.e., var not found)?

2. Do you have a mechanism for querying events getting triggered in the sim?

 

Share this post


Link to post
Share on other sites
1 hour ago, pty1973cm said:

(A:AUTOPILOT AIRSPEED HOLD VAR, Knots)

That is what needs to go into the "var". Fully qualified with a unit and syntax exactly like it would be called in an XML gauge. There are no underscores in variable names, only event-IDs have them. Make sure that you have actually set an airspeed to hold so you get a value different from 0. That variable may not work for all aircraft either. I usually use things like (A:PLANE LATITUDE, Degrees) to test.

1. You can check the syntax with the RPN script editor first.

2. No, sorry, AAO doesn't listen to these events. It probably could, but I'm not sure about the use case. The usual way to get that information would to query the variable that the event changes.

There are examples of the full JSON syntax in the AAO manual (last chapter).

 

Edited by Lorby_SI

LORBY-SI

Share this post


Link to post
Share on other sites
16 hours ago, Lorby_SI said:

 I usually use things like (A:PLANE LATITUDE, Degrees) to test.

There are examples of the full JSON syntax in the AAO manual (last chapter).

Thanks, yes I was/am trying to use section 14.3 from your docs as ref.

I am for some cases able to get a result by removing the "value" property from the JSON request.

Still im not getting consistent results, evidently im still missing something. 

For exampe, these work:

http://x.y.z.79:9080/webapi?json={"getvars": [{"var": "(A:PLANE LATITUDE, Degrees)"}]}
->
{"buttons":null,"triggers":null,"getvars":[{"var":"(A:PLANE LATITUDE, Degrees)","value":8.925546960368381}],"setvars":null}

http://x.y.z.79:9080/webapi?json={"getvars": [{"var": "(A:AUTOPILOT ALTITUDE LOCK VAR, Feet)","value": 0.0}]}
->
{"buttons":null,"triggers":null,"getvars":[{"var":"(A:AUTOPILOT ALTITUDE LOCK VAR, Feet)","value":5000.0}],"setvars":null}

 

But these don't:

http://x.y.z.79:9080/webapi?json={"getvars": [{"var": "(A:AUTOPILOT SPEED SETTING, UNITS_KNOTS)"}]}
->
{"buttons":null,"triggers":null,"getvars":[{"var":"(A:AUTOPILOT SPEED SETTING, UNITS_KNOTS)","value":0.0}],"setvars":null}

http://x.y.z.79:9080/webapi?json={"getvars": [{"var": "(A:AUTOPILOT ALTITUDE LOCK VAR, Feet)"}]}
->
{"buttons":null,"triggers":null,"getvars":[{"var":"(A:AUTOPILOT ALTITUDE LOCK VAR, Feet)","value":0.0}],"setvars":null}

 

Share this post


Link to post
Share on other sites
1 hour ago, pty1973cm said:

UNITS_KNOTS

This is not a valid "unit", try "Knots". Make sure that what you are writing in the structure is consistent with the syntax as per the SDK specification. 

What simulator and plane are you using? Are you certain that AUTOPILOT ALTITUDE LOCK VAR yields a result in this particular instance? Many complex aircraft ignore the default sim variables.

1 hour ago, pty1973cm said:

I am for some cases able to get a result by removing the "value" property from the JSON request.

That sounds really strange. The JSON structure is parsed by a 3rd party library, I am not doing this myself. I would expect that to fail when you break the definition.

Edit:

I've repeated your test using Powershell. If the first call doesn't yield the result, just try again. If a variable is used for the first time in a session, AAO has to establish the data collection first and can't present you with a result just yet. Every subsequent call will though (this is not an issue if you have other RPN scripts calling the same variables, even if it is just the one time). This will be improved in the next version, in v2.03 the first call should already fetch a valid result.

$result = Invoke-WebRequest -Uri "http://127.0.0.1:9080/webapi?json={'getvars':[{'var':'(A:AUTOPILOT ALTITUDE LOCK VAR, Feet)'}]}" -UseBasicParsing

$result.Content
{"buttons":null,"triggers":null,"getvars":[{"var":"(A:AUTOPILOT ALTITUDE LOCK VAR, Feet)","value":1400.0}],"setvars":null}

 

 

 

Edited by Lorby_SI

LORBY-SI

Share this post


Link to post
Share on other sites

Gotcha, I was able to reproduce the invalid result on first poll. I also noticed at least one instance where I had to restart AAO because the API was returning zero values.

About the "UNIT_KNOTS", I hear you it is not a valid unit, i used it because thats how its being reported from RPN editor .

Anyway, for the benefit of the forum here's the code I am using to poll a sample group of variables. Some of these actually are not returning the expected results, I havent investigated why.

##########################################################
# Query Sim Vars via Lorby Axis and Ohs Web API
# by https://github.com/ElSrJuez

# Polling interval (in seconds)
$Interval = 2

# Get Local NIC IP Addr
$Ip = (Get-NetIPAddress -PrefixOrigin Dhcp -AddressFamily IPv4).IPv4Address

# Add or remove variables as needed
$myvars = @(
    '(A:AUTOPILOT ALTITUDE SLOT INDEX, Number)',
    '(A:AUTOPILOT SPEED SLOT INDEX, Number)',
    '(A:AUTOPILOT HEADING SLOT INDEX, Number)',
    '(H:A320_Neo_CDU_MODE_MANAGED_HEADING, Number)',
    '(A:PLANE LATITUDE, Degrees)',
    '(A:AUTOPILOT SPEED SETTING, Knots)',
    '(A:AUTOPILOT ALTITUDE LOCK VAR, Feet)',
    '(H:A320_Neo_CDU_MODE_MANAGED_ALTITUDE, Number)'
)
$vartemplate = '"getvars": [{"var": "<simvar>","value": 0.0}],'
# Alternate JSON variable template syntax (?)
#$vartemplate = '"getvars": [{"var": "<simvar>"}],'

# Build JSON request substring
$url = "http://$($ip):9080/webapi?json={<json>}"
$json = $myVars | foreach {
    $vartemplate -replace '<simvar>',$_
}
$myUrl = $url -replace '<json>',"$json"

# Poll Variables Loop
while ($true) {
    cls
    Write-Host "Press Control-C to stop..." -ForegroundColor Cyan
    $result = Invoke-WebRequest -Uri $myUrl -UseBasicParsing
    ($result.Content | ConvertFrom-Json).getvars | 
        ft -AutoSize | Out-Host
    Start-Sleep -Seconds $Interval
}

 

Share this post


Link to post
Share on other sites
46 minutes ago, pty1973cm said:

I also noticed at least one instance where I had to restart AAO because the API was returning zero values.

That can happen when you are querying broken or invalid variables. At some point the internal data structure will get out of sync.

46 minutes ago, pty1973cm said:

Some of these actually are not returning the expected results

Define "expected" 🙂

Just a hint though: The H: variables are for writing values to (setvars, "(>H:..., Number)", usually for setting things in motion in the MSFS animation logic (= instead of doing it with the mouse). I can't remember having seen them being read from in the Asobo code, they probably don't return values at all .

If you want, send me an email or PM here with your order number, and you can have my current devel version. It should return values right away now, not always on the second try.

 

Edited by Lorby_SI
  • Like 1

LORBY-SI

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Tom Allensworth,
    Founder of AVSIM Online


  • Flight Simulation's Premier Resource!

    AVSIM is a free service to the flight simulation community. AVSIM is staffed completely by volunteers and all funds donated to AVSIM go directly back to supporting the community. Your donation here helps to pay our bandwidth costs, emergency funding, and other general costs that crop up from time to time. Thank you for your support!

    Click here for more information and to see all donations year to date.
×
×
  • Create New...