Remote Script Launch API
-
Description
POST /spawn HTTP/1.1
spawn_args: {"script launch args": ...}
[script body] -
Possible Responses
{"code":1,"message":"Operation failed"}
{"code":2,"message":"Syntax error in script","detail":"specific error details"}
{"code":3,"message":"A script is already running"}
{"code":233,"message":"What happened?"}
-
Notes
spawn_args
is a printable string without line breaks[script body]
can be plain text or encrypted binary data- The script can read launch args via
proc_get("spawn_args")
orproc_take("spawn_args")
- The script will not be saved to the device as a file; it only runs in memory
- Exception: when "script daemon mode" is enabled, device may cache script data bound to the device
-
Example
Example HTTP request to the device:
POST /spawn HTTP/1.1
spawn_args: {"server_ip":"192.168.31.13","port":55555}
Content-Length: 123
local args = proc_get("spawn_args")
args = json.decode(args)
sys.alert("Server IP: "..args.server_ip.."\nPort: "..args.port)The device will show an alert:
Server IP: 192.168.31.13
Port: 55555Python 3.x example:
# -*- coding: utf-8 -*-
import http.client
import json
spawn_args = {
"server_ip": "192.168.31.13",
"port": 55555,
}
data = r'''
local args = proc_get("spawn_args")
args = json.decode(args)
sys.alert("Server IP: "..args.server_ip.."\nPort: "..args.port)
'''
headers = {
"Content-type": "text/lua",
"spawn_args": json.dumps(spawn_args),
}
conn = http.client.HTTPConnection("192.168.31.72:46952")
conn.request("POST", "/spawn", data.encode('utf-8'), headers)
response = conn.getresponse()
print(response.status, response.reason)
data = response.read()
print(data.decode('utf-8'))
conn.close()