Board index FlightGear Support Flying

METAR not working

Controlling your aircraft, using the autopilot etc.

Re: METAR not working

Postby SurferTim » Wed Feb 06, 2019 12:12 pm

This is my python3 server code.
Code: Select all
import socket
import ssl
from http.server import BaseHTTPRequestHandler,HTTPServer

def send_request(myself, req):
  if(req == '/favicon.ico'):
    print('favicon.ico')
    return

  station = req[4:]
  hostname = 'tgftp.nws.noaa.gov'
  protocol = 'GET http://'
  page = protocol + hostname + station + ' HTTP/1.1\r\nHost: ' +hostname + '\r\nConnection: close\r\nContent-Type: text/plain\r\n\r\n'
  context = ssl.create_default_context()

  print(page)

  with socket.create_connection((hostname, 443)) as sock:
      with context.wrap_socket(sock, server_hostname=hostname) as ssock:
        ssock.sendall(page.encode())
        while(1):
            receivedMsg = ssock.recv(1024)
#            print(receivedMsg)
            if(len(receivedMsg) == 0):
                ssock.close()
                break
            myself.wfile.write(receivedMsg)

class RequestHandler(BaseHTTPRequestHandler):
    def do_GET(self):
        result = send_request(self,self.path)

#----------------------------------------------------------------------

if __name__ == '__main__':
    serverAddress = ('127.0.0.1', 8080)
    server = HTTPServer(serverAddress, RequestHandler)
    server.serve_forever()

I saved it as server.py.
Run it with
Code: Select all
python3 server.py

Use this link in a web browser to test it. I used Firefox.
http://127.0.0.1:8080/////data/observat ... s/KSFO.TXT
Note 5 slashes after 8080. It should display KSFO weather. If so, it is working.

BEFORE YOU GO ANY FURTHER: Copy your original fgfs executable out of harm's way as a backup in case of problems.

Edit the fgfs executable with a binary (HEX) editor, I used ghex from the Ubuntu repository.
Search for "http://t". You will find this string:
http://tgftp.nws.noaa.gov/data/observat ... /stations/
Edit it to this:
http://127.0.0.1:8080/////data/observat ... /stations/
Ensure you don't insert new text. Overwrite only. Note the five slashes. Don't worry. The server.py code removes them.
Save.

I guarantee nothing. It works for me on Ubuntu 18.04.
Fly low. Fly slow. Land on a dime. Twin Otter. https://github.com/SurferTim/dhc6p
My other aircraft is a Citation-X https://github.com/SurferTim/CitationX
PirateAir videos at https://www.youtube.com/user/SurferTim850
User avatar
SurferTim
 
Posts: 1718
Joined: Sun Dec 09, 2018 6:49 pm
Location: Miramar Beach, FL
Callsign: Pirate
Version: 2020.4.0
OS: Ubuntu 18.04

Re: METAR not working

Postby StuartC » Wed Feb 06, 2019 3:35 pm

Enrogue has produced a fix for the Broken METAR function.


Full details and download :-


http://www.fguk.eu/index.php/hangar/dow ... g-2018-3-2
StuartC
 
Posts: 3179
Joined: Fri Jun 18, 2010 9:18 pm
Location: Arse end of the Universe
Callsign: WF01
Version: 2019.1
OS: W10 64 bit

Re: METAR not working

Postby enrogue » Wed Feb 06, 2019 3:48 pm

Note: I didn't create the patch, I just applied the one created by Lenard & compiled with MSVC 2017 - the binary will only work on 64bit windows, and I've only tested it on Win 10 1809

The binary also has a new feature from next enabled - the YASim stiction feature/fix

YMMV
User avatar
enrogue
 
Posts: 294
Joined: Mon May 19, 2014 7:40 pm
Location: London (UK)
Callsign: enrogue
OS: Ubuntu, macOS

Re: METAR not working

Postby wkitty42 » Wed Feb 06, 2019 5:26 pm

lbartik wrote in Tue Feb 05, 2019 6:42 pm:I can tell you how not to fix it quick and dirty.

