zdo

package
v0.6.61 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

zhub4 - Система домашней автоматизации на Go Copyright (c) 2022-2023 GSB, Georgii Batanov gbatanov@yandex.ru MIT License

zhub4 - Система домашней автоматизации на Go Copyright (c) 2022-2023 GSB, Georgii Batanov gbatanov@yandex.ru MIT License

Index

Constants

View Source
const BUTTON_IKEA = uint64(0x8cf681fffe0656ef)
View Source
const BUTTON_SONOFF_1 = uint64(0x00124b0028928e8a)
View Source
const BUTTON_SONOFF_2 = uint64(0x00124b00253ba75f)
View Source
const CLIMAT_BALCON = uint64(0x00124b000b1bb401)
View Source
const DOOR_1_TOILET = uint64(0x00124b0025485ee6)
View Source
const DOOR_2_CAB = uint64(0x00124b002512a60b)
View Source
const DOOR_3_BOX = uint64(0x00124b00250bba63)
View Source
const MOTION_1_CORIDOR = uint64(0x00124b0025137475)
View Source
const MOTION_2_ROOM = uint64(0x00124b0024455048)
View Source
const MOTION_3_CORIDOR = uint64(0x00124b002444d159)
View Source
const MOTION_4_NURSERY = uint64(0x00124b002a535b66)
View Source
const MOTION_5_KITCHEN = uint64(0x00124b002a507fe2)
View Source
const MOTION_IKEA = uint64(0x0c4314fffe17d8a8)
View Source
const MOTION_LIGHT_CORIDOR = uint64(0x00124b0014db2724)
View Source
const MOTION_LIGHT_NURSERY = uint64(0x00124b0007246963)
View Source
const PLUG_1 = uint64(0x70b3d52b6001b4a4)
View Source
const PLUG_2_CHARGER = uint64(0x70b3d52b6001b5d9)
View Source
const PLUG_3_NURSERY_LIGHT = uint64(0x70b3d52b60022ac9)
View Source
const PLUG_4_SOLDER = uint64(0x70b3d52b60022cfd)
View Source
const PRESENCE_1_KITCHEN = uint64(0x00124b0009451438)
View Source
const RELAY_1 = uint64(0x54ef44100019335b)
View Source
const RELAY_2_WASH = uint64(0x54ef441000193352)
View Source
const RELAY_3_CAB_LIGHT = uint64(0x54ef44100018b523)
View Source
const RELAY_4_CORIDOR_LIGHT = uint64(0x54ef4410001933d3)
View Source
const RELAY_5_TOILET = uint64(0x54ef4410005b2639)
View Source
const RELAY_6_ROOM_LIGHT = uint64(0x54ef441000609dcc)
View Source
const RELAY_7_KITCHEN = uint64(0x00158d0009414d7e)
View Source
const VALVE_COLD_WATER = uint64(0xa4c138373e89d731)
View Source
const VALVE_HOT_WATER = uint64(0xa4c138d9758e1dcd)
View Source
const WATER_LEAK_1 = uint64(0x00158d0006e469a4)
View Source
const WATER_LEAK_2 = uint64(0x00158d0006f8fc61)
View Source
const WATER_LEAK_3 = uint64(0x00158d0006b86b79)
View Source
const WATER_LEAK_4 = uint64(0x00158d0006ea99db)

Variables

View Source
var DEVICE_TYPES map[uint8]string = map[uint8]string{
	1: "SonoffButton",
	2: "SonoffMotionSensor",
	3: "SonoffDoorSensor",
	4: "Custom",
	5: "WaterSensor",
	6: "WaterValve",
	7: "IkeaButton",
	8: "IkeaMotionSensor",
	9: "RelayAqara",

	10: "SmartPlug",
	11: "RelayAqaraDouble",

} //            2 -?

Input clusters can have commands sent to them to perform actions, where as output clusters instead send these commands to a bound device.

