cmd/

directory
v0.0.0-...-f934f63 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 17, 2024 License: GPL-3.0

README

Go CLI Programs

iotcorelogger and readtemp contain code that runs on the Raspberry Pi. iotcorelogger reads the temperature and logs it via Google Cloud IoT Core, storing the data in Google Cloud Datastore (see the Google App Engine app in the web directory).

From the root of this repository,

make

# Log temp to Google Cloud IoT Core

# Example config.pb.json
# {
#   "supported_sensors": ["mcp9808"],
#
#   "jobs": [
#     {
#       "cronspec": "0 */2 * * * *",
#       "operation": "SENSE",
#       "sensors": ["mcp9808"]
#     }
#   ]
# }
#
# Example device.json:
# {
#   "project_id": "my-gcp-project",
#   "registry_id": "my-iot-core-registry",
#   "device_id": "my-device",
#   "ca_certs_path": "roots.pem",
#   "priv_key_path": "my-device.pem",
#   "region": "us-central1"
# }
./out/iotcorelogger -config config.pb.json -gcp-device device.json

# Print temp to stdout
./out/readtemp

Prerequisites

On your development machine / where you'll build (No, you do not need to build on the Raspberry Pi! In fact it is slow and painful to do so.):

  1. Don't have Go installed? It's super easy.
  2. You'll need the protocol buffer compiler, version 3.0.0 or higher. Follow the instructions here — all you have to do is download a pre-built release for your platform and make sure the compiler, protoc, is on your PATH.
  3. You'll also need the protobuf compiler plugin that generates Go code. Follow the instructions here, or TL;DR: go get -u github.com/golang/protobuf/protoc-gen-go

On the Raspberry Pi:

wget https://pki.google.com/roots.pem

This is a set of trustworthy root certificates. See here for details. The path to this file is the value of "ca_certs_path" in the device file.

Building

From the root of this repository,

make

Simple as that. This will build the iotcorelogger program for the host architecture as well as ARMv6 (e.g. Raspberry Pi Zero W) and ARMv7 (e.g. Raspberry Pi 3 B1).

Full usage

Usage of iotcorelogger:
  -config string
      path to a file containing a JSON-encoded config proto
  -dryrun
      set to true to print rather than publish measurements
  -gcp-device string
      path to a JSON file describing a GCP IoT Core device. See github.com/mtraver/iotcore.
  -port int
      port on which the device's web server should listen (default 8080)

Footnotes

1 "How can this be!? The Raspberry Pi 3 B uses the BCM2837, a 64-bit ARMv8 SoC!" you exclaim. "That is correct," I reply, "but Raspbian is 32-bit only so the chip runs in 32-bit mode. It therefore cannot execute ARMv8 binaries."

Directories

Path Synopsis
Binary api implements the gRPC service MeasurementService.
Binary api implements the gRPC service MeasurementService.
Binary apiclient is a command line tool for calling the gRPC service MeasurementService.
Binary apiclient is a command line tool for calling the gRPC service MeasurementService.
Program iotcorelogger reads the temperature from an MCP9808 sensor and publishes it to Google Cloud IoT Core over MQTT.
Program iotcorelogger reads the temperature from an MCP9808 sensor and publishes it to Google Cloud IoT Core over MQTT.
Binary lambda is an AWS Lambda function that receives IoT telemetry messages and re-publishes them to Google Cloud Pub/Sub.
Binary lambda is an AWS Lambda function that receives IoT telemetry messages and re-publishes them to Google Cloud Pub/Sub.
Program readtemp reads the temperature from an MCP9808 sensor and prints it to stdout.
Program readtemp reads the temperature from an MCP9808 sensor and prints it to stdout.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL