odwdinc / Python-SimConnect

Python interface for MSFS2020 SimConnect.dll
GNU Affero General Public License v3.0
276 stars 105 forks source link

Set weather via SimConnect_WeatherSetObservation METAR string? #83

Closed vamshichittaluri closed 3 years ago

vamshichittaluri commented 3 years ago

Hello all,

Hope you are all well. I know through SimVars we cannot set the weather for the simulator. However, as seen in the attributes.py and simconnect function, i saw that we should be able to set METAR string weather(c++) implementation.

    # SIMCONNECTAPI SimConnect_WeatherSetObservation(
    #   HANDLE hSimConnect,
    #   DWORD Seconds
    #   const char * szMETAR);
    self.WeatherSetObservation = self.SimConnect.SimConnect_WeatherSetObservation
    self.WeatherSetObservation.restype = HRESULT
    self.WeatherSetObservation.argtypes = [HANDLE, DWORD, c_char_p]

Can anyone guide me how to send the METAR string, i dont mean the actual string format, but synatx etc.

Kind Regards Vamshi

vamshichittaluri commented 3 years ago

Sooo I figured out i can access the function through:

sim.dll.WeatherSetObservation(sim.hSimConnect, 2, "CYXU METAR 271700Z 320002KTS 9999M R24R/5203FT R24L/420340 SCT006 OVC019 -02/-03 Q1021")

but i get the following error: ctypes.ArgumentError: argument 3: <class 'TypeError'>: wrong type

I am guessing my first argument is wrong? Any idea on where I am loosing it?

Kind Regards Vamshi

odwdinc commented 3 years ago

Needs to be byte string aka

sim.dll.WeatherSetObservation(sim.hSimConnect, 2, b"CYXU METAR 271700Z 320002KTS 9999M R24R/5203FT R24L/420340 SCT006 OVC019 -02/-03 Q1021")

or

msg = "CYXU METAR 271700Z 320002KTS 9999M R24R/5203FT R24L/420340 SCT006 OVC019 -02/-03 Q1021"
sim.dll.WeatherSetObservation(sim.hSimConnect, 2, msg.encode())
vamshichittaluri commented 3 years ago

Ahh! Awesome! Thanks Odwdinc! Works now.