server

package
v0.4.4 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2017 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// SystemInfo holds NHC startevents
	SystemInfo = "{\"cmd\":\"systeminfo\"}"
	// RegisterCMD holds NHC startevents
	RegisterCMD = "{\"cmd\":\"startevents\"}"
	// ListActions holds NHC listactions
	ListActions = "{\"cmd\":\"listactions\"}"
	// ListLocations holds NHC listlocations
	ListLocations = "{\"cmd\":\"listlocations\"}"
	// ListEnergies holds NHC listenergy
	ListEnergies = "{\"cmd\":\"listenergy\"}"
	// ListThermostats holds NHC listthermostat
	ListThermostats = "{\"cmd\":\"listthermostat\"}"
)
View Source
const HealthMsg = `{"alive":true}`

HealthMsg static alive json for health endpoint

Variables

This section is empty.

Functions

func ConnectNhc added in v0.3.0

func ConnectNhc(cfg *config.NhcConf) (conn *net.TCPConn, err error)

ConnectNhc establish connection to Niko Home Control IP module

func CreateJeedomCMD added in v0.4.0

func CreateJeedomCMD(cmd interface{}) (i string, err error)

CreateJeedomCMD creates a cmd to a Jeedom script equipment

func CreateJeedomEquipment added in v0.4.0

func CreateJeedomEquipment(locID, name string) (i string, err error)

CreateJeedomEquipment saves a new script equipment to jeedom

func CreateJeedomObject added in v0.4.0

func CreateJeedomObject(name string) error

CreateJeedomObject saves the object to jeedom (location)

func Discover added in v0.3.0

func Discover() net.IP

Discover discover NHC controller by sending UDP pkg on port 10000 return NHC IP address and boolean

func ExecJeedomRPCRequest added in v0.4.0

func ExecJeedomRPCRequest(args *types.JsonRpcArgs) (res []byte, err error)

ExecJeedomRPCRequest send JSON RPC request to Jeedom, returns raw result

func GetJeedomCMDs added in v0.3.0

func GetJeedomCMDs(id string) []types.JeedomCMD

GetJeedomCMDs returns the list of cmds of a given equipment

func GetJeedomEquipments added in v0.3.0

func GetJeedomEquipments() []types.JeedomEquipment

GetJeedomEquipments list all Jeedom script equipments

func GetJeedomObjects added in v0.3.0

func GetJeedomObjects() []types.JeedomLocation

GetJeedomObjects gets all objects from Jeedom

func GetNhcInfo added in v0.3.0

func GetNhcInfo(w http.ResponseWriter, r *http.Request)

GetNhcInfo handler for /api/v1/nhc/

func GetNhcItem added in v0.3.0

func GetNhcItem(w http.ResponseWriter, r *http.Request)

GetNhcItem handler for /api/v1/nhc/{id}

func GetNhcItems added in v0.3.0

func GetNhcItems(w http.ResponseWriter, r *http.Request)

GetNhcItems handler for /api/v1/nhc/

func GetOutboundIP added in v0.3.0

func GetOutboundIP() net.IP

GetOutboundIP returns the IP address used for out access

func Health

func Health(w http.ResponseWriter, r *http.Request)

Health endpoint for health monitoring

func JeedomCmd added in v0.3.0

func JeedomCmd(w http.ResponseWriter, r *http.Request)

JeedomCmd handler for POST on /jeedom/{id}/{value}

func JeedomInit added in v0.3.0

func JeedomInit()

JeedomInit Initialize jeedom internal "db"

func NhcCmd added in v0.3.0

func NhcCmd(w http.ResponseWriter, r *http.Request)

NhcCmd endpoints for sending NHC commands

func NhcInit added in v0.3.0

func NhcInit(cfg *config.NhcConf)

NhcInit sends list commands to NHC in order to get all equipments

func NhcListener added in v0.3.0

func NhcListener()

NhcListener start a connection to nhc host, register itself to receive and route all messages from nhc broadcast

func Route added in v0.3.0

func Route(msg *types.Message)

Route parse and route incoming message the right handler

func SendCommand added in v0.3.0

func SendCommand(cmd string) error

SendCommand send passed command to nhc

func ServeWebSocket added in v0.3.0

func ServeWebSocket(w http.ResponseWriter, r *http.Request)

ServeWebSocket called by the http endpoint. Calls serveWS function and adds the WSPool to original connection

func Start added in v0.3.0

func Start(conf string)

Start Initialize and start the server

func UpdateJeedomState added in v0.3.0

func UpdateJeedomState(item types.NHCItem) error

UpdateJeedomState updates the device's status in Jeedom

Types

type ClientPool added in v0.3.0

type ClientPool struct {

	// Broadcast Inbound messages from the clients.
	Broadcast chan []byte

	// Unregister requests from clients.
	Unregister chan *WSClient
	// contains filtered or unexported fields
}

ClientPool maintains the set of active clients and broadcasts messages to the clients. Use the Broadcast channel to push msg to all clients

var (

	// WSPool instance to hold ClientPool
	WSPool *ClientPool
)

func (*ClientPool) Run added in v0.3.0

func (cp *ClientPool) Run()

Run activates the ClientPool so that we can manage client connections

type Server

type Server struct {
	Router     *mux.Router
	ListenPort string
	LogLevel   string
	LogFile    string
}

Server holds the gomotics app definition

func (*Server) Initialize

func (s *Server) Initialize()

Initialize initialize the server also calls the internal in mem db

func (*Server) Run

func (s *Server) Run()

Run starts the server process

type SimpleCmd added in v0.3.0

type SimpleCmd struct {
	Cmd   string `json:"cmd"`
	ID    int    `json:"id"`
	Value int    `json:"value1"`
}

SimpleCmd type holding a nhc command

func (SimpleCmd) Stringify added in v0.3.0

func (sc SimpleCmd) Stringify() string

Stringify return the string version of SimpleCmd

type WSClient added in v0.3.0

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

WSClient handles the ws client conn. use send channel as input for pushing msg to client

Jump to

Keyboard shortcuts

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