{"id":22878195,"url":"https://github.com/allthingstalk/go-sdk","last_synced_at":"2026-05-16T08:03:44.311Z","repository":{"id":57563778,"uuid":"86447325","full_name":"allthingstalk/go-sdk","owner":"allthingstalk","description":"Go SDK for AllThingsTalk IoT platform","archived":false,"fork":false,"pushed_at":"2018-05-11T08:16:09.000Z","size":28,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":12,"default_branch":"master","last_synced_at":"2025-08-06T08:19:26.587Z","etag":null,"topics":["allthingstalk","allthingstalk-maker","go","golang","iot","iot-device","json-schema","makers","sdk","sdk-go"],"latest_commit_sha":null,"homepage":"http://www.allthingstalk.com/","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/allthingstalk.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-03-28T10:33:43.000Z","updated_at":"2024-06-14T05:44:01.000Z","dependencies_parsed_at":"2022-09-16T13:33:42.339Z","dependency_job_id":null,"html_url":"https://github.com/allthingstalk/go-sdk","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/allthingstalk/go-sdk","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/allthingstalk%2Fgo-sdk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/allthingstalk%2Fgo-sdk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/allthingstalk%2Fgo-sdk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/allthingstalk%2Fgo-sdk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/allthingstalk","download_url":"https://codeload.github.com/allthingstalk/go-sdk/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/allthingstalk%2Fgo-sdk/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269228534,"owners_count":24381847,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-07T02:00:09.698Z","response_time":73,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["allthingstalk","allthingstalk-maker","go","golang","iot","iot-device","json-schema","makers","sdk","sdk-go"],"created_at":"2024-12-13T16:18:56.729Z","updated_at":"2026-05-16T08:03:44.243Z","avatar_url":"https://github.com/allthingstalk.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Go SDK [![Build Status](https://travis-ci.org/allthingstalk/go-sdk.svg?branch=master)](https://travis-ci.org/allthingstalk/go-sdk) [![Go Report Card](https://goreportcard.com/badge/github.com/allthingstalk/go-sdk)](https://goreportcard.com/report/github.com/allthingstalk/go-sdk) [![RELEASE](https://img.shields.io/github/release/allthingstalk/go-sdk.svg)](https://github.com/allthingstalk/go-sdk/releases/latest) [![GoDoc](https://godoc.org/github.com/allthingstalk/go-sdk?status.svg)](https://godoc.org/github.com/allthingstalk/go-sdk) [![LICENSE](https://img.shields.io/github/license/allthingstalk/go-sdk.svg)](LICENSE)\n\nAllThingsTalk Golang SDK provides APIs to implement AllThingsTalk devices.\n\n## Installation\n\nInstall [Go][5a0ab892], and then:\n\n```bash\ngo get -u github.com/allthingstalk/go-sdk\n```\n\nImport:\n\n```go\nimport \"github.com/allthingstalk/go-sdk\"\n```\n\n## Quickstart\n\nYou should create an [AllThingsTalk Maker][7447b4f9] account, and a simple device. All examples require `DeviceID` and `DeviceToken`, which can be found under Device Settings.\n\n```go\npackage main\n\nimport (\n\t\"github.com/allthingstalk/go-sdk\"\n\t\"time\"\n)\n\nconst (\n\tdeviceID    = \"\u003cYOUR_DEVICE_ID\u003e\"\n\tdeviceToken = \"\u003cYOUR_DEVICE_TOKEN\u003e\"\n)\n\n// A device which counts from 1 to 10 with a 1-second interval\nfunc main() {\n\t// initialize a device\n\tdevice, err := sdk.NewDevice(deviceID, deviceToken)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\t// add an asset named `counter` of `Integer` type\n\tcounter, err := device.AddInteger(\"counter\")\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\t\n\t// just count from 1 to 10 and send that value to Maker\n\tfor i := 1; i \u003c= 10; i++ {\n\t\ttime.Sleep(1 * time.Second)\n\t\tdevice.Publish(counter, i)\n\t}\n}\n```\n\n## HowTo\n\nPlease go through [examples][cfdc356c] for more comprehensive tutorials on how to use this package.\n\n### Initializing a device\n\nTo manage a device, you must obtain a DeviceID (which is an unique device identifier within [AllThingsTalk Maker][7447b4f9]) and DeviceToken (which this SDK uses to obtain access to APIs), both of which can be found on Device Settings page within [AllThingsTalk Maker][7447b4f9].\n\nDevice can be initialized by:\n\n```go\ndevice, _ := sdk.NewDevice(deviceID, deviceToken)\n```\n\nYou can also customize behind-the-scenes functionality, in this case - HTTP and MQTT clients, by optionally providing endpoints for them. By default these are securely connecting to Maker:\n\n```go\ndevice, _ := sdk.NewDevice(\"\u003cDEVICE_ID\u003e\", \"\u003cDEVICE_TOKEN\u003e\",\n\tsdk.WithHTTP(\"https://api.allthingstalk.io\"),\n\tsdk.WithMQTT(\"ssl://api.allthingstalk.io:8883\"))\n```\n\n### Creating Assets\n\nAssets represent a typed property of a device which can be used either to sense some physical value (a `Sensor`), or send a value to a device (an `Actuator`). Each asset is described by `name` (unique identifier within a device) and `profile` (a [JSON Schema][61d54ea9] which describes data format).\n\n#### Creating simple Sensors\n\nSensors of simple types (`integers`, `number`, `boolean`, `string`) can be created by `Add*` functions of a `Device`:\n\n```go\n// create a Sensor named `hello` with `integer` profile.\nsensor, _ := device.AddInteger(\"hello\")\n```\n\nPlease check API reference for all available methods.\n\n#### Creating Sensors and Actuators\n\n`Sensors` and `Actuators` can be created with [NewSensor][1cb40ec7] and [NewActuator][db6f36c9] functions. These functions expect `name` (unique identifier within a device) and `profile` (JSON Schema describing data).\n\nAfterwards, just to `device.Add(...)` to create that asset on the AllThingsTalk maker:\n\n```go\nnumberSensor := sdk.NewSensor(\"number\", profile.Number())\ndevice.Add(numberSensor)\n```\n\n#### Profiles\n\n```go\nimport \"github.com/allthingstalk/go-sdk/profile\"\n```\n\nProfiles are JSON Schemas which describe kind of data an Asset is working with. When creating an asset, we have to specify it's profile as well. Simplest way of doing this is using one of the pre-set types in `profile` package:\n\n```go\nprofile := profile.String()\n```\n\nThese functions just wrap `profile.New(...)` and provide schema type.\n\nAlternatively, you can specify a complete JSON schema for more complex profile types:\n\n```go\n\n// a profile describing a Geo location\nconst locationProfile = `\n{\n   \"type\":\"object\",\n   \"properties\":{\n\t  \"lat\":  {\"type\": \"number\"},\n\t  \"long\": {\"type\": \"number\"}\n   }\n}`\n\n// try creating it from JSON string\nprof, err := profile.JSON(locationProfile)\nif err != nil {\n\tpanic(err)\n}\n\n// create a location sensor asset with a location profile\nlocation := sdk.NewAsset(\"location\", sdk.Sensor, prof)\n```\n\nCheck out [profile package][5d088019] for more details.\n\n### Publishing states\n\nYou can publish sensor values using a `device.Publish(...)` function:\n\n```go\ndevice.Publish(sensor, \"value\")\n```\n\nSince all sensor state changes carry a timestamp, by default it's set to current UTC time if it's not provided. In order to set a custom one, just use `device.PublishState(...)`:\n\n```go\ndevice.PublishState(sensor, State{Value: \"hello\", Timestamp: time.Now().UTC()})\n```\n\n### Listening to commands\n\nAllThingsTalk Maker can also send commands to a device. You can set a global command handler which will be invoked every time command is received:\n\n```go\nfunc onMessage(command sdk.Command) {\n\tfmt.Printf(\"Received command for %s: %v with timestamp %s\\n\", command.Name, command.Value, command.Timestamp)\n}\n\nfunc main() {\n\t// ...\n\tdevice.SetCommandHandler(onMessage)\n}\n```\n\n### Error handling\n\nMost of the SDK APIs return an `error` in case something goes wrong. As per Go's idiomatic usage, it's always recommended to use something like:\n\n```go\nif err != nil {\n\t// handle error...\n}\n```\n\nTo check for any error conditions. This library uses plain `error` model. If you need stack traces, or extended functionality, your production application should probably use [pkg/errors][2f9b8fc1] or similar.\n\n### Logging\n\nYou can attach loggers for debugging purposes:\n\n```go\nsdk.ERROR = log.New(os.Stdout, \"\", 0)\n```\n\nAvailable loggers are `ERROR`, `CRITICAL`, `WARN`, `INFO` and `DEBUG`. Go's logging infrastructure being limited as is, it's generally recommended that [go-logging][5f643e4e] or similar is used in production applications.\n\n[1cb40ec7]: https://godoc.org/github.com/allthingstalk/go-sdk/#NewSensor \"NewSensor\"\n[2f9b8fc1]: https://github.com/pkg/errors \"pkg/errors\"\n[5a0ab892]: https://golang.org/doc/install \"Go\"\n[5d088019]: https://godoc.org/github.com/github.com/allthingstalk/go-sdk/profile \"profile package\"\n[5f643e4e]: https://github.com/op/go-logging \"go-logging\"\n[61d54ea9]: http://json-schema.org/ \"JSON Schema\"\n[7447b4f9]: https://maker.allthingstalk.com \"AllThingsTalk Maker\"\n[cfdc356c]: examples/ \"examples\"\n[db6f36c9]: https://godoc.org/github.com/allthingstalk/go-sdk/#NewActuator \"NewActuator\"\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fallthingstalk%2Fgo-sdk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fallthingstalk%2Fgo-sdk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fallthingstalk%2Fgo-sdk/lists"}