2022-11-05 21:27:33 +00:00
|
|
|
# -*- coding: UTF-8 -*-
|
|
|
|
"""
|
|
|
|
Created on 05.11.23
|
|
|
|
|
|
|
|
@author: DJ2LS
|
|
|
|
"""
|
|
|
|
# pylint: disable=invalid-name, line-too-long, c-extension-no-member
|
|
|
|
# pylint: disable=import-outside-toplevel, attribute-defined-outside-init
|
|
|
|
|
|
|
|
import requests
|
|
|
|
import threading
|
2024-02-28 19:01:26 +00:00
|
|
|
import json
|
2022-11-05 21:27:33 +00:00
|
|
|
import structlog
|
2024-01-11 13:39:53 +00:00
|
|
|
import sched
|
|
|
|
import time
|
2022-11-05 21:27:33 +00:00
|
|
|
|
|
|
|
log = structlog.get_logger("explorer")
|
|
|
|
|
|
|
|
class explorer():
|
2024-02-02 18:37:02 +00:00
|
|
|
def __init__(self, modem_version, config_manager, states):
|
|
|
|
self.modem_version = modem_version
|
|
|
|
|
|
|
|
self.config_manager = config_manager
|
|
|
|
self.config = self.config_manager.read()
|
2023-11-12 22:22:53 +00:00
|
|
|
self.states = states
|
2023-02-02 10:53:52 +00:00
|
|
|
self.explorer_url = "https://api.freedata.app/explorer.php"
|
2022-11-05 21:27:33 +00:00
|
|
|
|
|
|
|
def push(self):
|
2024-02-02 18:37:02 +00:00
|
|
|
self.config = self.config_manager.read()
|
2022-11-05 21:27:33 +00:00
|
|
|
|
2023-11-17 22:33:30 +00:00
|
|
|
frequency = 0 if self.states.radio_frequency is None else self.states.radio_frequency
|
2022-11-05 21:27:33 +00:00
|
|
|
band = "USB"
|
2023-12-03 18:16:09 +00:00
|
|
|
callsign = str(self.config['STATION']['mycall']) + "-" + str(self.config["STATION"]['myssid'])
|
2023-11-13 16:40:46 +00:00
|
|
|
gridsquare = str(self.config['STATION']['mygrid'])
|
2024-02-02 18:37:02 +00:00
|
|
|
version = str(self.modem_version)
|
2024-03-25 07:28:02 +00:00
|
|
|
bandwidth = str(self.config['MODEM']['maximum_bandwidth'])
|
2023-11-12 22:22:53 +00:00
|
|
|
beacon = str(self.states.is_beacon_running)
|
2024-01-12 20:44:31 +00:00
|
|
|
strength = str(self.states.s_meter_strength)
|
2024-04-13 11:03:56 +00:00
|
|
|
away_from_key = str(self.states.is_away_from_key)
|
2022-11-05 21:27:33 +00:00
|
|
|
|
2024-02-02 06:26:01 +00:00
|
|
|
# stop pushing if default callsign
|
|
|
|
if callsign in ['XX1XXX-6']:
|
|
|
|
return
|
|
|
|
|
2024-02-10 10:05:10 +00:00
|
|
|
# disabled this one
|
|
|
|
# log.info("[EXPLORER] publish", frequency=frequency, band=band, callsign=callsign, gridsquare=gridsquare, version=version, bandwidth=bandwidth)
|
2022-11-05 21:27:33 +00:00
|
|
|
|
|
|
|
headers = {"Content-Type": "application/json"}
|
2024-04-13 11:03:56 +00:00
|
|
|
station_data = {'callsign': callsign, 'gridsquare': gridsquare, 'frequency': frequency, 'strength': strength, 'band': band, 'version': version, 'bandwidth': bandwidth, 'beacon': beacon, "lastheard": [], "away_from_key": away_from_key}
|
2022-12-26 20:14:23 +00:00
|
|
|
|
2023-11-17 22:33:30 +00:00
|
|
|
for i in self.states.heard_stations:
|
2022-12-27 09:37:34 +00:00
|
|
|
try:
|
2023-12-03 18:16:09 +00:00
|
|
|
callsign = i[0]
|
|
|
|
grid = i[1]
|
2023-01-05 14:28:41 +00:00
|
|
|
timestamp = i[2]
|
2023-04-22 09:02:40 +00:00
|
|
|
frequency = i[6]
|
2022-12-27 10:33:16 +00:00
|
|
|
try:
|
|
|
|
snr = i[4].split("/")[1]
|
|
|
|
except AttributeError:
|
|
|
|
snr = str(i[4])
|
2023-04-22 09:02:40 +00:00
|
|
|
station_data["lastheard"].append({"callsign": callsign, "grid": grid, "snr": snr, "timestamp": timestamp, "frequency": frequency})
|
2022-12-27 09:37:34 +00:00
|
|
|
except Exception as e:
|
|
|
|
log.debug("[EXPLORER] not publishing station", e=e)
|
2022-12-26 20:14:23 +00:00
|
|
|
|
2022-11-05 21:27:33 +00:00
|
|
|
station_data = json.dumps(station_data)
|
|
|
|
try:
|
|
|
|
response = requests.post(self.explorer_url, json=station_data, headers=headers)
|
|
|
|
|
|
|
|
except Exception as e:
|
|
|
|
log.warning("[EXPLORER] connection lost")
|