thing

package
v0.2.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 29, 2022 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const RootPEM = `` /* 1187-byte string literal not displayed */

RootPEM is the Amazon Root CA for IoT Core - Subject to change (but likely not often) https://www.amazontrust.com/repository/AmazonRootCA1.pem

Variables

View Source
var RegisterCmd = &cobra.Command{
	Use:   "register",
	Short: "Registers a new thing",
	Long:  `Registers a new thing and creates/stores all the keys and certs needed to communicate with AWS IoT Core`,
	Args:  cobra.NoArgs,
	Run: func(cmd *cobra.Command, args []string) {
		if err := checkRegisterParameters(); err != nil {
			log.Fatal(err)
		}

		macAddress, _, err := networking.GetMACAddress()
		if err != nil {
			log.Fatal(err)
		}
		uniqueID := macAddress[:6] + "fffe" + macAddress[6:]
		parameters["UniqueId"] = string(uniqueID)

		keypair := models.KeyPair{
			PrivateKeyPath:    privateKeyPath,
			CertificatePath:   certificatePath,
			CACertificatePath: rootCAPath,
		}

		client, err := mqtt.MakeMQTTClient(keypair, endpoint, clientID)
		if err != nil {
			log.Fatal(err)
		}

		err = ProvisionThing(client, keypair, endpoint, templateName, parameters, outputFilePath)
		if err != nil {
			log.Fatal(err)
		}
	},
}

RegisterCmd registers a new thing

Functions

func ProvisionThing

func ProvisionThing(c mqtt.Client, keyPair models.KeyPair, awsEndpoint, templateName string, thingParameters map[string]string, certificateOutputPath string) error

ProvisionThing creates a new set of certificates for the device

Types

type AWSMQTTError

type AWSMQTTError struct {
	StatusCode   int    `json:"statusCode"`
	ErrorCode    string `json:"errorCode"`
	ErrorMessage string `json:"errorMessage"`
}

AWSMQTTError holds the data from a rejected request

type AWSMQTTErrorCh

type AWSMQTTErrorCh []byte

AWSMQTTErrorCh holds the bytes of a CreateKeysAndCertificateRejected message.

type CreateKeysAndCertificateAccepted

type CreateKeysAndCertificateAccepted struct {
	CertificateID             string `json:"certificateId"`
	CertificatePem            string `json:"certificatePem"`
	PrivateKey                string `json:"privateKey"`
	CertificateOwnershipToken string `json:"certificateOwnershipToken"`
}

CreateKeysAndCertificateAccepted holds the data from an accepted request to create a new key and certificate.

type CreateKeysAndCertificateAcceptedCh

type CreateKeysAndCertificateAcceptedCh []byte

CreateKeysAndCertificateAcceptedCh holds the bytes of a CreateKeysAndCertificateAccepted message.

type Payload

type Payload []byte

Payload device data

type RegisterThingAcceptedCh

type RegisterThingAcceptedCh []byte

RegisterThingAcceptedCh holds the bytes of a RegisterThingAccepted message.

type RegisterThingRequest

type RegisterThingRequest struct {
	TemplateName              string            `json:"-"`
	CertificateOwnershipToken string            `json:"certificateOwnershipToken"`
	Parameters                map[string]string `json:"parameters"`
}

RegisterThingRequest holds the values needed to make a request to register a new thing.

type RegisterThingResponse

type RegisterThingResponse struct {
	ThingName           string            `json:"thingName"`
	DeviceConfiguration map[string]string `json:"deviceConfiguration"`
}

RegisterThingResponse holds the values returned from a successful registration request.

type Shadow

type Shadow []byte

Shadow device shadow data

func (Shadow) String

func (s Shadow) String() string

String converts the Shadow to string

type ShadowError

type ShadowError = Shadow

ShadowError represents the model for handling the errors occurred during updating the device shadow

type Thing

type Thing struct {
	// contains filtered or unexported fields
}

Thing a structure for working with the AWS IoT device shadows

func NewThingFromFiles

func NewThingFromFiles(keyPair models.KeyPair, awsEndpoint string, thingName ThingName) (*Thing, error)

NewThingFromFiles returns a new instance of Thing

func NewThingFromStrings

func NewThingFromStrings(cert string, key string, awsEndpoint string, thingName ThingName) (*Thing, error)

NewThingFromStrings returns a new instance of Thing

func (*Thing) DeleteThingShadow

func (t *Thing) DeleteThingShadow() error

DeleteThingShadow publishes a message to remove the device's shadow and waits for the result. In case shadow delete was rejected the method will return error

func (*Thing) Disconnect

func (t *Thing) Disconnect()

Disconnect terminates the MQTT connection between the client and the AWS server. Recommended to use in defer to avoid connection leaks.

func (*Thing) GetNextJob

func (t *Thing) GetNextJob() (Payload, error)

func (*Thing) GetThingShadow

func (t *Thing) GetThingShadow() (Shadow, error)

GetThingShadow returns the current thing shadow

func (*Thing) ListenForJobs

func (t *Thing) ListenForJobs() (chan Payload, error)

ListenForJobs is a helper function that subscribes to the topic responsible for notifying on IoT Core Jobs

func (*Thing) PublishToCustomTopic

func (t *Thing) PublishToCustomTopic(payload Payload, topic string) error

PublishToCustomTopic publishes an async message to the custom topic.

func (*Thing) SubscribeForCustomTopic

func (t *Thing) SubscribeForCustomTopic(topic string) (chan Payload, error)

SubscribeForCustomTopic subscribes for the custom topic and returns the channel with the topic messages.

func (*Thing) SubscribeForThingShadowChanges

func (t *Thing) SubscribeForThingShadowChanges() (chan Shadow, chan ShadowError, error)

SubscribeForThingShadowChanges subscribes for the device shadow update topic and returns two channels: shadow and shadow error. The shadow channel will handle all accepted device shadow updates. The shadow error channel will handle all rejected device shadow updates

func (Thing) UnsubscribeFromCustomTopic

func (t Thing) UnsubscribeFromCustomTopic(topic string) error

UnsubscribeFromCustomTopic terminates the subscription to the custom topic. The specified topic argument will be prepended by a prefix "$aws/things/<thing_name>"

func (*Thing) UnsubscribeFromJobs

func (t *Thing) UnsubscribeFromJobs() error

func (*Thing) UpdateThingShadow

func (t *Thing) UpdateThingShadow(payload Shadow) error

UpdateThingShadow publishes an async message with new thing shadow

func (*Thing) UpdateThingShadowDocument

func (t *Thing) UpdateThingShadowDocument(payload Shadow) error

UpdateThingShadowDocument publishes an async message with new thing shadow document

type ThingName

type ThingName = string

ThingName the name of the AWS IoT device representation

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL