Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/vaelen/iot
A Go client for Google IoT Core
https://github.com/vaelen/iot
Last synced: 14 days ago
JSON representation
A Go client for Google IoT Core
- Host: GitHub
- URL: https://github.com/vaelen/iot
- Owner: vaelen
- License: mit
- Created: 2018-03-08T06:51:51.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-11-08T18:32:28.000Z (about 5 years ago)
- Last Synced: 2024-04-13T18:51:21.459Z (7 months ago)
- Language: Go
- Homepage:
- Size: 46.9 KB
- Stars: 66
- Watchers: 6
- Forks: 13
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-go - iot - IoT is a simple framework for implementing a Google IoT Core device. (IoT (Internet of Things) / Search and Analytic Databases)
- awesome-go-extra - iot - 03-08T06:51:51Z|2019-11-08T18:32:28Z| (IoT (Internet of Things) / Advanced Console UIs)
README
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](https://gocover.io/_badge/github.com/vaelen/iot)](https://gocover.io/github.com/vaelen/iot)
[![Go Report Card](https://goreportcard.com/badge/github.com/vaelen/iot)](https://goreportcard.com/report/github.com/vaelen/iot)
[![Go Docs](https://godoc.org/github.com/vaelen/iot?status.svg)](https://godoc.org/github.com/vaelen/iot)
[![Mentioned in Awesome Go](https://awesome.re/mentioned-badge.svg)](https://github.com/avelino/awesome-go)Copyright 2018, Andrew C. Young <>
License: [MIT]
Here is an example showing how to use this library:
```go
package mainimport (
"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.
[Andrew C. Young]: http;//vaelen.org
[Infostellar]: http://infostellar.net
[context package]: https://golang.org/pkg/context/
[MIT]: ../blob/master/LICENSE