mqtt_sonoff_basic_r2

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2024 License: MIT Imports: 13 Imported by: 0

README

MQTT Sonoff Basic R2

Communication with Sonoff Basic R2 via MQTT. The Sonoff Basic R2 must have Tasmota firmware. For MQTT the Mochi-MQTT library is used.

Install

go get github.com/formsi/mqtt_sonoff_basic_r2

Note: Current lib uses Go Modules to manage dependencies.

Note 2: Шаблон для full topic: %prefix%/%topic%/

Features

  • Functions to start or stop the server
  • Receive notification of connection or disconnection
  • Changing Power ON/OFF/TOGGLE
  • Changing Physical Button ON/OFF
  • Getting Status (0-11 and physical_button) with timeout and structs

Examples

Functions to start or stop the server

More on the file cmd/without_server/main.go

package main

import (
    sonoff "github.com/fromsi/mqtt_sonoff_basic_r2"
    "os"
    "os/signal"
    "syscall"
)

func main() {
    // init

    sigSystem := make(chan os.Signal, 1)

    signal.Notify(sigSystem, syscall.SIGINT, syscall.SIGTERM)

    server, err := sonoff.NewSonoffBasicR2("", 1883, 0)

    if err != nil {
        panic(err.Error())
    }

    // run

    go func() {
        _ = server.Serve()
    }()

    // ... your code ...
    // ...

    // stop

    select {
    case <-sigSystem:
        _ = server.Close()
    }
}

Receive notification of connection or disconnection
//...

func main() {
    // init
    // ...

    // run
    // ...

    // ... your code ...

    go func() {
        for {
            select {
            case id, ok := <-server.TeleConnected():
                if !ok {
                    return
                }

                log.Println("Connected", id)
            }
        }
    }()

    go func() {
        for {
            select {
            case id, ok := <-server.TeleDisconnected():
                if !ok {
                    return
                }

                log.Println("Disconnected", id)
            }
        }
    }()

    // stop
    // ...
}
Changing Power ON/OFF/TOGGLE
//...

func main() {
    // init
    // ...

    // run
    // ...

    // ... your code ...

    // connected with id
    time.Sleep(1 * time.Second)
    
    server.PowerOn(id)
    
    time.Sleep(1 * time.Second)
    
    server.PowerOff(id)
    
    time.Sleep(1 * time.Second)
    
    server.PowerToggle(id)
    
    time.Sleep(1 * time.Second)
    
    server.PowerOff(id)
    // connected with id

    // stop
    // ...
}
Changing Physical Button ON/OFF
//...

func main() {
    // init
    // ...

    // run
    // ...

    // ... your code ...

    // connected with id
    value, _ := StatusPhysicalButton(id)
    log.Println(id, "PhysicalButton", value)

    time.Sleep(1 * time.Second)
    
    server.PhysicalButtonOn(id)
    value, _ = StatusPhysicalButton(id)
    log.Println(id, "PhysicalButton", value)
    
    time.Sleep(1 * time.Second)
    
    server.PhysicalButtonOff(id)
    value, _ = StatusPhysicalButton(id)
    log.Println(id, "PhysicalButton", value)
    // connected with id

    // stop
    // ...
}
Getting Status (0-11) with timeout and structs
//...

func main() {
    // init
    // ...

    // run
    // ...

    // ... your code ...

    // connected with id
    time.Sleep(1 * time.Second)
    
    server.PowerOn(id)
    
    response, _ = server.Status(id)
    log.Println(response.Status.Topic, "POWER", response.Status.Power, "TIME", response.StatusTIM.Local.ToTime().String())
    
    time.Sleep(1 * time.Second)
    
    server.PowerOff(id)
    
    response, _ = server.Status(id)
    log.Println(response.Status.Topic, "POWER", response.Status.Power, "TIME", response.StatusTIM.Local.ToTime().String())
    // connected with id

    // stop
    // ...
}
Using the library as a wrapper for your server

More on the mochi-mqtt/server

package main

import (
    sonoff "github.com/fromsi/mqtt_sonoff_basic_r2"
    mqtt "github.com/mochi-mqtt/server/v2"
    mqttauth "github.com/mochi-mqtt/server/v2/hooks/auth"
    "github.com/mochi-mqtt/server/v2/listeners"
)

func main() {
    server := mqtt.New(
        &mqtt.Options{
            InlineClient: true,
        },
    )

    tcp := listeners.NewTCP(listeners.Config{ID: "t1", Address: ":1883"})
    _ = server.AddListener(tcp)
    _ = server.AddHook(new(mqttauth.AllowHook), nil)

    sonoffServer, _ := sonoff.NewSonoffBasicR2WithServer(server, 2)
	
    // run

    go func() {
        _ = sonoffServer.Serve()
        _ = server.Serve()
    }()

    // more on the file `cmd/without_server/main.go`
    // ... your code ...

    // stop

    sonoffServer.Close()
    server.Close()
}

Documentation

Overview

Example (WithServer)
package main

import (
	sonoff "github.com/fromsi/mqtt_sonoff_basic_r2"
	mqtt "github.com/mochi-mqtt/server/v2"

	mqttauth "github.com/mochi-mqtt/server/v2/hooks/auth"
	"github.com/mochi-mqtt/server/v2/listeners"
	"log"
	"os"
	"os/signal"
	"syscall"
)

func main() {
	// init

	sigSystem := make(chan os.Signal, 1)

	signal.Notify(sigSystem, syscall.SIGINT, syscall.SIGTERM)

	server := mqtt.New(
		&mqtt.Options{
			InlineClient: true,
		},
	)

	tcp := listeners.NewTCP(listeners.Config{ID: "t1", Address: ":1883"})
	err := server.AddListener(tcp)

	if err != nil {
		panic(err.Error())
	}

	err = server.AddHook(new(mqttauth.AllowHook), nil)

	if err != nil {
		panic(err.Error())
	}

	sonoffServer, err := sonoff.NewSonoffBasicR2WithServer(server, 2)

	if err != nil {
		panic(err.Error())
	}

	// run

	go func() {
		_ = sonoffServer.Serve()
		_ = server.Serve()
	}()

	// ... your code ...

	go func() {
		for {
			select {
			case id, ok := <-sonoffServer.TeleConnected():
				if !ok {
					return
				}

				log.Println("Connected", id)

				sonoffServer.PowerToggle(id)
			}
		}
	}()

	// stop

	select {
	case <-sigSystem:
		_ = sonoffServer.Close()
		_ = server.Close()
	}
}
Example (WithoutServer)
package main

import (
	sonoff "github.com/fromsi/mqtt_sonoff_basic_r2"
	"log"
	"os"
	"os/signal"
	"syscall"
)

func main() {
	// init

	sigSystem := make(chan os.Signal, 1)

	signal.Notify(sigSystem, syscall.SIGINT, syscall.SIGTERM)

	server, err := sonoff.NewSonoffBasicR2("", 1883, 0)

	if err != nil {
		panic(err.Error())
	}

	// run

	go func() {
		_ = server.Serve()
	}()

	// ... your code ...

	go func() {
		for {
			select {
			case id, ok := <-server.TeleConnected():
				if !ok {
					return
				}

				log.Println("Connected", id)

				server.PowerToggle(id)
			}
		}
	}()

	// stop

	select {
	case <-sigSystem:
		_ = server.Close()
	}
}

Index

Examples

Constants

View Source
const (
	// TasmotaPrefixTele is used for telemetry topics that report device status at regular intervals.
	TasmotaPrefixTele = "tele"

	// TasmotaPrefixStat is used for status topics, which report the device's response to commands or state changes.
	TasmotaPrefixStat = "stat"

	// TasmotaPrefixCmnd is used for command topics to send instructions to the device.
	TasmotaPrefixCmnd = "cmnd"
)

