Skip to content

Commit 47ce70a

Browse files
committed
Enable Emitter.io
These changes allow emmitter.io to be used to trigger functions. Signed-off-by: Alex Ellis (OpenFaaS Ltd) <[email protected]>
1 parent 3a95e34 commit 47ce70a

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

chart/mqtt-connector/templates/deployment.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ spec:
5757
{{- if .Values.authPassword }}
5858
- "-password={{.Values.authPassword}}"
5959
{{- end }}
60+
{{- if .Values.trimChannelKey }}
61+
- "-trim-channel-key={{.Values.trimChannelKey}}"
62+
{{- end }}
6063
env:
6164
- name: gateway_url
6265
value: {{ .Values.gateway_url | quote }}

chart/mqtt-connector/values.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1-
image: alexellis2/mqtt-connector:0.1.4
1+
image: alexellis2/mqtt-connector:0.1.5
22
replicas: 1
33

4+
# Emitter.io example
5+
#topic: CHANNEL_KEY/drone-position/?ttl=1200
6+
7+
# Formal MQTT topic example:
48
topic: drone-position
9+
510
# For use with emitter.io
611
trimChannelKey: false
712

main.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@ import (
1919
func main() {
2020

2121
var gatewayUsername, gatewayPassword, gatewayFlag string
22+
var trimChannelKey bool
2223

2324
flag.StringVar(&gatewayUsername, "gw-username", "", "Username for the gateway")
2425
flag.StringVar(&gatewayPassword, "gw-password", "", "Password for gateway")
2526
flag.StringVar(&gatewayFlag, "gateway", "", "gateway")
27+
flag.BoolVar(&trimChannelKey, "trim-channel-key", false, "Trim channel key when using emitter.io MQTT broker")
2628

2729
topic := flag.String("topic", "", "The topic name to/from which to publish/subscribe")
2830
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() {
102104
topic := incoming[0]
103105
data := []byte(incoming[1])
104106

105-
if strings.Contains(incoming[1], "sensor") {
107+
if trimChannelKey {
108+
index := strings.Index(topic, "/")
109+
topic = topic[index+1:]
110+
}
106111

107-
log.Printf("Invoking (%s) on topic: %q, value: %q\n", gatewayURL, topic, data)
112+
log.Printf("Invoking (%s) on topic: %q, value: %q\n", gatewayURL, topic, data)
108113

109-
controller.Invoke(topic, &data)
110-
}
114+
controller.Invoke(topic, &data)
111115

112116
receiveCount++
113117
}

0 commit comments

Comments
 (0)