Skip to content

Commit 1391a31

Browse files
committed
Implement GCP Cloud IoT Core integration.
1 parent 380a01f commit 1391a31

File tree

25 files changed

+1037
-678
lines changed

25 files changed

+1037
-678
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,6 @@
1414

1515
# dependencies
1616
/vendor
17+
18+
# certificates
19+
/certs

Gopkg.lock

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,7 @@
4444
[[override]]
4545
version = "v1.1.0"
4646
name = "github.com/golang/protobuf"
47+
48+
[[constraint]]
49+
name = "github.com/dgrijalva/jwt-go"
50+
version = "3.2.0"

cmd/lora-gateway-bridge/cmd/configfile.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ skip_crc_check = {{ .PacketForwarder.SkipCRCCheck }}
7878
# LoRa Server MQTT backend. Therefore only change these values when
7979
# absolutely needed.
8080
# Use "{{ "{{ .MAC }}" }}" as an substitution for the LoRa gateway MAC.
81+
#
82+
# Note that some authentication types might overwrite these templates (e.g.
83+
# in case of GCP Cloud IoT Core)!
8184
uplink_topic_template="{{ .Backend.MQTT.UplinkTopicTemplate }}"
8285
downlink_topic_template="{{ .Backend.MQTT.DownlinkTopicTemplate }}"
8386
stats_topic_template="{{ .Backend.MQTT.StatsTopicTemplate }}"
@@ -154,6 +157,41 @@ marshaler="{{ .Backend.MQTT.Marshaler }}"
154157
max_reconnect_interval="{{ .Backend.MQTT.Auth.Generic.MaxReconnectInterval }}"
155158
156159
160+
# Google Cloud Platform Cloud IoT Core authentication.
161+
#
162+
# Please note that when using this authentication type, the MQTT topics
163+
# will be automatically set to match the MQTT topics as expected by
164+
# Cloud IoT Core.
165+
[backend.mqtt.auth.gcp_cloud_iot_core]
166+
# MQTT server.
167+
server="{{ .Backend.MQTT.Auth.GCPCloudIoTCore.Server }}"
168+
169+
# Google Cloud IoT Core Device id.
170+
device_id="{{ .Backend.MQTT.Auth.GCPCloudIoTCore.DeviceID }}"
171+
172+
# Google Cloud project id.
173+
project_id="{{ .Backend.MQTT.Auth.GCPCloudIoTCore.ProjectID }}"
174+
175+
# Google Cloud region.
176+
cloud_region="{{ .Backend.MQTT.Auth.GCPCloudIoTCore.CloudRegion }}"
177+
178+
# Google Cloud IoT registry id.
179+
registry_id="{{ .Backend.MQTT.Auth.GCPCloudIoTCore.RegistryID }}"
180+
181+
# JWT token expiration time.
182+
jwt_expiration="{{ .Backend.MQTT.Auth.GCPCloudIoTCore.JWTExpiration }}"
183+
184+
# JWT token key-file.
185+
#
186+
# Example command to generate a key-pair:
187+
# $ ssh-keygen -t rsa -b 4096 -f private-key.pem
188+
# $ openssl rsa -in private-key.pem -pubout -outform PEM -out public-key.pem
189+
#
190+
# Then point the setting below to the private-key.pem and associate the
191+
# public-key.pem with this device / gateway in Google Cloud IoT Core.
192+
jwt_key_file="{{ .Backend.MQTT.Auth.GCPCloudIoTCore.JWTKeyFile }}"
193+
194+
157195
# Metrics configuration.
158196
[metrics]
159197