MQTT topic prefixes used by Tasmota firmware for communication

View Source
const (
	// TasmotaTeleTopicLWT is the Last Will and Testament topic used by Tasmota devices to report their availability.
	TasmotaTeleTopicLWT = "LWT"

	// TasmotaTeleTopicLWTValueAll subscribes to all LWT topics.
	TasmotaTeleTopicLWTValueAll = "+"

	// TasmotaTeleTopicLWTResponseOnline is the message indicating that the device is online.
	TasmotaTeleTopicLWTResponseOnline = "Online"

	// TasmotaTeleTopicLWTResponseOffline is the message indicating that the device is offline.
	TasmotaTeleTopicLWTResponseOffline = "Offline"
)

MQTT telemetry (tele) topics

View Source
const (
	// TasmotaCmndTopicStatus requests the status of the device.
	TasmotaCmndTopicStatus = "STATUS"

	// TasmotaCmndTopicStatusAll requests the status of all device components.
	TasmotaCmndTopicStatusAll = "STATUS0"

	// TasmotaCmndTopicPower controls the power state of the device (on, off, toggle).
	TasmotaCmndTopicPower = "POWER"

	// TasmotaCmndTopicPowerValueOn turns the device power on.
	TasmotaCmndTopicPowerValueOn = "ON"

	// TasmotaCmndTopicPowerValueOff turns the device power off.
	TasmotaCmndTopicPowerValueOff = "OFF"

	// TasmotaCmndTopicPowerValueToggle toggles the device power between on and off.
	TasmotaCmndTopicPowerValueToggle = "TOGGLE"

	// TasmotaCmndTopicPhysicalButton configures the physical button behavior (SETOPTION73).
	TasmotaCmndTopicPhysicalButton = "SETOPTION73"

	// TasmotaCmndTopicPhysicalButtonValueOn disables the physical button.
	TasmotaCmndTopicPhysicalButtonValueOn = "0"

	// TasmotaCmndTopicPhysicalButtonValueOff enables the physical button.
	TasmotaCmndTopicPhysicalButtonValueOff = "1"
)

MQTT command (cmnd) topics

View Source
const (
	// TasmotaStatTopicResult provides the result of a command execution.
	TasmotaStatTopicResult = "RESULT"

	// TasmotaStatTopicStatus is the general status response topic.
	TasmotaStatTopicStatus = "STATUS0"

	// TasmotaStatTopicStatusOne to TasmotaStatTopicStatusEleven represent different status responses of the device.
	TasmotaStatTopicStatusOne         = "STATUS1"
	TasmotaStatTopicStatusOneValue    = "1"
	TasmotaStatTopicStatusTwo         = "STATUS2"
	TasmotaStatTopicStatusTwoValue    = "2"
	TasmotaStatTopicStatusThree       = "STATUS3"
	TasmotaStatTopicStatusThreeValue  = "3"
	TasmotaStatTopicStatusFour        = "STATUS4"
	TasmotaStatTopicStatusFourValue   = "4"
	TasmotaStatTopicStatusFive        = "STATUS5"
	TasmotaStatTopicStatusFiveValue   = "5"
	TasmotaStatTopicStatusSix         = "STATUS6"
	TasmotaStatTopicStatusSixValue    = "6"
	TasmotaStatTopicStatusSeven       = "STATUS7"
	TasmotaStatTopicStatusSevenValue  = "7"
	TasmotaStatTopicStatusEight       = "STATUS8"
	TasmotaStatTopicStatusEightValue  = "8"
	TasmotaStatTopicStatusEleven      = "STATUS11"
	TasmotaStatTopicStatusElevenValue = "11"
)

MQTT status (stat) topics

View Source
const DefaultCtxCmndResponseTimeoutInSeconds = 10

DefaultCtxCmndResponseTimeoutInSeconds is default value for ctxCmndResponseTimeoutInSeconds

Variables

This section is empty.

