163 Star 1.1K Fork 276

GVP赵建辉 / rtty

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
COMMAND.md 1.71 KB
一键复制 编辑 原始数据 按行查看 历史
赵建辉 提交于 2021-01-25 23:13 . Fix doc

Instructions

API Path

/cmd/:devid?wait=10

The wait parameter is optional and defaults to 30s, or 0 if you do not care about the execution of the command

Request message format

{
    "username": "test",
    "password": "test",
    "cmd": "echo",
    "params": ["hello rtty"]
}

The username, cmd in the message must be provided. The password, params are optional. The params is a JSON array.

If the command is executed finish, the server will return the command execution result in json format.

{
    "code": 0,
    "stdout": "aGVsbG8gcnR0eQo=",
    "stderr": ""
}

The stdout and stderr in the response are base64 encoded.

If any of the steps fail, the server will return an error message in json format.

{
    "err": 1002,
    "msg": "device offline"
}

All error codes are as follows

1001    invalid format
1002    device offline
1003    timeout
1       operation not permitted
2       not found
3       no mem
4       sys error
5       stdout+stderr is too big

Example

Shell

Jquery

var data = {username: 'test', password: 'test', cmd: 'echo', params: ['hello rtty']};
$.post('http://your-server:5913/cmd/test', JSON.stringify(data), function(r) {
    if (r.stdout) {
        console.log(window.atob(r.stdout))
    } else {
        console.log(r)
    }
});

Axios

var data = {username: 'test', password: 'test', cmd: 'echo', params: ['hello rtty']};
axios.post('http://your-server:5913/cmd/test', data).then(function(r) {
    var resp = r.data;
    if (resp.stdout) {
        console.log(window.atob(resp.stdout))
    } else {
        console.log(resp)
    }
});
C
1
https://gitee.com/zhaojh329/rtty.git
git@gitee.com:zhaojh329/rtty.git
zhaojh329
rtty
rtty
master

搜索帮助