Skip to content

Commit

Permalink
Enable Emitter.io
Browse files Browse the repository at this point in the history
These changes allow emmitter.io to be used to trigger functions.

Signed-off-by: Alex Ellis (OpenFaaS Ltd) <[email protected]>
  • Loading branch information
alexellis committed Dec 10, 2019
1 parent 3a95e34 commit 47ce70a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
3 changes: 3 additions & 0 deletions chart/mqtt-connector/templates/deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
7 changes: 6 additions & 1 deletion chart/mqtt-connector/values.yaml
Original file line number Diff line number Diff line change
@@ -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

Expand Down
12 changes: 8 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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++
}
Expand Down

0 comments on commit 47ce70a

Please sign in to comment.