Functions

This section is empty.

Types

type MochiMQTTV2

type MochiMQTTV2 interface {
	Serve() error
	Close() error
	Subscribe(filter string, subscriptionId int, handler mqtt.InlineSubFn) error
	Unsubscribe(filter string, subscriptionId int) error
	Publish(topic string, payload []byte, retain bool, qos byte) error
}

MochiMQTTV2 is interface to support dependency inversion

type SonoffBasicR2

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

SonoffBasicR2 is a struct that manages MQTT connections to a Sonoff Basic R2 device using the Tasmota firmware. It handles device commands, status checks, and power control over MQTT.

func NewSonoffBasicR2

func NewSonoffBasicR2(ip string, port uint16, qos byte) (*SonoffBasicR2, error)

NewSonoffBasicR2 initializes a new instance of SonoffBasicR2 and sets up an internal MQTT server. It listens for TCP connections on the provided IP and port and allows connections from MQTT clients.

func NewSonoffBasicR2WithServer

func NewSonoffBasicR2WithServer(server MochiMQTTV2, qos byte) (*SonoffBasicR2, error)

NewSonoffBasicR2WithServer initializes a SonoffBasicR2 instance with an external MQTT server. The server must have the InlineClient option enabled. Warning: inline_client must be true.

func (SonoffBasicR2) Close

func (sonoffBasicR2 SonoffBasicR2) Close() error

Close closes the MQTT server and stops the internal channels.

func (SonoffBasicR2) GetCtxCmndResponseTimeoutInSeconds

func (sonoffBasicR2 SonoffBasicR2) GetCtxCmndResponseTimeoutInSeconds() uint

GetCtxCmndResponseTimeoutInSeconds returns the command response timeout duration in seconds.

func (SonoffBasicR2) PhysicalButtonOff

func (sonoffBasicR2 SonoffBasicR2) PhysicalButtonOff(id string)

PhysicalButtonOff sends an MQTT command to disable the physical button on the Sonoff device. This prevents the device's physical button from toggling the power. It corresponds to the Tasmota command SetOption73.

func (SonoffBasicR2) PhysicalButtonOn

func (sonoffBasicR2 SonoffBasicR2) PhysicalButtonOn(id string)

PhysicalButtonOn sends an MQTT command to enable the physical button on the Sonoff device. This allows the device's physical button to control power toggling. It corresponds to the Tasmota command SetOption73.

func (SonoffBasicR2) PowerOff

func (sonoffBasicR2 SonoffBasicR2) PowerOff(id string)

PowerOff sends an MQTT command to turn off the device.

func (SonoffBasicR2) PowerOn

func (sonoffBasicR2 SonoffBasicR2) PowerOn(id string)

PowerOn sends an MQTT command to turn on the device.

func (SonoffBasicR2) PowerToggle

func (sonoffBasicR2 SonoffBasicR2) PowerToggle(id string)

PowerToggle sends an MQTT command to toggle the power state of the Sonoff device. It switches the power between ON and OFF, depending on the current state.

func (SonoffBasicR2) Serve

func (sonoffBasicR2 SonoffBasicR2) Serve() error

Serve starts the MQTT server and subscribes to connection status topics for devices. It handles the telemetric connection status (`LWT` - Last Will and Testament) from Tasmota devices.

func (*SonoffBasicR2) SetCtxCmndResponseTimeoutInSeconds

func (sonoffBasicR2 *SonoffBasicR2) SetCtxCmndResponseTimeoutInSeconds(value uint)

SetCtxCmndResponseTimeoutInSeconds sets the command response timeout duration in seconds.

func (SonoffBasicR2) Status

func (sonoffBasicR2 SonoffBasicR2) Status(id string) (*Status, error)

Status retrieves the complete status (STATUS 0) of the Sonoff device via MQTT. This includes the device's overall configuration and current state. The response is unmarshaled into the AutoGenerated structure.

func (SonoffBasicR2) StatusEight