I tried editing FGFS.exe for windows with a hex editor by inserting an "s" character at offset E9F57C and deleting a NULL character at E9F5B4.

yeah, that won't work because this is C and strings in C generally have to end with a null character... without it, the string system doesn't know where the end of the string is... the only ways to fix this is in the code which also points out that older versions of FG will not be able to get METAR data because they either don't know how to https or they don't know how to follow redirects or both... in other words, folks will have to upgrade FG versions at some point thanks to 3rd party external services that are needed/used...
"You get more air close to the ground," said Angalo. "I read that in a book. You get lots of air low down, and not much when you go up."
"Why not?" said Gurder.
"Dunno. It's frightened of heights, I guess."
User avatar
wkitty42
 
Posts: 9161
Joined: Fri Feb 20, 2015 4:46 pm
Location: central NC, USA
Callsign: wk42
Version: git next
OS: Kubuntu 22.04

Re: METAR not working

Postby V12 » Wed Feb 06, 2019 5:32 pm

I will test python solution ASAP...

EDIT :
SurferTim, big thank You for solution, works perfectly. I made short test flight with UFO from Sint Maarten to Barbados, FG downloaded all weather data along route flawless. Tested with FG 2018.3.1 on LUbuntu 18.04.

Image
Fly high, fly fast - fly Concorde !
V12
 
Posts: 2757
Joined: Thu Jan 12, 2017 5:27 pm
Location: LZIB
Callsign: BAWV12

Re: METAR not working

Postby lbartik » Wed Feb 06, 2019 6:31 pm

wkitty42 wrote in Wed Feb 06, 2019 5:26 pm:yeah, that won't work because this is C and strings in C generally have to end with a null character... without it, the string system doesn't know where the end of the string is... the only ways to fix this is in the code which also points out that older versions of FG will not be able to get METAR data because they either don't know how to https or they don't know how to follow redirects or both... in other words, folks will have to upgrade FG versions at some point thanks to 3rd party external services that are needed/used...


There are actually (13) NULL characters following this text string in the broken FGFS.EXE. I deleted one of them to preserve the file size. Maybe the text string character length is fixed in the compiled EXE just like it is in a C string declaration?
lbartik
 
Posts: 7
Joined: Wed Nov 14, 2018 8:46 pm

Re: METAR not working

Postby lbartik » Wed Feb 06, 2019 6:38 pm

enrogue wrote in Wed Feb 06, 2019 3:48 pm:Note: I didn't create the patch, I just applied the one created by Lenard & compiled with MSVC 2017 - the binary will only work on 64bit windows, and I've only tested it on Win 10 1809

The binary also has a new feature from next enabled - the YASim stiction feature/fix

YMMV

StuartC wrote in Wed Feb 06, 2019 3:35 pm:Enrogue has produced a fix for the Broken METAR function.


Full details and download :-


http://www.fguk.eu/index.php/hangar/dow ... g-2018-3-2


Appreciate it. I couldn't get it to run on x64 Windows 10 1803.

Error message: [This application failed to start because it could not find or load the Qt platform plugin "windows" in "", Available platform plugins are: windows. Reinstalling the application may fix this problem.]
lbartik
 
Posts: 7
Joined: Wed Nov 14, 2018 8:46 pm

Re: METAR not working

Postby SurferTim » Wed Feb 06, 2019 6:52 pm

After considerable testing, it appears the fgfs program expects that URL to be exactly that length. If it isn't, it does not append the airport ident correctly.

The good part about the external python server is that I (you) can redirect the request to anywhere, including a personal weather server.

@V12: Thanks for the report. I'm a big fan of flying around the Caribbean. Barbados has not been a destination yet, but soon! St. Maarten, Guadeloupe, Martinique, Virgin Islands, and Puerto Rico are my current favs. The real time weather ensures the flights are never the same.
Fly low. Fly slow. Land on a dime. Twin Otter. https://github.com/SurferTim/dhc6p
My other aircraft is a Citation-X https://github.com/SurferTim/CitationX
PirateAir videos at https://www.youtube.com/user/SurferTim850
User avatar
SurferTim
 
