# Setup and configuration

# What does the app need

I need some parameters to be set by the user for this app to work. First the user have to select the door that will start the timer, secondly the light to be controlled needs to be selected. The third parameter will be the time in seconds for the light to be on.

# Setup a test environment

It is possible to run the app as a standalone program using the programs accompanied in the edged package. With some extra parameter I can specify the executable file to run, and the config file to load for that application. I can trigger functions to be called to verify that all logic in the callbacks works as intended.

I create the config file with the parameters I wanted to use, it should look like the result from the API:response from GET /api/v2/edge/app/configured/{installation_id}/{instance_id}.

I saved the config as config.json with this content:

{
  "id": 455,
  "app_id": 32,
  "installation_id": 23,
  "version": "1.0.0",
  "config": {
    "trigger_function": "2",
    "control": "12",
    "timeout": "5"
  },
  "name": "My test run",
  "created": 1600676011,
  "updated": 1600676011
}

To run apps there is a wrapper program included in the edge-daemon. This program can be run with the command edge-app. I used the following parameters to test my app:

edge-app -l app.lua -a config.json -r 1

This will run in the terminal. While the program is running the following RPC calls can be done to test the logic.

Write + enter description
destoyApp() Call onDestroy
createApp() Call onCreate
updateFunctions() Read the downloaded FunctionX data and call the onFunctionsUpdated callback

CTRL-C will cancel the execution and call onExit callback.