Getting Started

This section gives a short introduction on how to develop a device and make it ready to use.

Device

Devices are the nodes which communicate with your equipment and can be registered to the application. They all must implement the same skeleton in order to work with our application. However, you are completely free which equipment you want to control with MUSCLE, since you must implement the functionality and hardware communication. There must only be an interface via which the device can communicate with the equipment.

To get an idea how to the source tree of a device implementation looks like, have a look in the demo branch of the device template repository on GitLab.

Source

The source code for the devices can be found as a skeleton on GitLab on which there are two important branches:

  • master

    Which contains an empty skeleton

  • demo

    Which contains a demo implementation to test a the functionality

Clone the repository with:

git clone https://gitlab.ti.bfh.ch/muscle/device-skeleton.git

Or by using ssh:

git clone git@gitlab.ti.bfh.ch:muscle/device-skeleton.git

Then change the origin to one of your git repositories

git remote set-url origin <URL_TO_YOUR_GIT_REPO>

Development

While developing a device, there is no need to for a production ready server. The device skeleton does already provide the necessary setup to run a Flask development server.

To be able to run the server you must have Flask and the necessary dependencies installed, follow this section or simply run

sudo chmod +x install.sh
sudo ./install.sh

when in the source directory of the device.

You can activate the virtual environment and start the Flask server with

source venv/bin/activate && flask run

This command will start the development server on port 8080 and makes it publicly available in your current network.

Once the server is started, you can register it via the Frontend and start developing.

Alternatively you can use the browsable API from Flask JSON-RPC to quickly debug. Note that this only works when in debug mode and when all types are correctly specified, for example.

def monitor(option :str) -> str

To use the API, navigate to http://<DEVICE_IP>:8080/api/device/browse/#/ in your browser.

Read Implementing Devices for instructions on how to implement a device.

Production

When the development is finished it is recommended to use a real server application to serve your device instance.

Furthermore if you enable the service with the webserver, the device instance will start on each boot. This will replace the need for the command flask run, which should be used for development only.

Read Server Setup for a guide on how to install and setup a server for production.

Warning

Devices do not require a user to be authenticated to controll it by default. In order to make them secure, make sure to configure the AUTHENTICATION_BACKEND as described in the Configuration section.