Added MQTT reporting of profile changes and SDR status changes.
This commit is contained in:
parent
50c10a6a7c
commit
ea055a746e
|
|
@ -95,12 +95,12 @@ class ReportingController(SettingsFormController):
|
||||||
"MQTT settings",
|
"MQTT settings",
|
||||||
CheckboxInput(
|
CheckboxInput(
|
||||||
"mqtt_enabled",
|
"mqtt_enabled",
|
||||||
"Enable publishing decodes to MQTT",
|
"Enable publishing reports to MQTT",
|
||||||
),
|
),
|
||||||
TextInput(
|
TextInput(
|
||||||
"mqtt_host",
|
"mqtt_host",
|
||||||
"Broker address",
|
"Broker address",
|
||||||
infotext="Addresss of the MQTT broker to send decodes to (address[:port])",
|
infotext="Addresss of the MQTT broker to send reports to (address[:port])",
|
||||||
validator=AddressAndOptionalPortValidator(),
|
validator=AddressAndOptionalPortValidator(),
|
||||||
),
|
),
|
||||||
TextInput(
|
TextInput(
|
||||||
|
|
@ -125,7 +125,7 @@ class ReportingController(SettingsFormController):
|
||||||
TextInput(
|
TextInput(
|
||||||
"mqtt_topic",
|
"mqtt_topic",
|
||||||
"MQTT topic",
|
"MQTT topic",
|
||||||
infotext="MQTT topic to publish decodes to (default: openwebrx/decodes)",
|
infotext="MQTT topic to publish reports to (default: openwebrx)",
|
||||||
converter=OptionalConverter(),
|
converter=OptionalConverter(),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class MqttReporter(Reporter):
|
class MqttReporter(Reporter):
|
||||||
DEFAULT_TOPIC = "openwebrx/decodes"
|
DEFAULT_TOPIC = "openwebrx"
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
pm = Config.get()
|
pm = Config.get()
|
||||||
|
|
|
||||||
|
|
@ -17,8 +17,10 @@ from owrx.form.input.converter import Converter, OptionalConverter, IntConverter
|
||||||
from owrx.form.input.device import GainInput, SchedulerInput, WaterfallLevelsInput
|
from owrx.form.input.device import GainInput, SchedulerInput, WaterfallLevelsInput
|
||||||
from owrx.form.input.validator import RequiredValidator, Range, RangeValidator, RangeListValidator
|
from owrx.form.input.validator import RequiredValidator, Range, RangeValidator, RangeListValidator
|
||||||
from owrx.form.section import OptionalSection
|
from owrx.form.section import OptionalSection
|
||||||
|
from owrx.reporting import ReportingEngine
|
||||||
from owrx.feature import FeatureDetector
|
from owrx.feature import FeatureDetector
|
||||||
from owrx.log import LogPipe, HistoryHandler
|
from owrx.log import LogPipe, HistoryHandler
|
||||||
|
from datetime import datetime
|
||||||
from typing import List
|
from typing import List
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
|
|
||||||
|
|
@ -274,6 +276,17 @@ class SdrSource(ABC):
|
||||||
profile_name = self.getProfiles()[profile_id]["name"]
|
profile_name = self.getProfiles()[profile_id]["name"]
|
||||||
self.logger.debug("activating profile \"%s\" for \"%s\"", profile_name, self.getName())
|
self.logger.debug("activating profile \"%s\" for \"%s\"", profile_name, self.getName())
|
||||||
self.profileCarousel.switch(profile_id)
|
self.profileCarousel.switch(profile_id)
|
||||||
|
# Report profile changes
|
||||||
|
ReportingEngine.getSharedInstance().spot({
|
||||||
|
"mode" : "RX",
|
||||||
|
"timestamp" : round(datetime.now().timestamp() * 1000),
|
||||||
|
"source_id" : self.id,
|
||||||
|
"source" : self.getName(),
|
||||||
|
"profile_id" : profile_id,
|
||||||
|
"profile" : profile_name,
|
||||||
|
"freq" : self.props["center_freq"],
|
||||||
|
"samplerate" : self.props["samp_rate"]
|
||||||
|
})
|
||||||
except KeyError:
|
except KeyError:
|
||||||
self.logger.warning("invalid profile %s for sdr %s. ignoring", profile_id, self.getId())
|
self.logger.warning("invalid profile %s for sdr %s. ignoring", profile_id, self.getId())
|
||||||
|
|
||||||
|
|
@ -566,8 +579,18 @@ class SdrSource(ABC):
|
||||||
return self.state
|
return self.state
|
||||||
|
|
||||||
def setState(self, state: SdrSourceState):
|
def setState(self, state: SdrSourceState):
|
||||||
|
# Drop out if state has not changed
|
||||||
if state == self.state:
|
if state == self.state:
|
||||||
return
|
return
|
||||||
|
# Report state changes
|
||||||
|
ReportingEngine.getSharedInstance().spot({
|
||||||
|
"mode" : "RX",
|
||||||
|
"timestamp" : round(datetime.now().timestamp() * 1000),
|
||||||
|
"source_id" : self.id,
|
||||||
|
"source" : self.getName(),
|
||||||
|
"state" : str(state)
|
||||||
|
})
|
||||||
|
# Update state and broadcast to clients
|
||||||
self.state = state
|
self.state = state
|
||||||
for c in self.clients.copy():
|
for c in self.clients.copy():
|
||||||
c.onStateChange(state)
|
c.onStateChange(state)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue