iot

package
v0.0.0-...-46dd8e8 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const Biz = "/biz"
View Source
const Broadcast = "/broadcast"
View Source
const ClientId = "${clientid}"
View Source
const Ext = "/ext"
View Source
const MLW = "#" // multi level wildcard
View Source
const Ota = "/ota"
View Source
const ProductKey = "miner" // Temporarily fixed as “miner”
View Source
const SLW = "+" // single level wildcard
View Source
const SSys = "$SYS"
View Source
const Shadow = "/shadow"
View Source
const Sys = "/sys"
View Source
const Version = "1.0"

Variables

This section is empty.

Functions

func NewTLSConfig

func NewTLSConfig(certFile string, certPrivateKey string) (*tls.Config, error)

NewTLSConfig New TLS Config

func PublishData

func PublishData(mc *MqttClient, topic string, data interface{}) (msgId string, err error)

func SubscribeData

func SubscribeData(mc *MqttClient, topic string, handler func(res *Message, err error)) (err error)

func ToTopic

func ToTopic(str ...string) string

Types

type DeviceInfo

type DeviceInfo struct {
	Kernel    string `json:"kernel"`
	Hostname  string `json:"hostname"`
	System    string `json:"system"`
	Model     string `json:"model"`
	BoardName string `json:"board_name"`
	Release   struct {
		Distribution string `json:"distribution"`
		Version      string `json:"version"`
		Revision     string `json:"revision"`
		Target       string `json:"target"`
		Description  string `json:"description"`
	} `json:"release"`
}

type Identity

type Identity struct {
	Validator interface{} `json:"validator" v:"required" binding:"required"`
	Miner     interface{} `json:"miner" v:"required" binding:"required"`
}

type Message

type Message struct {
	Id      string      `json:"id"`
	Ts      int64       `json:"ts"`
	Data    interface{} `json:"data"`
	Version string      `json:"version"`
	// contains filtered or unexported fields
}

func NewMessage

func NewMessage(data interface{}) *Message

func NewMessageWithId

func NewMessageWithId(msgId string, data interface{}) *Message

func (Message) ClientId

func (m Message) ClientId() string

func (Message) ProductKey

func (m Message) ProductKey() string

func (Message) RawMessage

func (m Message) RawMessage() mqtt.Message

type MinerGuestData

type MinerGuestData struct {
	MinerSn       string `json:"minerSn"       description:""`
	ClientId      string `json:"clientId"      description:"Device ID"`
	Hostname      string `json:"hostname"      description:"guest phone brand"`
	Mac           string `json:"mac"           description:"guest device mac"`
	DisplayName   string `json:"displayName"   description:"guest display name"`
	PhoneNumber   string `json:"phoneNumber"   description:"Phone number"`
	BirthDate     string `json:"birthDate"     description:"Birthday"`
	Gender        int    `json:"gender"        description:"Gender(0-Unknown,1-Male,2-Female)"`
	Email         string `json:"email"         description:"Email address"`
	EmailVerified bool   `json:"emailVerified" description:"Whether the email has been verified"`
	CountryCode   string `json:"countryCode"   description:"Country Code"`
	LanguageCode  string `json:"languageCode"  description:"Language code"`
}

MinerGuestData is the golang structure for table miner_guest_record.

type MinerHeartbeatData

type MinerHeartbeatData struct {
	Sn            string       `json:"sn" binding:"required" v:"required"`
	Did           string       `json:"did" binding:"required" v:"required"`
	Mac           string       `json:"mac" binding:"required" v:"required"`
	PublicIP      string       `json:"publicIP"`
	WalletAddress string       `json:"walletAddress" `
	RadioStatus   []WiFiStatus `json:"radioStatus" binding:"required"`
	SystemStatus  SystemInfo   `json:"systemStatus" binding:"required"`
	DeviceStatus  DeviceInfo   `json:"deviceStatus" binding:"required"`
}

type MinerSettingsData

type MinerSettingsData struct {
	CreatedAt    int64  `json:"createdAt"`
	UpdatedAt    int64  `json:"updatedAt"`
	Banner       string `json:"banner"`
	ForwardLink  string `json:"forwardLink"`
	Timeout      int    `json:"timeout"`
	UploadRate   int    `json:"uploadRate"`
	DownloadRate int    `json:"downloadRate"`
}

type MinerWorkloadData

