Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/arduino/iot-client-go
Go client for Arduino IoT API
https://github.com/arduino/iot-client-go
Last synced: about 1 month ago
JSON representation
Go client for Arduino IoT API
- Host: GitHub
- URL: https://github.com/arduino/iot-client-go
- Owner: arduino
- License: other
- Created: 2019-08-20T11:23:14.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2024-09-20T08:10:02.000Z (about 2 months ago)
- Last Synced: 2024-09-29T08:49:32.733Z (about 2 months ago)
- Language: Go
- Homepage: https://www.arduino.cc/reference/en/iot/api/
- Size: 869 KB
- Stars: 19
- Watchers: 9
- Forks: 9
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Arduino iot-api Go client
## Getting Started
The client requires a valid access token to authenticate, you can use the
`golang.org/x/oauth2` to easily get one with the Client Credentials OAuth2 flow:```Go
import cc "golang.org/x/oauth2/clientcredentials"// We need to pass the additional "audience" var to request an access token
additionalValues := url.Values{}
additionalValues.Add("audience", "https://api2.arduino.cc/iot")
// Set up OAuth2 configuration
config := cc.Config{
ClientID: clientID,
ClientSecret: clientSecret,
TokenURL: "https://api2.arduino.cc/iot/v1/clients/token",
EndpointParams: additionalValues,
}
// Get the access token in exchange of client_id and client_secret
tok, err := config.Token(context.Background())
if err != nil {
log.Fatalf("Error retrieving access token, %v", err)
}
// Confirm we got the token and print expiration time
log.Printf("Got an access token, will expire on %s", tok.Expiry)
```For a working example, see [the example folder](https://github.com/arduino/iot-client-go/tree/master/example) in this repo.
## How to get Arduino IoT Cloud Client Credentials
You can generate Arduino IoT Cloud Client Credentials in the `ARDUINO API` section in the [IoT Cloud things section](https://create.arduino.cc/iot/things):
### Step 1
![IoT Cloud Site](https://github.com/arduino/iot-client-js/blob/master/img/selection_1.png?raw=true)
### Step 2
![IoT Cloud Site](https://github.com/arduino/iot-client-js/blob/master/img/selection_2.png?raw=true)
### Step 3
![IoT Cloud Site](https://github.com/arduino/iot-client-js/blob/master/img/selection_3.png?raw=true)