From 47ce70a70eb62ad17cb5b57db75cffeba7d802b9 Mon Sep 17 00:00:00 2001 From: "Alex Ellis (OpenFaaS Ltd)" Date: Tue, 10 Dec 2019 16:20:41 +0000 Subject: [PATCH] Enable Emitter.io These changes allow emmitter.io to be used to trigger functions. Signed-off-by: Alex Ellis (OpenFaaS Ltd) --- chart/mqtt-connector/templates/deployment.yml | 3 +++ chart/mqtt-connector/values.yaml | 7 ++++++- main.go | 12 ++++++++---- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/chart/mqtt-connector/templates/deployment.yml b/chart/mqtt-connector/templates/deployment.yml index a0b378b..2209124 100644 --- a/chart/mqtt-connector/templates/deployment.yml +++ b/chart/mqtt-connector/templates/deployment.yml @@ -57,6 +57,9 @@ spec: {{- if .Values.authPassword }} - "-password={{.Values.authPassword}}" {{- end }} + {{- if .Values.trimChannelKey }} + - "-trim-channel-key={{.Values.trimChannelKey}}" + {{- end }} env: - name: gateway_url value: {{ .Values.gateway_url | quote }} diff --git a/chart/mqtt-connector/values.yaml b/chart/mqtt-connector/values.yaml index 894a4e7..2bf3977 100644 --- a/chart/mqtt-connector/values.yaml +++ b/chart/mqtt-connector/values.yaml @@ -1,7 +1,12 @@ -image: alexellis2/mqtt-connector:0.1.4 +image: alexellis2/mqtt-connector:0.1.5 replicas: 1 +# Emitter.io example +#topic: CHANNEL_KEY/drone-position/?ttl=1200 + +# Formal MQTT topic example: topic: drone-position + # For use with emitter.io trimChannelKey: false diff --git a/main.go b/main.go index 3d84ac5..ea2a92d 100644 --- a/main.go +++ b/main.go @@ -19,10 +19,12 @@ import ( func main() { var gatewayUsername, gatewayPassword, gatewayFlag string + var trimChannelKey bool flag.StringVar(&gatewayUsername, "gw-username", "", "Username for the gateway") flag.StringVar(&gatewayPassword, "gw-password", "", "Password for gateway") flag.StringVar(&gatewayFlag, "gateway", "", "gateway") + flag.BoolVar(&trimChannelKey, "trim-channel-key", false, "Trim channel key when using emitter.io MQTT broker") topic := flag.String("topic", "", "The topic name to/from which to publish/subscribe") broker := flag.String("broker", "tcp://iot.eclipse.org:1883", "The broker URI. ex: tcp://10.10.1.1:1883") @@ -102,12 +104,14 @@ func main() { topic := incoming[0] data := []byte(incoming[1]) - if strings.Contains(incoming[1], "sensor") { + if trimChannelKey { + index := strings.Index(topic, "/") + topic = topic[index+1:] + } - log.Printf("Invoking (%s) on topic: %q, value: %q\n", gatewayURL, topic, data) + log.Printf("Invoking (%s) on topic: %q, value: %q\n", gatewayURL, topic, data) - controller.Invoke(topic, &data) - } + controller.Invoke(topic, &data) receiveCount++ }