utils

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2024 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateCloudEvent

func CreateCloudEvent(t string, source string, data string) (cloudevents.Event, error)

CreateCloudEvent creates a CloudEvent JSON.

func GetBroadcastAddress

func GetBroadcastAddress() (string, error)

func MarshallCloudEvent

func MarshallCloudEvent(event cloudevents.Event) ([]byte, error)

MarshallCloudEvent converts a CloudEvent struct to a JSON byte array.

func UnmarshalCloudEvent

func UnmarshalCloudEvent(bytes []byte) (cloudevents.Event, error)

UnmarshalCloudEvent converts a JSON byte array to a CloudEvent struct.

Types

type Config

type Config struct {
	MQTT         MQTT   `mapstructure:"mqtt"`
	UDP          UDP    `mapstructure:"udp"`
	LogLevel     string `mapstructure:"log_level"`
	ConfigFolder string
}

Config represents the application configuration.

func LoadConfig

func LoadConfig() (*Config, error)

type Connection

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

func (*Connection) Receive

func (c *Connection) Receive() chan []byte

func (*Connection) RemoteAddress

func (c *Connection) RemoteAddress(ip string, port int) (*net.UDPAddr, error)

func (*Connection) Send

func (c *Connection) Send(ip string, port int, ce cloudevents.Event) error

type MQTT

type MQTT struct {
	ClientId string `mapstructure:"client_id"`
	Endpoint string `mapstructure:"endpoint"`
	Protocol string `mapstructure:"protocol"`
	Port     int    `mapstructure:"port"`
	CaFile   string `mapstructure:"ca_file"`
	CertFile string `mapstructure:"cert_file"`
	KeyFile  string `mapstructure:"key_file"`
	TopicIn  string `mapstructure:"topic_in"`
	TopicOut string `mapstructure:"topic_out"`
}

type MQTTClient

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

MQTTClient struct

func NewClient

func NewClient(broker, clientId, certFile, keyFile, caFile, topic string) (*MQTTClient, error)

NewClient creates a new MQTT client to connect to AWS IoT Core.

func (*MQTTClient) Disconnect

func (c *MQTTClient) Disconnect() error

Disconnect disconnects the MQTT client.

func (*MQTTClient) Publish

func (c *MQTTClient) Publish(topic string, qos byte, retained bool, payload interface{}) error

Publish sends a message to the specified topic.

func (*MQTTClient) Receive

func (c *MQTTClient) Receive() <-chan []byte

Receive returns the receive channel for MQTT messages.

func (*MQTTClient) Send

func (c *MQTTClient) Send(topic string, ce cloudevents.Event) error

Send sends a message to the specified topic.

func (*MQTTClient) SendMessage

func (c *MQTTClient) SendMessage(topic string, data string) error

Send Message as Cloudevent

func (*MQTTClient) SendRaw

func (c *MQTTClient) SendRaw(topic string, raw []byte) error

Send Raw Message

type UDP

type UDP struct {
	IpIn    string `mapstructure:"ip_in"`
	IpOut   string `mapstructure:"ip_out"`
	PortIn  int    `mapstructure:"port_in"`
	PortOut int    `mapstructure:"port_out"`
}

type UDPConn

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

UDP connection struct

func NewConnection

func NewConnection(ip string, portIn int) (*UDPConn, error)

NewConnection creates a new UDP connection.

func (*UDPConn) Receive

func (u *UDPConn) Receive() <-chan []byte

Method to receive UDP packets

func (*UDPConn) SendRaw

func (u *UDPConn) SendRaw(ip string, port int, raw []byte) error

Jump to

Keyboard shortcuts

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