cmd/lora-gateway-bridge/cmd/root.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,13 @@ func init() {
8181

8282
viper.SetDefault("backend.mqtt.marshaler", "v2_json")
8383
viper.SetDefault("backend.mqtt.auth.type", "generic")
84+
8485
viper.SetDefault("backend.mqtt.auth.generic.server", "tcp://127.0.0.1:1883")
8586
viper.SetDefault("backend.mqtt.auth.generic.clean_session", true)
8687
viper.SetDefault("backend.mqtt.auth.generic.max_reconnect_interval", 10*time.Minute)
8788

88-
viper.SetDefault("metrics.prometheus.bind", "")
89+
viper.SetDefault("backend.mqtt.auth.gcp_cloud_iot_core.server", "ssl://mqtt.googleapis.com:8883")
90+
viper.SetDefault("backend.mqtt.auth.gcp_cloud_iot_core.jwt_expiration", time.Hour*24)
8991

9092
rootCmd.AddCommand(versionCmd)
9193
rootCmd.AddCommand(configCmd)

cmd/lora-gateway-bridge/cmd/root_run.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cmd
22

33
import (
4+
"fmt"
45
"net/http"
56
"os"
67
"os/signal"
@@ -56,6 +57,10 @@ func run(cmd *cobra.Command, args []string) error {
5657
}()
5758

5859
if config.C.Backend.MQTT.Marshaler == "v2_json" {
60+
if config.C.Backend.MQTT.Auth.Type != "generic" {
61+
return fmt.Errorf("auth type '%s' can not be used with 'v2_json' marshaler", config.C.Backend.MQTT.Auth.Type)
62+
}
63+
5964
return runV2(cmd, args)
6065
}
6166
return runV3(cmd, args)

docs/config.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ pygmentsUseClasses = true
1919
weight = 2
2020

2121
[[menu.main]]
22-
pre = "<i class='fas fa-user'></i>"
23-
name = "Use"
24-
identifier = "use"
25-
url = "/use/"
22+
pre = "<i class='fas fa-code'></i>"
23+
name = "Integrate"
24+
identifier = "integrate"
25+
url = "/integrate/"
2626
weight = 3
2727

2828
[[menu.main]]

docs/content/install/config.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,9 @@ skip_crc_check = false
142142
# LoRa Server MQTT backend. Therefore only change these values when
143143
# absolutely needed.
144144
# Use "{{ .MAC }}" as an substitution for the LoRa gateway MAC.
145+
#
146+
# Note that some authentication types might overwrite these templates (e.g.
147+
# in case of GCP Cloud IoT Core)!
145148
uplink_topic_template="gateway/{{ .MAC }}/rx"
146149
downlink_topic_template="gateway/{{ .MAC }}/tx"
147150
stats_topic_template="gateway/{{ .MAC }}/stats"
@@ -218,6 +221,41 @@ marshaler="v2_json"
218221
max_reconnect_interval="10m0s"
219222

220223

224+
# Google Cloud Platform Cloud IoT Core authentication.
225+
#
226+
# Please note that when using this authentication type, the MQTT topics
227+
# will be automatically set to match the MQTT topics as expected by
228+
# Cloud IoT Core.
229+
[backend.mqtt.auth.gcp_cloud_iot_core]
230+
# MQTT server.
231+
server="ssl://mqtt.googleapis.com:8883"
232+
233+
# Google Cloud IoT Core Device id.
234+
device_id=""
235+
236+
# Google Cloud project id.
237+
project_id=""
238+
239+
# Google Cloud region.
240+
cloud_region=""
241+
242+
# Google Cloud IoT registry id.
243+
registry_id=""
244+
245+
# JWT token expiration time.
246+
jwt_expiration="24h0m0s"
247+
248+
# JWT token key-file.
249+
#
250+
# Example command to generate a key-pair:
251+
# $ ssh-keygen -t rsa -b 4096 -f private-key.pem
252+
# $ openssl rsa -in private-key.pem -pubout -outform PEM -out public-key.pem
253+
#
254+
# Then point the setting below to the private-key.pem and associate the
255+
# public-key.pem with this device / gateway in Google Cloud IoT Core.
256+
jwt_key_file=""
257+
258+
221259
# Metrics configuration.
222260
[metrics]
223261

docs/content/install/gateway/_index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ description: Instructions on how to install the LoRa Gateway Bridge component on
1111
# Gateway installation & configuration
1212

1313
For Raspberry Pi / Rasbian based gateways, please refer the
14-
[Debian / Ubuntu]({{< ref "install/debian.md" >}}) installation instructions.
14+
[Debian / Ubuntu]({{< ref "/install/debian.md" >}}) installation instructions.
1515

1616
## Contribute to this list
1717

docs/content/install/gateway/kerlink.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ These steps will install the LoRa Gateway Bridge ARM build on the Kerlink.
2222
{{< /highlight >}}
2323

2424
2. Download and extract the LoRa Gateway Bridge ARM binary into the above
25-
directory. See [downloads]({{< ref "overview/downloads.md" >}}).
25+
directory. See [downloads]({{< ref "/overview/downloads.md" >}}).
2626
Make sure the binary is marked as executable.
2727

2828
3. Save the following content as `/mnt/fsuser-1/lora-gateway-bridge/start.sh`:

0 commit comments

Comments
 (0)