func (sonoffBasicR2 SonoffBasicR2) StatusEight(id string) (*StatusEight, error)

StatusEight retrieves sensor data (STATUS 8) from the Sonoff device. This includes the most recent readings from the device's sensors.

func (SonoffBasicR2) StatusEleven

func (sonoffBasicR2 SonoffBasicR2) StatusEleven(id string) (*StatusEleven, error)

StatusEleven retrieves runtime status information (STATUS 11) from the Sonoff device. This includes uptime, heap usage, WiFi information, and more.

func (SonoffBasicR2) StatusFive

func (sonoffBasicR2 SonoffBasicR2) StatusFive(id string) (*StatusFive, error)

StatusFive retrieves network configuration details (STATUS 5) from the Sonoff device. This includes IP address, gateway, subnet mask, and DNS server information.

func (SonoffBasicR2) StatusFour

func (sonoffBasicR2 SonoffBasicR2) StatusFour(id string) (*StatusFour, error)

StatusFour retrieves memory and storage-related information (STATUS 4) from the Sonoff device. This includes program size, free heap space, flash size, and other memory metrics.

func (SonoffBasicR2) StatusOne

func (sonoffBasicR2 SonoffBasicR2) StatusOne(id string) (*StatusOne, error)

StatusOne retrieves specific system-related information (STATUS 1) from the Sonoff device. This includes details like uptime, boot count, and other system parameters.

func (SonoffBasicR2) StatusPhysicalButton

func (sonoffBasicR2 SonoffBasicR2) StatusPhysicalButton(id string) (bool, error)

StatusPhysicalButton retrieves the current configuration of the physical button on the Sonoff device. It checks the status of SetOption73, which controls whether the physical button is enabled (OFF) or disabled (ON).

func (SonoffBasicR2) StatusSeven

func (sonoffBasicR2 SonoffBasicR2) StatusSeven(id string) (*StatusSeven, error)

StatusSeven retrieves time and date settings (STATUS 7) from the Sonoff device. This includes local time, daylight savings settings, and timezone information.

func (SonoffBasicR2) StatusSix

func (sonoffBasicR2 SonoffBasicR2) StatusSix(id string) (*StatusSix, error)

StatusSix retrieves MQTT configuration information (STATUS 6) from the Sonoff device. This includes MQTT host, port, client ID, and other MQTT settings.

func (SonoffBasicR2) StatusThree

func (sonoffBasicR2 SonoffBasicR2) StatusThree(id string) (*StatusThree, error)

StatusThree retrieves logging-related settings (STATUS 3) from the Sonoff device. This includes serial, web, and MQTT log configurations.

func (SonoffBasicR2) StatusTwo

func (sonoffBasicR2 SonoffBasicR2) StatusTwo(id string) (*StatusTwo, error)

StatusTwo retrieves firmware-related information (STATUS 2) from the Sonoff device. This includes firmware version, build date, and other firmware-specific data.

func (SonoffBasicR2) TeleConnected

func (sonoffBasicR2 SonoffBasicR2) TeleConnected() <-chan string

TeleConnected returns a channel that emits the ID of a device when it is connected to the MQTT broker.

func (SonoffBasicR2) TeleDisconnected

func (sonoffBasicR2 SonoffBasicR2) TeleDisconnected() <-chan string

TeleDisconnected returns a channel that emits the ID of a device when it is disconnected from the MQTT broker.

type Status

type Status struct {
	Status    StatusZero   `json:"Status"`
	StatusPRM StatusOne    `json:"StatusPRM"`
	StatusFWR StatusTwo    `json:"StatusFWR"`
	StatusLOG StatusThree  `json:"StatusLOG"`
	StatusMEM StatusFour   `json:"StatusMEM"`
	StatusNET StatusFive   `json:"StatusNET"`
	StatusMQT StatusSix    `json:"StatusMQT"`
	StatusTIM StatusSeven  `json:"StatusTIM"`
	StatusSNS StatusEight  `json:"StatusSNS"`
	StatusSTS StatusEleven `json:"StatusSTS"`
}

