mqtt

package module
v0.0.0-...-41190df Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2021 License: MIT Imports: 6 Imported by: 2

README

AWS IoT Device SDK GoLang

AWS IoT gateway interface connection interface in GoLang

Seamlessly connect with AWS IoT using this interface built on top of Paho MQTT Client

Sample code:

package main

import (
	MQTT "github.com/eclipse/paho.mqtt.golang"
	mqtt "github.com/tech-sumit/aws-iot-device-sdk-go"
)

func main(){
	connection,err:=mqtt.NewConnection(mqtt.Config{
		KeyPath:  "<KEY_PATH>",
		CertPath: "<CERT_PATH>",
		CAPath:   "<CA_PATH>",
		ClientId: "ping_client",
		Endpoint: "<MQTT_GATEWAY_ENDPOINT>",
	})
	if err!=nil {
		panic(err)
	}
	go func() {
		err=connection.SubscribeWithHandler("ping",0, func(client MQTT.Client, message MQTT.Message) {
			print(string(message.Payload()))
		})
	}()
	if err!=nil {
		panic(err)
	}
	err=connection.Publish("ping","pong",0)
	if err!=nil {
		panic(err)
	}
}

Documentation

Overview

Package mqtt provides paho mqtt implementation to connect with AWS IoT Gateway

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AWSIoTConnection

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

AWSIoTConnection holds connection for AWS IoT

func NewConnection

func NewConnection(config Config) (*AWSIoTConnection, error)

NewConnection Creates new MQTT connection with AWS IoT It requires config parameter for initialisation

func (*AWSIoTConnection) Disconnect

func (c *AWSIoTConnection) Disconnect() bool

Disconnect function disconnects the MQTT connection only if its already connected else returns error

func (*AWSIoTConnection) Publish

func (c *AWSIoTConnection) Publish(topic string, data interface{}, qos byte) error

Publish function publishes data in interface on topic with level of qos (Quality of service) currently supported 0 & 1 (2 coming in future)

func (*AWSIoTConnection) Subscribe

func (c *AWSIoTConnection) Subscribe(topic string, qos byte) error

Subscribe function subscribes on topic with level of qos (Quality of service) currently supported 0 & 1 (2 coming in future).

func (*AWSIoTConnection) SubscribeWithHandler

func (c *AWSIoTConnection) SubscribeWithHandler(topic string, qos byte, handler MQTT.MessageHandler) error

SubscribeWithHandler function subscribes on topic with level of qos (Quality of service) currently supported 0 & 1 (2 coming in future) & handler function to listen to incoming messages for the topic & qos level. It is called every time when message is received

func (*AWSIoTConnection) Unsubscribe

func (c *AWSIoTConnection) Unsubscribe(topic string) error

Unsubscribe function removes subscription for specified topic

type Config

type Config struct {
	KeyPath  string `json:"keyPath" binding:"required"`
	CertPath string `json:"certPath" binding:"required"`
	CAPath   string `json:"caPath" binding:"required"`
	ClientId string `json:"clientId" binding:"required"`
	Endpoint string `json:"endpoint" binding:"required"`
}

Config struct holds connection parameters for AWSIoTConnection initialisation All parameters are compulsory KeyPath is path to x.509 Private Key CertPath is path to x.509 Public Key CAPath is path to CA certificate ClientId is the clientId of thing Endpoint is Unique AWS IoT endpoint provided by AWS IoT

Directories

Path Synopsis
topics
lifecycle
Package lifecycle provides topics to intercept thing lifecycle & subscription events
Package lifecycle provides topics to intercept thing lifecycle & subscription events
registry
Package registry provides topics for Device registry operations
Package registry provides topics for Device registry operations

Jump to

Keyboard shortcuts

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