type MinerWorkloadData struct {
	Identity *Identity `json:"identity" v:"required" binding:"required"`
	Qos      *Qos      `json:"qos" v:"required" binding:"required"`
	Tracks   string    `json:"tracks"`
}

type MqttClient

type MqttClient struct {
	Client mqtt.Client
	// contains filtered or unexported fields
}

MqttClient MQTT Client

func NewMqttClient

func NewMqttClient(cfg MqttConfig) (*MqttClient, error)

func (*MqttClient) ClientId

func (mc *MqttClient) ClientId() string

func (*MqttClient) Close

func (mc *MqttClient) Close()

func (*MqttClient) Publish

func (mc *MqttClient) Publish(topic string, payload []byte) error

Publish Mqtt message.

func (*MqttClient) PublishData

func (mc *MqttClient) PublishData(topicType TopicType, data interface{}) (string, error)

func (*MqttClient) PublishDataTo

func (mc *MqttClient) PublishDataTo(clientId string, topicType TopicType, data interface{}) (string, error)

func (*MqttClient) Subscribe

func (mc *MqttClient) Subscribe(topic string, onMessage mqtt.MessageHandler) error

Subscribe subscribe a Mqtt topic.

func (*MqttClient) SubscribeData

func (mc *MqttClient) SubscribeData(topicType TopicType, handler func(res *Message, err error)) (err error)

func (*MqttClient) SubscribeDataFrom

func (mc *MqttClient) SubscribeDataFrom(clientId string, topicType TopicType, handler func(res *Message, err error)) (err error)

func (*MqttClient) Unsubscribe

func (mc *MqttClient) Unsubscribe(topics ...string) error

Unsubscribe unsubscribe a Mqtt topic.

type MqttConfig

type MqttConfig struct {
	Broker                string `json:"broker"`
	ClientId              string `json:"clientId"` //SN
	Username              string `json:"username"` //did (optional)
	Password              string `json:"password"`
	CertFile              string `json:"certFile"`
	CertPrivateKey        string `json:"certPrivateKey"`
	WillEnabled           bool   `json:"willEnabled"`
	WillPayload           string `json:"willPayload"`
	WillQos               byte   `json:"willQos"`
	Qos                   byte   `json:"qos"`
	Retained              bool   `json:"retained"`
	ConnectionLostHandler mqtt.ConnectionLostHandler
	OnConnectHandler      mqtt.OnConnectHandler
}

MqttConfig MQTT Config

type OtaFirmwareCheckData

type OtaFirmwareCheckData struct {
	Distribution string `json:"distribution" binding:"required" v:"required"`
	Version      string `json:"version" binding:"required" v:"required"`
	Target       string `json:"target" binding:"required" v:"required"`
	Description  string `json:"description" binding:"required" v:"required"`
	Model        string `json:"model" binding:"required" v:"required"`
	BoardName    string `json:"boardName" binding:"required" v:"required"`
	Sn           string `json:"sn" binding:"required" v:"required"`
}

type OtaFirmwareUpgradeData

type OtaFirmwareUpgradeData struct {
	Id           int    `json:"id" binding:"required" v:"required"`
	Distribution string `json:"distribution" binding:"required" v:"required"`
	Version      string `json:"version" binding:"required" v:"required"`
	Target       string `json:"target" binding:"required" v:"required"`
	Description  string `json:"description" binding:"required" v:"required"`
	ImageUrl     string `json:"imageUrl" binding:"required" v:"required"`
	IsForced     bool   `json:"isForced" binding:"required" v:"required"`
	Sha256       string `json:"sha256" binding:"required" v:"required"`
	Model        string `json:"model" binding:"required" v:"required"`
	BoardName    string `json:"boardName" binding:"required" v:"required"`
}

type OtaFirmwareUpgradeReplyData

type OtaFirmwareUpgradeReplyData struct {
	UpgradeId int    `json:"upgradeId" binding:"required" v:"required"`
	Message   string `json:"message" binding:"required" v:"required"`
	Success   bool   `json:"success" binding:"required" v:"required"`
}

type Qos

type Qos struct {
	Bandwidth  string `json:"bandwidth"`
	Rssi       string `json:"rssi"`
	PacketLose string `json:"packetLose"`
	Latency    string `json:"latency"`
	Nonce      string `json:"nonce" binding:"required"`
	Signature  string `json:"signature" binding:"required"`
}

type ReplyData