View Source
var KNOWN_DEVICES map[uint64]DeviceInfo = map[uint64]DeviceInfo{

	WATER_LEAK_1: {5, "Aqara", "SJCGQ11LM", "Протечка1", "Датчик протечки 1 (туалет)", zcl.PowerSource_BATTERY, 1, 0},
	WATER_LEAK_2: {5, "Aqara", "SJCGQ11LM", "Протечка2", "Датчик протечки 2 (кухня)", zcl.PowerSource_BATTERY, 1, 0},
	WATER_LEAK_3: {5, "Aqara", "SJCGQ11LM", "Протечка3", "Датчик протечки 3 (ванна)", zcl.PowerSource_BATTERY, 1, 0},
	WATER_LEAK_4: {5, "Aqara", "SJCGQ11LM", "Протечка4", "Датчик протечки 4 (кухня)", zcl.PowerSource_BATTERY, 1, 0},

	RELAY_2_WASH: {9, "Aqara", "SSM-U01", "Стиралка", "Реле2(Стиральная машина)", zcl.PowerSource_SINGLE_PHASE, 1, 0},

	RELAY_4_CORIDOR_LIGHT: {9, "Aqara", "SSM-U01", "КоридорСвет", "Реле4(Свет в коридоре)", zcl.PowerSource_SINGLE_PHASE, 1, 0},
	RELAY_5_TOILET:        {9, "Aqara", "SSM-U01", "ТулетЗанят", "Реле5(Туалет занят)", zcl.PowerSource_SINGLE_PHASE, 1, 0},
	RELAY_6_ROOM_LIGHT:    {9, "Aqara", "SSM-U01", "Реле6", "Реле6 (Свет комната)", zcl.PowerSource_SINGLE_PHASE, 1, 1},
	RELAY_7_KITCHEN:       {11, "Aqara", "Double", "КухняСвет/КухняВент", "Реле 7(Свет/Вентилятор кухня)", zcl.PowerSource_SINGLE_PHASE, 1, 0},

	PLUG_2_CHARGER:       {10, "Girier", "TS011F", "Розетка2", "Розетка 2(Зарядники)", zcl.PowerSource_SINGLE_PHASE, 1, 0},
	PLUG_3_NURSERY_LIGHT: {10, "Girier", "TS011F", "Розетка3", "Розетка 3(Лампы в детской)", zcl.PowerSource_SINGLE_PHASE, 1, 0},

	VALVE_HOT_WATER:  {6, "TUYA", "Valve", "КранГВ", "Кран1 ГВ", zcl.PowerSource_SINGLE_PHASE, 1, 0},
	VALVE_COLD_WATER: {6, "TUYA", "Valve", "КранХВ", "Кран2 ХВ", zcl.PowerSource_SINGLE_PHASE, 1, 0},

	MOTION_1_CORIDOR: {2, "Sonoff", "SNZB-03", "КоридорДвижение", "Датчик движения 1 (коридор)", zcl.PowerSource_BATTERY, 1, 0},
	MOTION_2_ROOM:    {2, "Sonoff", "SNZB-03", "КомнатаДвижение", "Датчик движения 2 (комната)", zcl.PowerSource_BATTERY, 1, 0},
	MOTION_3_CORIDOR: {2, "Sonoff", "SNZB-03", "Движение3", "Датчик движения 3(коридор) ", zcl.PowerSource_BATTERY, 1, 0},
	MOTION_4_NURSERY: {2, "Sonoff", "SNZB-03", "ДетскаяДвижение4", "Датчик движения 4 (детская)", zcl.PowerSource_BATTERY, 1, 0},

	PRESENCE_1_KITCHEN: {4, "Custom", "CC2530", "КухняПрисутствие", "Датчик присутствия 1 (кухня)", zcl.PowerSource_SINGLE_PHASE, 1, 0},

	MOTION_LIGHT_NURSERY: {4, "Custom", "CC2530", "ДетскаяДвижение", "Датчик движение + освещение (детская)", zcl.PowerSource_SINGLE_PHASE, 1, 0},

	DOOR_1_TOILET: {3, "Sonoff", "SNZB-04", "ТуалетДатчик", "Датчик открытия 1 (туалет)", zcl.PowerSource_BATTERY, 1, 0},

	BUTTON_SONOFF_2: {1, "Sonoff", "SNZB-01", "Кнопка2", "Кнопка Sonoff 2", zcl.PowerSource_BATTERY, 1, 0},

	CLIMAT_BALCON: {4, "GSB", "CC2530", "КлиматБалкон", "Датчик климата (балкон)", zcl.PowerSource_BATTERY, 1, 0},
}

