yolink

package module
v0.0.0-...-9a34feb Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2022 License: MIT Imports: 13 Imported by: 0

README

Setup

  • Get credentials from YoLink mobile app:

    • Settings, Account, Advanced Settings, User Access Credentials
  • Store the credentials in environment variables:

      export YOLINK_UAID="UAID"
      export YOLINK_SECRET_KEY="Secret Key"
    
  • Build and run the yl-request app to test the API.

Commands / Sample Apps

yl-request
  • Utility to query device list and device state.

  • Example commands:

      yl-request list-devices
      yl-request get-state DEVICE_ID
    
yl-msgdump
  • Logs MQTT messages to stdout.
yl-pgwriter
  • Logs MQTT messages to PostgreSQL.

  • See cmd/yl-pgwriter/postgres_setup.sql for DB setup script.

  • Configure DB connection in an environment variable:

      export YOLINK_DB_URL="postgres://yolink:abcd@localhost:5432/yolink"
    
  • Example query:

      select time,
             dev_id,
             (payload->'data'->'temperature')::float as t,
             (payload->'data'->'humidity')::float as h
      from mqtt_messages
      order by time;
    

Documentation

Index

Constants

View Source
const (
	// API
	API_HOST   = "api.yosmart.com"
	API_PATH   = "/open/yolink/v2/api"
	TOKEN_PATH = "/open/yolink/token"
	MQTT_PORT  = 8003

	// Misc
	SUCCESS_CODE = "000000"
	ERROR_STATE  = "error"
)

Variables

View Source
var ErrInvalidFormat = errors.New("invalid format")

Functions

This section is empty.

Types

type APIClient

type APIClient struct {
	// User Access Credentials from YoLink app:
	UAID      string
	SecretKey string

	// Set by getToken:
	AccessToken  string
	RefreshToken string

	// Set by getHomeId
	HomeId             string
	MqttMessageHandler MessageHandler
	// contains filtered or unexported fields
}

func NewAPIClient

func NewAPIClient(uaid, secretKey string) (*APIClient, error)

func (*APIClient) GetDevices

func (c *APIClient) GetDevices() ([]Device, error)

func (*APIClient) GetHomeId

func (c *APIClient) GetHomeId() (string, error)

func (*APIClient) GetState

func (c *APIClient) GetState(d Device) (JsonResponse, error)

func (*APIClient) MQTTConnect

func (client *APIClient) MQTTConnect() error

type Device

type Device struct {
	DeviceID string
	Token    string
	Name     string
	Type     string
}

type JsonRequest

type JsonRequest map[string]any

type JsonResponse

type JsonResponse map[string]any

type MessageHandler

type MessageHandler func(topic string, body []byte)

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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