type ReplyData struct {
	Code int         `json:"code"`
	Msg  string      `json:"msg"`
	Data interface{} `json:"data"`
}

type SystemCommandData

type SystemCommandData struct {
	Id      int      `json:"id" binding:"required" v:"required"`
	BinName string   `json:"binName" binding:"required" v:"required"`
	Args    []string `json:"args" binding:"required" v:"required"`
}

type SystemCommandReplyData

type SystemCommandReplyData struct {
	Id      int    `json:"id" binding:"required" v:"required"`
	Output  string `json:"output" binding:"required" v:"required"`
	Success bool   `json:"success" binding:"required" v:"required"`
}

type SystemInfo

type SystemInfo struct {
	Localtime int   `json:"localtime"`
	Uptime    int   `json:"uptime"`
	Load      []int `json:"load"`
	Memory    struct {
		Total     int `json:"total"`
		Free      int `json:"free"`
		Shared    int `json:"shared"`
		Buffered  int `json:"buffered"`
		Available int `json:"available"`
		Cached    int `json:"cached"`
	} `json:"memory"`
	Swap struct {
		Total int `json:"total"`
		Free  int `json:"free"`
	} `json:"swap"`
}

type TopicType

type TopicType string
const (
	SysWillStatus TopicType = Sys + "/%s/%s/will/status" // client Pub

	SysHeartbeatUpdate      TopicType = Sys + "/%s/%s/heartbeat/update" // client Pub
	SysHeartbeatUpdateReply TopicType = SysHeartbeatUpdate + _REPLY     // client Sub

	SysSettingsGet    TopicType = Sys + "/%s/%s/settings/get"    // client Pub
	SysSettingsUpdate TopicType = Sys + "/%s/%s/settings/update" // client Sub

	SysCommand      TopicType = Sys + "/%s/%s/command/issue" // client Sub
	SysCommandReply TopicType = SysCommand + _REPLY          // client Pub

	BizWorkloadValidate      TopicType = Biz + "/%s/%s/workload/validate" // client Pub
	BizWorkloadValidateReply TopicType = BizWorkloadValidate + _REPLY     // client Sub

	OtaFirmwareCheck        TopicType = Ota + "/%s/%s/firmware/check"   // client Pub
	OtaFirmwareUpgrade      TopicType = Ota + "/%s/%s/firmware/upgrade" // client Sub
	OtaFirmwareUpgradeReply TopicType = OtaFirmwareUpgrade + _REPLY     // client Pub
)

func (TopicType) Topic

func (t TopicType) Topic(productKey, clientId string) string

type WiFiStatus

type WiFiStatus struct {
	Disabled        bool   `json:"disabled"`
	Type            string `json:"type"` // openroaming | free
	Phy             string `json:"phy"`
	Ssid            string `json:"ssid"`
	Bssid           string `json:"bssid"`
	Country         string `json:"country"`
	Mode            string `json:"mode"`
	Channel         int    `json:"channel"`
	CenterChan1     int    `json:"center_chan1"`
	Frequency       int    `json:"frequency"`
	FrequencyOffset int    `json:"frequency_offset"`
	Txpower         int    `json:"txpower"`
	TxpowerOffset   int    `json:"txpower_offset"`
	Quality         int    `json:"quality"`
	QualityMax      int    `json:"quality_max"`
	Signal          int    `json:"signal"`
	Noise           int    `json:"noise"`
	Bitrate         int    `json:"bitrate"`
	Encryption      struct {
		Enabled        bool     `json:"enabled"`
		Wpa            []int    `json:"wpa,omitempty"`
		Authentication []string `json:"authentication,omitempty"`
		Ciphers        []string `json:"ciphers,omitempty"`
	} `json:"encryption"`
	Htmodes []string         `json:"htmodes"`
	Hwmodes []string         `json:"hwmodes"`
	Hwmode  string           `json:"hwmode"`
	Htmode  string           `json:"htmode"`
	Station []WifiClientInfo `json:"station"`
}

type WifiClientInfo

type WifiClientInfo struct {
	Hostname      string `json:"hostname"`
	Mac           string `json:"mac"`
	Signal        int    `json:"signal"`
	SignalAvg     int    `json:"signal_avg"`
	Noise         int    `json:"noise"`
	Inactive      int    `json:"inactive"`
	ConnectedTime int    `json:"connected_time"`
}

Jump to

Keyboard shortcuts

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