Run script on request

Hello,

I have a TRB245 with a wake-on LAN script on it. Is it possible to run this script by sending an MQTT message or an HTTP request? (MQTT is desired).

Thanks in advance

Hello and welcome to the Teltonika community!

On Teltonika devices, the MQTT protocol is used to read modem parameters. It can’t be used with parameters other than those mentioned here: Monitoring via MQTT - Teltonika Networks Wiki

The Wake on LAN feature is built into the RutOS, if it’s not visible under Services > Wake on LAN please check if the package is installed under System > Package Manager. You can install the package directly from our server or manually by uploading a file from TRB245 Package Downloads - Teltonika Networks Wiki. As for running the script with an HTTP request, it is not possible, but you can instead trigger the built-in Wake device feature. Please keep in mind you need to authenticate before making the request. You could use for example the POST method http://192.168.1.1/api/wol/actions/wake_device with body contents below:

{
    "data": {
        "name": "string",
        "mac": "11:22:33:44:55:66"
    }
}

For more information about Wake on LAN feature and API calls please visit: TRB245 Wake on LAN - Teltonika Networks Wiki and Teltonika Networks Web API

You can also use JSON-RPC to run any Linux command on the device, including running the script. For example, to run script “example” that is placed in /scripts/ directory you can use:

{
    "jsonrpc": "2.0", "id": 1, "method": "call", "params": 
    [
        "YourSessionID", "file", "exec",
        {
            "command":"sh",
            "params":
            [
                "/scripts/example"
            ]
        }
    ]
}

To obtain your JSON-RPC session ID, please take a look at our wiki which explains JSON-RPC in detail Monitoring via JSON-RPC windows RutOS - Teltonika Networks Wiki.

Please ensure that the scripts are included in /etc/sysupgrade.conf configuration file so they are not lost after the firmware upgrade.

Please let me know if you have any more questions.

Best regards,
Kacper