Skip to content

Commit

Permalink
Merge pull request #4 from balena-io-examples/add_examples
Browse files Browse the repository at this point in the history
Update documentation for true block implementation
  • Loading branch information
kb2ma authored Mar 9, 2022
2 parents a68d419 + b509f32 commit 15991aa
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 3 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,18 @@ Cloud Relay accepts application data via MQTT and relays it to a cloud provider'

## Getting Started

You must install the Cloud Relay container on your device as well as set up the cloud provider's IoT service. Balena also provides cloud functions for AWS, Azure and GCP that expose an HTTP endpoint to initially provision each device. See the _Cloud Provisioning_ section below.
You first must set up the cloud provider's IoT service. Balena also provides cloud functions for AWS, Azure and GCP that expose an HTTP endpoint to initially provision each device. See the _Cloud Provisioning_ section below.

### Device
We will use the docker-compose [example script](docker-compose.yml), which provides WiFi metrics data. First create a multi-container fleet in balenaCloud and provision a device with balenaOS. See the [online docs](https://www.balena.io/docs/learn/getting-started/raspberrypi3/nodejs/) for details. Next define the fleet variables from the cloud provider's setup, as described in the *Configuration* section below. Finally push the docker-compose script to the balena builders, substituting your fleet's name for `<myFleet>` in the commands below.
To setup the balena device, we will use a docker-compose [example script](doc/wifi-example/docker-compose.yml) that includes containers for generation of WiFi metrics data, an MQTT broker, and the Cloud Relay block itself. First create a multi-container fleet in balenaCloud and provision a device with balenaOS. See the [online docs](https://www.balena.io/docs/learn/getting-started/raspberrypi3/nodejs/) for details. Next define fleet variables as described in the *Configuration* section below. Finally push the docker-compose script to the balena builders, substituting your fleet's name for `<myFleet>` in the commands below.

```
git clone https://github.com/balena-io-examples/cloud-relay.git
cd cloud-relay/doc/wifi-example
balena push <myFleet>
```

After any automated cloud provisioning, you should see data flowing through the cloud relay to the provider's MQTT broker, like the log output below.
Cloud Relay first will attempt to provision the device if required, using `PROVISION_URL`. Once that completes, you should see data flowing through the cloud relay to the provider's MQTT broker, like the log output below.

```
sensor publishing sample: {} {'short_uuid': 'ab24d4b', 'quality_value': '70', 'quality_max': 70, 'signal_level': -39.0}
Expand Down
52 changes: 52 additions & 0 deletions doc/balenasense-example/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
version: '2'
volumes:
sense-data:
dashboard-data:
services:
influxdb:
restart: always
image: arm32v7/influxdb@sha256:2fed9b09a672cab330ac3ea1f03616e6821f2235bda64d549f605ef0d7081911
volumes:
- 'sense-data:/var/lib/influxdb'
dashboard:
image: balenablocks/dashboard
restart: always
volumes:
- 'dashboard-data:/data'
ports:
- '80'
sensor:
image: balenablocks/sensor
privileged: true
labels:
io.balena.features.kernel-modules: '1'
io.balena.features.sysfs: '1'
io.balena.features.supervisor-api: '1'
environment:
RAW_VALUES: '0'
COLLAPSE_FIELDS: '1'
# workaround issue balenablocks/sensor#8
MQTT_ADDRESS: 'mqtt'
depends_on:
- "mqtt"
connector:
image: balenablocks/connector
restart: always
labels:
io.balena.features.balena-api: '1'
privileged: true
ports:
- "8080"
mqtt:
image: eclipse-mosquitto:1.6.15
ports:
- "1883:1883"
restart: always
cloud-relay:
image: kb2ma/cloud-relay
restart: unless-stopped
network_mode: host
labels:
io.balena.features.supervisor-api: '1'
depends_on:
- "mqtt"
32 changes: 32 additions & 0 deletions doc/wifi-example/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Example script to push WiFi metrics to the cloud
version: '2'
services:
cloud-relay:
image: kb2ma/cloud-relay
restart: unless-stopped
network_mode: host
labels:
io.balena.features.supervisor-api: '1'
depends_on:
- "mqtt"
# collects WiFi metrics
sensor:
image: kb2ma/sensor
privileged: true
network_mode: host
labels:
io.balena.features.kernel-modules: '1'
io.balena.features.sysfs: '1'
io.balena.features.supervisor-api: '1'
depends_on:
- "mqtt"
environment:
MQTT_ADDRESS: '127.0.0.1'
RAW_VALUES: '0'
COLLAPSE_FIELDS: '1'
mqtt:
image: eclipse-mosquitto:1.6.15
restart: unless-stopped
# need host exposure for sensor service, but limit to just this host for security
ports:
- 127.0.0.1:1883:1883

0 comments on commit 15991aa

Please sign in to comment.