Status combines various status commands into one structure. It represents the entire set of status information returned by a Tasmota device, including system, network, and sensor data. See the full Tasmota documentation: https://tasmota.github.io/docs/Commands/#management

func UnmarshalStatus

func UnmarshalStatus(data []byte) (*Status, error)

UnmarshalStatus unmarshals the entire set of Tasmota status information from JSON data.

type StatusEight

type StatusEight struct {
	Time TasmotaTime `json:"Time"`
}

StatusEight represents sensor data collected from the device. It corresponds to the Status 8 command in Tasmota, also known as StatusSNS (Sensor Status). See: https://tasmota.github.io/docs/Commands/#management

func UnmarshalStatusEight

func UnmarshalStatusEight(data []byte) (*StatusEight, error)

UnmarshalStatusEight unmarshals the sensor data (Status 8) from JSON data.

type StatusEleven

type StatusEleven struct {
	Time      TasmotaTime `json:"Time"`
	Uptime    string      `json:"Uptime"`
	UptimeSec int         `json:"UptimeSec"`
	Heap      int         `json:"Heap"`
	SleepMode string      `json:"SleepMode"`
	Sleep     int         `json:"Sleep"`
	LoadAvg   int         `json:"LoadAvg"`
	MqttCount int         `json:"MqttCount"`
	POWER     string      `json:"POWER"`
	Wifi      struct {
		AP        int    `json:"AP"`
		SSID      string `json:"SSId"`
		BSSID     string `json:"BSSId"`
		Channel   int    `json:"Channel"`
		Mode      string `json:"Mode"`
		RSSI      int    `json:"RSSI"`
		Signal    int    `json:"Signal"`
		LinkCount int    `json:"LinkCount"`
		Downtime  string `json:"Downtime"`
	} `json:"Wifi"`
}

StatusEleven represents the runtime status of the device, including uptime, heap usage, and WiFi information. It corresponds to the Status 11 command in Tasmota, also known as StatusSTS (Status System). See: https://tasmota.github.io/docs/Commands/#management

func UnmarshalStatusEleven

func UnmarshalStatusEleven(data []byte) (*StatusEleven, error)

UnmarshalStatusEleven unmarshals the runtime status (Status 11) from JSON data.

type StatusFive

type StatusFive struct {
	Hostname   string  `json:"Hostname"`
	IPAddress  string  `json:"IPAddress"`
	Gateway    string  `json:"Gateway"`
	Subnetmask string  `json:"Subnetmask"`
	DNSServer1 string  `json:"DNSServer1"`
	DNSServer2 string  `json:"DNSServer2"`
	Mac        string  `json:"Mac"`
	Webserver  int     `json:"Webserver"`
	HTTPAPI    int     `json:"HTTP_API"`
	WifiConfig int     `json:"WifiConfig"`
	WifiPower  float64 `json:"WifiPower"`
}

StatusFive represents the network configuration of the device, including IP addresses, DNS settings, and MAC address. It corresponds to the Status 5 command in Tasmota. See: https://tasmota.github.io/docs/Commands/#management

func UnmarshalStatusFive

func UnmarshalStatusFive(data []byte) (*StatusFive, error)

UnmarshalStatusFive unmarshals the network configuration (Status 5) from JSON data.

type StatusFour

type StatusFour struct {
	ProgramSize      int      `json:"ProgramSize"`
	Free             int      `json:"Free"`
	Heap             int      `json:"Heap"`
	ProgramFlashSize int      `json:"ProgramFlashSize"`
	FlashSize        int      `json:"FlashSize"`
	FlashChipID      string   `json:"FlashChipId"`
	FlashFrequency   int      `json:"FlashFrequency"`
	FlashMode        string   `json:"FlashMode"`
	Features         []string `json:"Features"`
	Drivers          string   `json:"Drivers"`
	Sensors          string   `json:"Sensors"`
	I2CDriver        string   `json:"I2CDriver"`
}

