A Go client for Google IoT Core

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 <[email protected]>

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.

Owner
Andrew Young
I'm a software engineer and manager who dabbles in all sorts of random languages. I am currently a Software Engineering Manager at Indeed in Tokyo, Japan.
Andrew Young
Similar Resources

A opinionated multi-tenant hyperscale Internet of Things platform to connect IoT devices fast and securely with minimal TCO

infinimesh IoT Platform infinimesh is a opinionated multi-tenant hyperscale Internet of Things platform to connect IoT devices fast and securely with

Feb 14, 2022

Exploring and comparing different IOT messaging protocols / transports.

IOT Messaging Protocols Blynk https://blynk.io/ A fully integrated suite of IoT software Device provisioning Sensor data visualization Remote control

Jan 2, 2022

IoT platform with things/user management and visualization, in Go with Docker using microservices

BARIOT IoT platform to Manage Users and their Things and visualize their data. Microservices services architecture build with Go and docker (compose).

Jun 22, 2022

An extensive Philips Hue client library for Go with an emphasis on simplicity

An extensive Philips Hue client library for Go with an emphasis on simplicity

Huego An extensive Philips Hue client library for Go with an emphasis on simplicity. It is designed to be clean, unbloated and extensible. With Huego

Dec 28, 2022

handle multiple mqtt server/cluster based on paho client

pakhshi Introduction Consider you have an array of brokers but you want to publish and subscribe on all of them at the same time. Why you may need thi

Nov 9, 2022

Courier Golang client library provides an opinionated wrapper over paho MQTT library to add features on top of it

Courier Golang Client Library Introduction Courier Golang client library provides an opinionated wrapper over paho MQTT library to add features on top

Nov 19, 2022

IoT Manager: use IoT platforms with Mender

Mender: Azure IoT Manager: use Azure IoT with Mender General Mender is an open source over-the-air (OTA) software updater for embedded Linux devices.

Jan 10, 2022

Data Connector is a Google Sheets Add-on that lets you import (and export) data to/from Google Sheets

Data Connector Data Connector is a Google Sheets Add-on that lets you import (and export) data to/from Google Sheets. Our roadmap: Connect to JSON/XML

Jul 30, 2022

Jacket of google/wire: advanced DI approach wrapping google/wire for cloud.

Jacket of google/wire: advanced DI approach wrapping google/wire for cloud.

Wire-Jacket: IoC Container of google/wire for cloud-native Jacket of google/wire: advanced DI approach wrapping google/wire for cloud. google/wire : h

Nov 21, 2022

Telegram + Google Sheet daily routine trackerTelegram + Google Sheet daily routine tracker

Telegram + Google Sheet daily routine tracker Deploy as serverless function Fork this repository and set secrets github secrets: API_DOMAIN - your ver

Oct 13, 2021

GC2 is a Command and Control application that allows an attacker to execute commands on the target machine using Google Sheet and exfiltrate data using Google Drive.

GC2 is a Command and Control application that allows an attacker to execute commands on the target machine using Google Sheet and exfiltrate data using Google Drive.

GC2 GC2 (Google Command and Control) is a Command and Control application that allows an attacker to execute commands on the target machine using Goog

Dec 13, 2022

Go-based search engine URL collector , support Google, Bing, can be based on Google syntax batch collection URL

Go-based search engine URL collector , support Google, Bing, can be based on Google syntax batch collection URL

Go-based search engine URL collector , support Google, Bing, can be based on Google syntax batch collection URL

Nov 9, 2022

Correct the timestamp of photo/video of Google Photo from Google takeout

Correct Timestamp of Google Photo from Google Takeout Development Environment: Ubuntu 20.04 Go 1.17 Usage Require Go 1.16 or later to build. go build

Sep 9, 2022

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Yandex Files

Website | Documentation | Download | Contributing | Changelog | Installation | Forum Rclone Rclone ("rsync for cloud storage") is a command-line progr

Jan 9, 2023

Google-pay-decryptor - Google Pay payload decryptor Tool

Google Pay Decryptor Tool Tired of looking for information about cryptography an

Mar 20, 2022

Fast specialized time-series database for IoT, real-time internet connected devices and AI analytics.