MAC Address,Type, Vendor,Model, GrafanaName, Human name, Power source,available,test

List of devices that are turned off by long pressing the Sonoff1 button I use the same list for forced shutdown in the mode "No one is at home"

View Source
var PROM_DOOR_LIST []uint64 = []uint64{
	DOOR_1_TOILET,
}
View Source
var PROM_RELAY_LIST []uint64 = []uint64{
	RELAY_7_KITCHEN,
	RELAY_4_CORIDOR_LIGHT,

	RELAY_5_TOILET} // toilet is busy

Functions

func Command_to_string

func Command_to_string(c CommandId) string

func GetDevicesByType

func GetDevicesByType(tp uint8) []uint64

Types

type BatteryParams

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

type Command

type Command struct {
	Id      CommandId // command ID
	Payload []byte    // payload field
}

func New2

func New2(cmnd CommandId, payload_length uint8) *Command

command with payload

func NewCommand

func NewCommand(cmnd CommandId) *Command

empty command

func (Command) Fcs

func (c Command) Fcs() byte

control summ

func (Command) Payload_size

func (c Command) Payload_size() byte

get payload size (size of field "Payload")

func (*Command) Set_data

func (c *Command) Set_data(data []byte)

type CommandId

type CommandId uint16

commands

const (
	//System
	SYS_RESET_REQ              CommandId = 0x4100
	SYS_RESET_IND              CommandId = 0x4180
	SYS_PING                   CommandId = 0x2101
	SYS_PING_SRSP              CommandId = 0x6101
	SYS_OSAL_NV_READ           CommandId = 0x2108
	SYS_OSAL_NV_READ_SRSP      CommandId = 0x6108
	SYS_OSAL_NV_WRITE          CommandId = 0x2109
	SYS_OSAL_NV_WRITE_SRSP     CommandId = 0x6109
	SYS_OSAL_NV_ITEM_INIT      CommandId = 0x2107
	SYS_OSAL_NV_ITEM_INIT_SRSP CommandId = 0x6107
	SYS_OSAL_NV_LENGTH         CommandId = 0x2113
	SYS_OSAL_NV_LENGTH_SRSP    CommandId = 0x6113
	SYS_OSAL_NV_DELETE         CommandId = 0x2112
	SYS_OSAL_NV_DELETE_SRSP    CommandId = 0x6112
	SYS_SET_TX_POWER           CommandId = 0x2114
	SYS_SET_TX_POWER_SRSP      CommandId = 0x6114
	SYS_VERSION                CommandId = 0x2102
	SYS_VERSION_SRSP           CommandId = 0x6102

	// ZDO
	ZDO_STARTUP_FROM_APP_SRSP CommandId = 0x6540
	ZDO_STATE_CHANGE_IND      CommandId = 0x45c0
	ZDO_BIND_REQ              CommandId = 0x2521
	ZDO_BIND_RSP              CommandId = 0x45a1
	ZDO_BIND_SRSP             CommandId = 0x6521
	ZDO_UNBIND_REQ            CommandId = 0x2522
	ZDO_UNBIND_RSP            CommandId = 0x45a2
	ZDO_MGMT_LQI_REQ          CommandId = 0x2531
	ZDO_MGMT_LQI_SRSP         CommandId = 0x6531
	ZDO_MGMT_LQI_RSP          CommandId = 0x45b1
	ZDO_SRC_RTG_IND           CommandId = 0x45C4
	ZDO_MGMT_PERMIT_JOIN_REQ  CommandId = 0x2536
	ZDO_MGMT_PERMIT_JOIN_SRSP CommandId = 0x6536
	ZDO_MGMT_PERMIT_JOIN_RSP  CommandId = 0x45b6
	ZDO_PERMIT_JOIN_IND       CommandId = 0x45cb
	ZDO_TC_DEV_IND            CommandId = 0x45ca
	ZDO_LEAVE_IND             CommandId = 0x45c9
	ZDO_END_DEVICE_ANNCE_IND  CommandId = 0x45c1
	ZDO_ACTIVE_EP_REQ         CommandId = 0x2505
	ZDO_ACTIVE_EP_SRSP        CommandId = 0x6505
	ZDO_ACTIVE_EP_RSP         CommandId = 0x4585
	ZDO_SIMPLE_DESC_REQ       CommandId = 0x2504
	ZDO_SIMPLE_DESC_SRSP      CommandId = 0x6504
	ZDO_SIMPLE_DESC_RSP       CommandId = 0x4584
	ZDO_POWER_DESC_REQ        CommandId = 0x2503
	ZDO_POWER_DESC_SRSP       CommandId = 0x6503
	ZDO_POWER_DESC_RSP        CommandId = 0x4583
	ZDO_IEEE_ADDR_REQ         CommandId = 0x2501
	ZDO_IEEE_ADDR_REQ_SRSP    CommandId = 0x6501
	ZDO_IEEE_ADDR_RSP         CommandId = 0x4581
	ZDO_STARTUP_FROM_APP      CommandId = 0x2540

	// AF
	AF_REGISTER          CommandId = 0x2400
	AF_REGISTER_SRSP     CommandId = 0x6400
	AF_INCOMING_MSG      CommandId = 0x4481
	AF_DATA_REQUEST      CommandId = 0x2401
	AF_DATA_REQUEST_SRSP CommandId = 0x6401
	AF_DATA_CONFIRM      CommandId = 0x4480

	// UTIL
	UTIL_GET_DEVICE_INFO      CommandId = 0x2700
	UTIL_GET_DEVICE_INFO_SRSP CommandId = 0x6700

	// ZB
	ZB_GET_DEVICE_INFO      CommandId = 0x2606
	ZB_GET_DEVICE_INFO_SRSP CommandId = 0x6606
)

type DeviceInfo

type DeviceInfo struct {
	PowerSource zcl.PowerSource
	Available   uint8 // include in prod configuration
	Test        uint8 //include in test configuration
	// contains filtered or unexported fields
}

type ElectricParams

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

type EndDevice

type EndDevice struct {
	MacAddress   uint64
	ShortAddress uint16
	Di           DeviceInfo

	ChargerOn bool
	// contains filtered or unexported fields
}

func EndDeviceCreate

func EndDeviceCreate(macAddress uint64, shortAddress uint16) *EndDevice

func (*EndDevice) Bytes_to_float64

func (ed *EndDevice) Bytes_to_float64(src []byte) (float64, error)

func (EndDevice) GetCurrentState

func (ed EndDevice) GetCurrentState(channel uint8) string

func (EndDevice) GetDeviceType

func (ed EndDevice) GetDeviceType() uint8

func (EndDevice) GetHumanName

func (ed EndDevice) GetHumanName() string

func (*EndDevice) GetMainsVoltage

func (ed *EndDevice) GetMainsVoltage() float64

func (EndDevice) GetMotionState

func (ed EndDevice) GetMotionState() int8

func (EndDevice) GetPowerSource

func (ed EndDevice) GetPowerSource() uint8

func (*EndDevice) GetPromDoorString

func (ed *EndDevice) GetPromDoorString() string

/ @brief Возвращает строку для Prometheus / @return

func (EndDevice) GetPromMotionString

func (ed EndDevice) GetPromMotionString() string

func (*EndDevice) GetPromPressure

func (ed *EndDevice) GetPromPressure() string

func (EndDevice) GetPromRelayString

func (ed EndDevice) GetPromRelayString() string

/ @brief Возвращает строку для Prometheus / Чтобы линия реле не сливалась с линией датчика, / искуственно отступаю на 0,1 / @return

func (*EndDevice) Get_battery_level

func (ed *EndDevice) Get_battery_level() uint8

func (*EndDevice) Get_battery_voltage

func (ed *EndDevice) Get_battery_voltage() float64

func (*EndDevice) Get_current

func (ed *EndDevice) Get_current() float64

func (*EndDevice) Get_energy

func (ed *EndDevice) Get_energy() float64

func (*EndDevice) Get_humidity

func (ed *EndDevice) Get_humidity() int8

func (*EndDevice) Get_last_action

func (ed *EndDevice) Get_last_action() time.Time

func (*EndDevice) Get_last_seen

func (ed *EndDevice) Get_last_seen() time.Time

func (*EndDevice) Get_linkquality

func (ed *EndDevice) Get_linkquality() uint8

func (*EndDevice) Get_luminocity

func (ed *EndDevice) Get_luminocity() int8

func (EndDevice) Get_mac_address

func (ed EndDevice) Get_mac_address() uint64

func (*EndDevice) Get_power

func (ed *EndDevice) Get_power() float64

func (*EndDevice) Get_pressure

func (ed *EndDevice) Get_pressure() float64

func (*EndDevice) Get_temperature

func (ed *EndDevice) Get_temperature() int8

func (*EndDevice) SetBatteryParams

func (ed *EndDevice) SetBatteryParams(value1 uint8, value2 float64)

charge level, battery voltage

func (*EndDevice) SetCurrent

func (ed *EndDevice) SetCurrent(value float64)

func (*EndDevice) SetCurrentState

func (ed *EndDevice) SetCurrentState(state string, channel uint8)

func (*EndDevice) SetLastAction

func (ed *EndDevice) SetLastAction(tm time.Time)

func (*EndDevice) SetMainsVoltage

func (ed *EndDevice) SetMainsVoltage(value float64)

func (*EndDevice) SetMotionState

func (ed *EndDevice) SetMotionState(state uint8)

func (*EndDevice) SetPowerSource

func (ed *EndDevice) SetPowerSource(value uint8)

func (*EndDevice) Set_energy

func (ed *EndDevice) Set_energy(value float64)

func (*EndDevice) Set_humidity

func (ed *EndDevice) Set_humidity(value int8)

func (*EndDevice) Set_last_seen

func (ed *EndDevice) Set_last_seen(tm time.Time)

func (*EndDevice) Set_linkquality

func (ed *EndDevice) Set_linkquality(quality uint8)

func (*EndDevice) Set_luminocity

func (ed *EndDevice) Set_luminocity(value int8)

func (*EndDevice) Set_manufacturer

func (ed *EndDevice) Set_manufacturer(value string)

func (*EndDevice) Set_model_identifier

func (ed *EndDevice) Set_model_identifier(value string)

func (*EndDevice) Set_power

func (ed *EndDevice) Set_power(value float64)

func (*EndDevice) Set_pressure

func (ed *EndDevice) Set_pressure(value float64)

func (*EndDevice) Set_product_code

func (ed *EndDevice) Set_product_code(value string)

func (*EndDevice) Set_temperature

func (ed *EndDevice) Set_temperature(value int8)

type Event

type Event struct {
	Id   CommandId
	Emit chan Command
}

type EventHandler

type EventHandler struct {
	Events map[CommandId]Event
}

func Create_event_handler