StatusFour represents the memory status of the device, including flash memory and heap size. It corresponds to the Status 4 command in Tasmota. See: https://tasmota.github.io/docs/Commands/#management

func UnmarshalStatusFour

func UnmarshalStatusFour(data []byte) (*StatusFour, error)

UnmarshalStatusFour unmarshals the memory status (Status 4) from JSON data.

type StatusOne

type StatusOne struct {
	Baudrate      int         `json:"Baudrate"`
	SerialConfig  string      `json:"SerialConfig"`
	GroupTopic    string      `json:"GroupTopic"`
	OtaURL        string      `json:"OtaUrl"`
	RestartReason string      `json:"RestartReason"`
	Uptime        string      `json:"Uptime"`
	StartupUTC    TasmotaTime `json:"StartupUTC"`
	Sleep         int         `json:"Sleep"`
	CfgHolder     int         `json:"CfgHolder"`
	BootCount     int         `json:"BootCount"`
	BCResetTime   TasmotaTime `json:"BCResetTime"`
	SaveCount     int         `json:"SaveCount"`
	SaveAddress   string      `json:"SaveAddress"`
}

StatusOne represents system and configuration details of a Tasmota device, such as baudrate and OTA URL. It corresponds to the Status 1 command in Tasmota. See: https://tasmota.github.io/docs/Commands/#management

func UnmarshalStatusOne

func UnmarshalStatusOne(data []byte) (*StatusOne, error)

UnmarshalStatusOne unmarshals the system status (Status 1) from JSON data.

type StatusSeven

type StatusSeven struct {
	UTC      time.Time   `json:"UTC"`
	Local    TasmotaTime `json:"Local"`
	StartDST TasmotaTime `json:"StartDST"`
	EndDST   TasmotaTime `json:"EndDST"`
	Timezone string      `json:"Timezone"`
	Sunrise  string      `json:"Sunrise"`
	Sunset   string      `json:"Sunset"`
}

StatusSeven represents the time settings of the device, including local time, daylight saving time (DST), and time zone. It corresponds to the Status 7 command in Tasmota. See: https://tasmota.github.io/docs/Commands/#management

func UnmarshalStatusSeven

func UnmarshalStatusSeven(data []byte) (*StatusSeven, error)

UnmarshalStatusSeven unmarshals the time settings (Status 7) from JSON data.

type StatusSix

type StatusSix struct {
	MqttHost       string `json:"MqttHost"`
	MqttPort       int    `json:"MqttPort"`
	MqttClientMask string `json:"MqttClientMask"`
	MqttClient     string `json:"MqttClient"`
	MqttUser       string `json:"MqttUser"`
	MqttCount      int    `json:"MqttCount"`
	MAXPACKETSIZE  int    `json:"MAX_PACKET_SIZE"`
	KEEPALIVE      int    `json:"KEEPALIVE"`
	SOCKETTIMEOUT  int    `json:"SOCKET_TIMEOUT"`
}

StatusSix represents MQTT configuration and settings of the Tasmota device, such as MQTT host, port, and client information. It corresponds to the Status 6 command in Tasmota. See: https://tasmota.github.io/docs/Commands/#management

func UnmarshalStatusSix

func UnmarshalStatusSix(data []byte) (*StatusSix, error)

UnmarshalStatusSix unmarshals the MQTT configuration (Status 6) from JSON data.

type StatusThree

type StatusThree struct {
	SerialLog  int      `json:"SerialLog"`
	WebLog     int      `json:"WebLog"`
	MqttLog    int      `json:"MqttLog"`
	SysLog     int      `json:"SysLog"`
	LogHost    string   `json:"LogHost"`
	LogPort    int      `json:"LogPort"`
	SSID       []string `json:"SSId"`
	TelePeriod int      `json:"TelePeriod"`
	Resolution string   `json:"Resolution"`
	SetOption  []string `json:"SetOption"`
}

