diff options
| author | Noah Stride <[email protected]> | 2024-02-01 00:28:09 +0000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2024-01-31 14:28:09 -1000 |
| commit | 463760ccf1cb99f387f5bf99ed83e31772744671 (patch) | |
| tree | 99feec624d4f04542e0c4aaab037b4e0b937a9f4 /mqtt | |
| parent | 202889338e29c416e810de888734a2d41c6b1069 (diff) | |
Rough initial radio emulator (#1)
* Super rough initial subscription to channels and sending node info
* Very ugly hacky FromRadio subscription
* Add more TODOs :weary:
* Add log message before we try to broadcast NodeInfo
* Add basic positioning broadcasting
* demo sending message from consumer
* Use const for BroadcastNodeID
* Config validation and defaults
* Tidy up examples/TODOs
* Tidy up example
* Handle position and devicetelemetry updates
* Fix dodgy merge
* Allow configuring interval for nodeinfo/position seperately
* Make broadcasted position configurable
* Add MQTTProtoTopic constant rather than modifying topic root
* Allow altitude of broadcasted position to be configured
* static check ignore
Diffstat (limited to 'mqtt')
| -rw-r--r-- | mqtt/client.go | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/mqtt/client.go b/mqtt/client.go index c3746b5..eff4736 100644 --- a/mqtt/client.go +++ b/mqtt/client.go @@ -9,6 +9,8 @@ import ( "time" ) +const MQTTProtoTopic = "/2/c/" + type Client struct { server string username string @@ -108,11 +110,13 @@ func (c *Client) Handle(channel string, h HandlerFunc) { c.channelHandlers[channel] = append(c.channelHandlers[channel], h) c.client.Subscribe(topic+"/+", 0, c.handleBrokerMessage) } + func (c *Client) GetFullTopicForChannel(channel string) string { - return c.topicRoot + "/c/" + channel + return c.topicRoot + MQTTProtoTopic + channel } + func (c *Client) GetChannelFromTopic(topic string) string { - trimmed := strings.TrimPrefix(topic, c.topicRoot+"/c/") + trimmed := strings.TrimPrefix(topic, c.topicRoot+MQTTProtoTopic) sepIndex := strings.Index(trimmed, "/") if sepIndex > 0 { return trimmed[:sepIndex] |