func Create_event_handler() *EventHandler

func (*EventHandler) AddEvent

func (eh *EventHandler) AddEvent(id CommandId)

func (*EventHandler) GetEvent

func (eh *EventHandler) GetEvent(id CommandId) *Event

type Message

type Message struct {
	Source      zcl.Endpoint
	Destination zcl.Endpoint
	Cluster     zcl.Cluster
	ZclFrame    zcl.Frame
	LinkQuality uint8
}

type RF_Channels

type RF_Channels struct {
	Channels []uint8
}
var DefaultRFChannels RF_Channels = RF_Channels{[]uint8{11}}
var TestRFChannels RF_Channels = RF_Channels{[]uint8{15}}

func (RF_Channels) Compare

func (current RF_Channels) Compare(new RF_Channels) bool

type Simple_descriptor

type Simple_descriptor struct {
	// contains filtered or unexported fields
}
var Default_endpoint Simple_descriptor = Simple_descriptor{1,
	0x0104,
	0x05,
	0,
	[]uint16{},

	[]uint16{}} // Output clusters list.

type Zdo

type Zdo struct {
	Flag     bool
	Uart     *serial3.Uart
	Cmdinput chan []byte

	ShortAddress uint16
	// contains filtered or unexported fields
}

func ZdoCreate

func ZdoCreate(port string, os string, chn chan Command, jchn chan []byte) (*Zdo, error)

func (*Zdo) ActiveEndpoints

func (zdo *Zdo) ActiveEndpoints(address uint16) error

get endpoint list from device

func (*Zdo) Bind

func (zdo *Zdo) Bind(shortAddress uint16, macAddress uint64, endpoint uint8, cluster zcl.Cluster) error

bind device with zhub

func (*Zdo) FinishConfiguration

func (zdo *Zdo) FinishConfiguration() error

func (*Zdo) Generate_transaction_number

func (zdo *Zdo) Generate_transaction_number() uint8

in payload

func (*Zdo) Generate_transaction_sequence_number

func (zdo *Zdo) Generate_transaction_sequence_number() uint8

in zcl.Frame

func (*Zdo) InputCommand

func (zdo *Zdo) InputCommand()

receive command from UART and call command handler

func (*Zdo) ParseZclData

func (zdo *Zdo) ParseZclData(data []byte) zcl.Frame

func (*Zdo) PermitJoin

func (zdo *Zdo) PermitJoin(duration time.Duration) error

Enable pairing mode for duration seconds

func (*Zdo) ReadRfChannels

func (zdo *Zdo) ReadRfChannels() RF_Channels

read channels list from coordinator

func (*Zdo) RegisterEndpointDescriptor

func (zdo *Zdo) RegisterEndpointDescriptor(endpoint_descriptor Simple_descriptor) error

func (*Zdo) Reset

func (zdo *Zdo) Reset() error

reset zigbee-adapter

func (*Zdo) SendMessage

func (zdo *Zdo) SendMessage(ep zcl.Endpoint, cl zcl.Cluster, frame zcl.Frame) error

send a message to a specific device

func (*Zdo) Simple_descriptor

func (zdo *Zdo) Simple_descriptor(address uint16, endpointNumber uint8) error

get endpoint descriptor from device

func (*Zdo) Startup

func (zdo *Zdo) Startup(delay time.Duration) error

func (*Zdo) Stop

func (zdo *Zdo) Stop()

func (*Zdo) WriteRfChannels

func (zdo *Zdo) WriteRfChannels(new RF_Channels) error

write channels list into coordinator

Directories

Path Synopsis
zhub4 - Система домашней автоматизации на Go Copyright (c) 2023 GSB, Georgii Batanov gbatanov @ yandex.ru
zhub4 - Система домашней автоматизации на Go Copyright (c) 2023 GSB, Georgii Batanov gbatanov @ yandex.ru

Jump to

Keyboard shortcuts

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