Skip to content
A Go client for Google IoT Core
Go Shell
Branch: master
Clone or download
Latest commit 4859fc7 Nov 9, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
examples Added support for eliptic curve keys. Apr 2, 2018
paho Do not log error if EOF (#2) Oct 24, 2019
test_keys Added support for eliptic curve keys. Apr 2, 2018
tools Added support for eliptic curve keys. Apr 2, 2018
.gitignore Initial commit Mar 8, 2018
LICENSE
README.md Updated README.md Nov 8, 2019
example_mock_test.go Changed package of examples to make go vet happy. Mar 29, 2018
example_thing_test.go Added support for eliptic curve keys. Apr 2, 2018
iot.go Fix comment Apr 6, 2018
iot_test.go Re-subscribe to config topic on reconnect. Apr 6, 2018
mock.go Re-subscribe to config topic on reconnect. Apr 6, 2018
thing.go

README.md

IoT

A simple framework for implementing a Google IoT device.

This package makes use of the context package to handle request cancelation, timeouts, and deadlines.

gocover.io Go Report Card Go Docs Mentioned in Awesome Go

Copyright 2018, Andrew C. Young <andrew@vaelen.org>

License: MIT

Here is an example showing how to use this library:

package main

import (
	"context"
	"log"
	"github.com/vaelen/iot"
	// Your client must include the paho package
	// to use the default Eclipse Paho MQTT client.
	_ "github.com/vaelen/iot/paho"
)

func main() {
	ctx := context.Background()

	id := &iot.ID{
		DeviceID:  "deviceName",
		Registry:  "my-registry",
		Location:  "asia-east1",
		ProjectID: "my-project",
	}

	credentials, err := iot.LoadRSACredentials("rsa_cert.pem", "rsa_private.pem")
	if err != nil {
		panic("Couldn't load credentials")
	}

	options := iot.DefaultOptions(id, credentials)
	options.DebugLogger = log.Println
	options.InfoLogger = log.Println
	options.ErrorLogger = log.Println
	options.ConfigHandler = func(thing iot.Thing, config []byte) {
		// Do something here to process the updated config and create an updated state string
		state := []byte("ok")
		thing.PublishState(ctx, state)
	}

	thing := iot.New(options)

	err = thing.Connect(ctx, "ssl://mqtt.googleapis.com:443")
	if err != nil {
		panic("Couldn't connect to server")
	}
	defer thing.Disconnect(ctx)

	// This publishes to /events
	thing.PublishEvent(ctx, []byte("Top level telemetry event"))
	// This publishes to /events/a
	thing.PublishEvent(ctx, []byte("Sub folder telemetry event"), "a")
	// This publishes to /events/a/b
	thing.PublishEvent(ctx, []byte("Sub folder telemetry event"), "a", "b")
}

Thanks to Infostellar for supporting my development of this project.

You can’t perform that action at this time.