Posts: 1718
Joined: Sun Dec 09, 2018 6:49 pm
Location: Miramar Beach, FL
Callsign: Pirate
Version: 2020.4.0
OS: Ubuntu 18.04

Re: METAR not working

Postby jtprophet » Wed Feb 06, 2019 8:50 pm

Yeah I am getting the same error that lbartik received.
jtprophet
 
Posts: 210
Joined: Mon Apr 04, 2016 3:21 pm
Callsign: DAL1464

Re: METAR not working

Postby mathieugouin » Wed Feb 06, 2019 9:56 pm

Thanks SurferTim for the idea! This was clever!

I built on your idea and published on my google app engine a piece of code that perform the same action.

Similar procedure to hex edit the binary executable for fgfs. But no need to have the local webserver running.

The final string should be (notice the long name to match exactly the original length of the URL)

Code: Select all
http://mgouin.appspot.com/fg?icao-station-identifier-name1=


FG will append the station, ex KSFO.TXT to get something like this:

Code: Select all
http://mgouin.appspot.com/fg?icao-station-identifier-name1=KSFO.TXT


Thanks
Mathieu
mathieugouin
 
Posts: 36
Joined: Thu Jan 06, 2011 4:37 am
Location: CYHU
Callsign: MGOUIN
Version: V2018.1.1
OS: Lubuntu 18.04

Re: METAR not working

Postby lbartik » Thu Feb 07, 2019 12:50 am

Thanks mathieugouin, your URL works magically.
lbartik
 
Posts: 7
Joined: Wed Nov 14, 2018 8:46 pm

Re: METAR not working

Postby Alant » Thu Feb 07, 2019 1:24 am

The devel email list is also looking at this, and coming up with rather diferent findings and solutons. I have alerted them to the recent posts here.

Alan
Alant
 
Posts: 1223
Joined: Wed Jun 23, 2010 6:58 am
Location: Portugal
Callsign: Tarnish99
Version: latest Git
OS: Windows 10/11

Re: METAR not working

Postby charlie_x249 » Thu Feb 07, 2019 4:02 am

Where do I put the patch ?
My dreams don't lie down there, But when I looked to the sky, I saw my dreams
charlie_x249
 
Posts: 4
Joined: Tue Oct 09, 2018 4:02 am
Location: Mumbai, India
Callsign: CHX09
Version: 2018.3.2
OS: Windows 10.1

Re: METAR not working

Postby SurferTim » Thu Feb 07, 2019 1:00 pm

charlie_x249 wrote in Thu Feb 07, 2019 4:02 am:Where do I put the patch ?

Which patch? If mine with the python code, the python script just needs to be run prior to starting your flightgear program.
I have a Windows 10 disk for my computer. If I get a chance today, I'll check it out for you.

Edit: The fgfs modified program should be placed where your original executable was. Ensure you copy your executable file as a backup in case the edit goes wrong. It did go wrong for me a couple times during testing.
Fly low. Fly slow. Land on a dime. Twin Otter. https://github.com/SurferTim/dhc6p
My other aircraft is a Citation-X https://github.com/SurferTim/CitationX
PirateAir videos at https://www.youtube.com/user/SurferTim850
User avatar
SurferTim
 
Posts: 1718
Joined: Sun Dec 09, 2018 6:49 pm
Location: Miramar Beach, FL
Callsign: Pirate
Version: 2020.4.0
OS: Ubuntu 18.04

Re: METAR not working

Postby enrogue » Thu Feb 07, 2019 1:06 pm

If you're downloading the Win 10 bin zip from FGUK, you'll need an existing 2018.3.2 install, then extract *only* fgfs.exe from the zip file & place it in your flightgear bin directory (back up the original fgfs.exe by renaming it first)

Apologies but the bin wasn't meant to be distributed just yet - I hadn't fully tested it on a new install
User avatar
enrogue
 
Posts: 294
Joined: Mon May 19, 2014 7:40 pm
Location: London (UK)
Callsign: enrogue
OS: Ubuntu, macOS

PreviousNext

Return to Flying

Who is online

Users browsing this forum: No registered users and 5 guests