junzis / pyModeS

Python decoder for Mode S and ADS-B signals
GNU General Public License v3.0
527 stars 151 forks source link

Dumping weather data live to file #124

Open guidocioni opened 2 years ago

guidocioni commented 2 years ago

Hi, I'm trying to decode weather data (temperature, winds, pressure...) from ADS-B messages and dump it to file. I already have a working installation of dump1090-fa and can see the data by connecting with modeslive to the beast port (modeslive --source net --connect 127.0.0.1 30005 beast).

The question is..how can I connect and stream the data directly using the python module to a file using the Meteorological reports [Experimental] section functions?

I'm currently looking into the source of modeslive, and could probably build something using that, but I was wondering whether maybe you already have some example written with this scope in mind and wanted to avoid reinventing the wheel :D

Thanks

junzis commented 1 year ago

hi, you can use this example code that process a specific type of messages in your code: https://github.com/junzis/pyModeS#customize-the-streaming-module

guidocioni commented 1 year ago

Thanks. In the end I could decode easily temperature, winds and pressure readings but the part about latitude and longitude was too complicated to port it. So I just adapted the code for modeslive to allow for decoding of weather data (from https://github.com/junzis/pyModeS/blob/bb8f83e8328e36df203d238db09fe242a4ff0700/pyModeS/streamer/decode.py#L190)

        # process commb message
           ........
            if bds == "BDS50":
                ...
                winds = pms.commb.wind44(msg)     # Wind speed (kt) and direction (true) (deg)
                temp = pms.commb.temp44(msg)     # Static air temperature (C)
                pres = pms.commb.p44(msg)        # Average static pressure (hPa)
                hum = pms.commb.hum44(msg)      # Humidity (%)

added it to the output_buffer and filter the dump to CSV (from https://github.com/junzis/pyModeS/blob/bb8f83e8328e36df203d238db09fe242a4ff0700/pyModeS/streamer/decode.py#L253)

        if self.dumpto is not None:
            dh = str(datetime.datetime.now().strftime("%Y%m%d_%H"))
            fn = self.dumpto + "/pymodes_dump_%s.csv" % dh
            output_buffer.sort(key=lambda x: x[0])
            # filter output buffer
            # only take acs with 3D position
            if self.acs[icao]["lon"] and self.acs[icao]["lat"] and self.acs[icao]["alt"]:
                # only print interesting variables
                output_buffer = [o for o in output_buffer 
                                          if o[2] in ["winds","temp","pres", "hum","lat","lon","alt"]]
                with open(fn, "a") as f:
                    writer = csv.writer(f)
                    writer.writerows(output_buffer)

That seems to work well for now.

guidocioni commented 1 year ago

Ok, actually now I understood that the meteorological variables need a BDS44, which seems to never appear in my messages because it hasn't been implemented yet.

Is there any way to use pyModeS to extract temperature and winds from the wind speed, heading, etc... ?