StatusThree represents the logging configuration of the device, including log levels and host settings. It corresponds to the Status 3 command in Tasmota. See: https://tasmota.github.io/docs/Commands/#management

func UnmarshalStatusThree

func UnmarshalStatusThree(data []byte) (*StatusThree, error)

UnmarshalStatusThree unmarshals the logging status (Status 3) from JSON data.

type StatusTwo

type StatusTwo struct {
	Version       string      `json:"Version"`
	BuildDateTime TasmotaTime `json:"BuildDateTime"`
	Boot          int         `json:"Boot"`
	Core          string      `json:"Core"`
	SDK           string      `json:"SDK"`
	CPUFrequency  int         `json:"CpuFrequency"`
	Hardware      string      `json:"Hardware"`
	CR            string      `json:"CR"`
}

StatusTwo represents firmware details of the Tasmota device, such as version and build date. It corresponds to the Status 2 command in Tasmota. See: https://tasmota.github.io/docs/Commands/#management

func UnmarshalStatusTwo

func UnmarshalStatusTwo(data []byte) (*StatusTwo, error)

UnmarshalStatusTwo unmarshals the firmware status (Status 2) from JSON data.

type StatusZero

type StatusZero struct {
	Module       int      `json:"Module"`
	DeviceName   string   `json:"DeviceName"`
	FriendlyName []string `json:"FriendlyName"`
	Topic        string   `json:"Topic"`
	ButtonTopic  string   `json:"ButtonTopic"`
	Power        string   `json:"Power"`
	PowerLock    string   `json:"PowerLock"`
	PowerOnState int      `json:"PowerOnState"`
	LedState     int      `json:"LedState"`
	LedMask      string   `json:"LedMask"`
	SaveData     int      `json:"SaveData"`
	SaveState    int      `json:"SaveState"`
	SwitchTopic  string   `json:"SwitchTopic"`
	SwitchMode   []int    `json:"SwitchMode"`
	ButtonRetain int      `json:"ButtonRetain"`
	SwitchRetain int      `json:"SwitchRetain"`
	SensorRetain int      `json:"SensorRetain"`
	PowerRetain  int      `json:"PowerRetain"`
	InfoRetain   int      `json:"InfoRetain"`
	StateRetain  int      `json:"StateRetain"`
	StatusRetain int      `json:"StatusRetain"`
}

StatusZero represents the JSON structure of the device status information returned by Tasmota. It contains general information about the device such as the module type, power state, and more. See: https://tasmota.github.io/docs/Commands/#management

func UnmarshalStatusZero

func UnmarshalStatusZero(data []byte) (*StatusZero, error)

UnmarshalStatusZero unmarshals the device status (Status 0) from JSON data.

type TasmotaTime

type TasmotaTime time.Time

TasmotaTime is a custom time type used to parse and format Tasmota's specific date-time format (YYYY-MM-DDTHH:MM:SS). Tasmota is a firmware for ESP8266 devices, like Sonoff, which communicates over MQTT and provides device status in JSON format. More about Tasmota: https://tasmota.github.io/docs/

func (TasmotaTime) MarshalJSON

func (tasmotaTime TasmotaTime) MarshalJSON() ([]byte, error)

MarshalJSON handles converting TasmotaTime into a string in the Tasmota-specific format when marshaling JSON data.

func (TasmotaTime) ToTime

func (tasmotaTime TasmotaTime) ToTime() time.Time

ToTime converts TasmotaTime back to the standard Go time.Time type.

func (*TasmotaTime) UnmarshalJSON

func (tasmotaTime *TasmotaTime) UnmarshalJSON(value []byte) error

UnmarshalJSON handles parsing the Tasmota-specific time format when unmarshaling JSON data.

Directories

Path Synopsis
cmd
with_server command
without_server command

Jump to

Keyboard shortcuts

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