Skip to content

Services

inhies edited this page Dec 15, 2016 · 2 revisions

Introduction

Services are plugins designed to extend the functionality of Casa. Almost everything Casa does is run as a service to enable flexibility for the user.

Interface

A Casa service need only implement the following three functions:

Start(config *viper.Viper) error
UseLogger(logger Logger)
Stop() error
  • Start(config *viper.Viper) error: This is the main part of the service, where it is configured and then started. config is an in-memory representation of the section of configuration file for the service. For example the Services.Logger portion of the config file is passed to the logger service when Start() is called. An error is returned if there is any problem starting the service.

  • UseLogger(logger Logger): This specifies the logger to be used for debugging output. It allows the use of a single logger throughout the entire program.

  • Stop() error: This stops the service and returns an error if there were any issues in doing so.

Details

Services are responsible for creating their own MQTT client and connecting to the MessageBus. By default, services can connect to tcp://127.0.0.1:1883 with no SSL or other authentication. If the user were to specify one or more username/password combinations for outside devices to connect to the MessageBus, then a random username/password combination will be generated and passed to the service when Start() is called. They will be available in config as MQTT.User and MQTT.Pass.

Clone this wiki locally