Fast specialized time-series database for IoT, real-time internet connected devices and AI analytics.

unitdb Unitdb is blazing fast specialized time-series database for microservices, IoT, and realtime internet connected devices. As Unitdb satisfy the

Jan 1, 2023

An Open-Source Platform for Quantified Self & IoT

An Open-Source Platform for Quantified Self & IoT

Heedy Note: Heedy is currently in alpha. You can try it out by downloading it from the releases page, but there is no guarantee that future versions w

Jan 1, 2023

Suite of libraries for IoT devices (written in Go), experimental for x/exp/io

Go libraries/drivers for IoT devices This repo contains a suite of libraries for IoT devices/sensors/actuators. The suite is meant to be as dependency

Sep 26, 2022

Make IoT a lot more fun with data.

Eywa What is Eywa? "Eywa is the guiding force and deity of Pandora and the Na'vi. All living things on Pandora connect to Eywa." -- Avatar Wiki Projec

Nov 28, 2022
Comments
  • Couple of ideas for you

    Couple of ideas for you

    As I mentioned, this is really nice! I've written my own but I spent a lot of my time working around the password problem (I guess I should have forked the code, as you did); there are a lot of nice details in your code.

    Some ideas if you are interested:

    • I made the top-level client an interface, to facilitate mocking.
    • I have a utility function which sets mqtt.DEBUG, mqtt.WARN, ... etc so that if you need it you can get the underlying MQTT debug information.
    • I opted for now to expose the MQTT token to callers, because I wasn't sure if a fixed timeout would be the right thing. Dunno if that's really a good idea or not. I guess I could wrap the token to make it less ugly.

    Anyway, well done.

An Open-Source Platform for Quantified Self & IoT
An Open-Source Platform for Quantified Self & IoT

Heedy Note: Heedy is currently in alpha. You can try it out by downloading it from the releases page, but there is no guarantee that future versions w

Jan 1, 2023
Suite of libraries for IoT devices (written in Go), experimental for x/exp/io

Go libraries/drivers for IoT devices This repo contains a suite of libraries for IoT devices/sensors/actuators. The suite is meant to be as dependency

Sep 26, 2022
Make IoT a lot more fun with data.

Eywa What is Eywa? "Eywa is the guiding force and deity of Pandora and the Na'vi. All living things on Pandora connect to Eywa." -- Avatar Wiki Projec

Nov 28, 2022
Golang framework for robotics, drones, and the Internet of Things (IoT)
Golang framework for robotics, drones, and the Internet of Things (IoT)

Gobot (https://gobot.io/) is a framework using the Go programming language (https://golang.org/) for robotics, physical computing, and the Internet of

Dec 29, 2022
Industrial IoT Messaging and Device Management Platform
Industrial IoT Messaging and Device Management Platform

Mainflux Mainflux is modern, scalable, secure, open-source, and patent-free IoT cloud platform written in Go. It accepts user and thing (sensor, actua

Dec 31, 2022
Gobot - Golang framework for robotics, drones, and the Internet of Things (IoT)
Gobot - Golang framework for robotics, drones, and the Internet of Things (IoT)

Gobot (https://gobot.io/) is a framework using the Go programming language (https://golang.org/) for robotics, physical computing, and the Internet of Things.

Jan 8, 2023
An embeddable lightweight Go/Golang MQTT broker(server) for IoT.
An embeddable lightweight Go/Golang MQTT broker(server) for IoT.

Snple MQTT 简体中文 Note: The API of this library is still unstable and has not been sufficiently tested, please do not use it in production environments.

Sep 12, 2022
🐼 IoT worm written in pure golang.
🐼 IoT worm written in pure golang.

GoriaNet Most powerfull cross compiler (27arch). Kill process by port and check for duplicate instance. Killing process by port. Cross compiler. Infor

Oct 17, 2022
Next-generation IoT open source platform.
Next-generation IoT open source platform.

tKeel Next-generation IoT open source platform High performance, High security and easy to use tKeel is a strong and reusable IoT platform that helps

Dec 28, 2022
Whichip: discover (IoT) device's IP in local network
Whichip: discover (IoT) device's IP in local network

whichip: discover (IoT) device's IP in local network Install On (IoT) Device wget -O install.sh

Dec 8, 2021