Skip to content

API Setup

Code A Software edited this page Jan 27, 2024 · 5 revisions

Config

Requirements

  • MSSQL-Server/Instance (you can specify the connection string) and import the schema from home-db.sql.
  • .NET Core 8.0.x and ASP.NET Core 8.0.x are both required!

config.json

{
  "host": "http://localhost:5250",
  "connection_string": "Server=YOUR_PC\\SQLEXPRESS,1433;User Id=user;password=set_your_password;Database=home;Trusted_Connection=False;MultipleActiveResultSets=true",
  "use_webhook": false,
  "webhook_url": null,
  "health_check_timer_interval": "00:01:00",
  "remove_inactive_gui_clients": "00:10:00",
  "remove_inactive_clients": "00:03:00",
  "acquire_new_screenshot": "12:00:00",
  "remove_old_screenshots": "1.00:00:00",
  "storage_warning_percentage": 10,
  "battery_warning_percentage": 10,
  "web_hook_date_time_format": "dd.MM.yyyy HH:mm",
  "detect_screen_changes_as_a_device_change": false,
  "wake_on_lan_port": 9,
  "broadcast_shutdown_config": {
    "is_active": false,
    "security_code": null,
    "entries": []
  }
}

Broadcast Shutdown

A broadcast shutdown command can be triggered via API/GUI. It is intended for shutting down all/some devices at once. This can be useful if your USV notices a power failure and if you don't have a network shutdown module. But be aware that the clients will recieve these requests only on their next ack (at least 1 minute). So before shutting down your server you should wait at least one minute to ensure all clients have recieved the ack requests with the shutdown command. Shutdown is supported on Windows and Linux. In the default configuration this feature is disabled.
You can only activate it via config.json:

"broadcast_shutdown_config": 
{
    "is_active": true,
    "security_code": "your-code",
    "entries": []
}

Make sure to set up a security code (otherwise it will not work) which is not to complex to remember in an emergency situation. If you are triggering this via API automatically with your USV you can use the following endpoint:
http://API_URL/api/v1/Communication/broadcast_shutdown?code=test&reason=usv
There is also a reason you have to specify why this shutdown was required, because this will be logged.
If you leave entries empty, then all online and compatible devices will be shutdown. But you can also specifiy multiple entries. These entries can contain a device guid, a device name or even a group name. This could be useful if you only have certain devices connected to your usv for example!

Setup

  1. Locate your dotnet installation (.NET Core 8.0.x and ASP.NET Core 8.0.x are both required!)
  2. Create a service file at /etc/systemd/system/homeapi.service:
[Unit]
Description=HomeAPI Service

[Service]
WorkingDirectory=/media/server/Server/andy/home
ExecStart=/usr/bin/dotnet /media/server/Server/andy/home/Home.API.dll
Restart=always
# Restart service after 10 seconds if the dotnet service crashes:
RestartSec=10
SyslogIdentifier=homeapi
User=root

[Install]
WantedBy=multi-user.target
  • Make sure your pathes are correctly setuped!
  1. Enable service: sudo systemctl enable homeapi.service
  2. Start service: sudo systemctl start homeapi.service
  • You can also maintain the service with sudo service homeapi status!

Clone this wiki locally