Remote Management Guide for Smart Radio – Appendix B – Using the JSON-RPC API

Remote Management Guide for Smart Radio – Appendix B – Using the JSON-RPC API

Appendix B – Using the JSON-RPC API

 

For detailed descriptions on how to use the JSON-RPC API, please refer to the following links:

https://openwrt.org/docs/techref/ubus

https://github.com/openwrt/luci/wiki/JsonRpcHowTo

The listings below, along with additional scripts and packages can be found here:

https://doodlelabs.sharepoint.com/:f:/s/Technical/Elhb0AcP3ClCltsuPOu9gqEBY0v34XZYp1GDrMCTaRS8oA?e=IgmAJd

In order to access the radio, you first need to set the permissions for your user profile (to be created next). Create a new profile /usr/share/rpcd/acl.d/superuser.json like the one below.

{
        "superuser": {
                "description": "Super user access role",
                "read": {
                        "ubus": {
                                "*": [ "*" ]
                        },
                        "uci": [ "*" ],
                        "file": {
                                "*": ["*"]
                        }
                },
                "write": {
                        "ubus": {
                                "*": [ "*" ]
                        },
                        "uci": [ "*" ],
                        "file": {
                                "*": ["*"]
                        },
                        "cgi-io": ["*"]
                }
        }
}

Next, create a user profile in /etc/config/rpcd, and then restart the process with /etc/init.d/rpcd restart. An example profile is shown below.

config login
        option username 'root'
        option password '$p$root'
        list read 'superuser'
        list write 'superuser'

The API is now ready to be used. You should adjust the user profile and permissions to your liking. The permissions above could pose a security risk. In order to use API, you need to get a session ID and use it for subsequent requests. For ubus, for example, you can try the following call,

curl -k https://<IP-ADDRESS>/ubus -d '
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "call",
  "params": [ "00000000000000000000000000000000", "session", "login", { "username": "root", "password": "secret"  } ]
}'

the -k option is required because the Smart Radio doesn’t use a third party certificate authority. An example of using JSON-RPC API for file access is shown below. Substitute <TOKEN> with the value returned above.

curl -k https://<IP-ADDRESS>/ubus -d '
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "call",
  "params": [ “<TOKEN>”, "file", "read", { "path": "/etc/board.json" } ]

}'

    • Related Articles

    • Introduction to Remote Management Guide for Smart Radio

      Remote Management Guide for Smart Radio Advanced Mesh Router for Private Wireless Networks Introduction The Smart Radio runs the Mesh Rider OS. It is a customized version of Openwrt with enhancements useful for applications requiring low-latency ...
    • Remote Management Guide for Smart Radio –Appendix C – Using SNMP

      Appendix C – Using SNMP Before you can use SNMP, you need to open up the firewall at port 161 for UDP traffic. In the GUI, navigate to Network Configuration → Firewall. Under the section Open ports on router, add a new rule like that shown in the ...
    • Remote Management Guide for Smart Radio - Appendix A – Using SSH

      Appendix A – Using SSH   The followings are some examples of remotely executing a command via SSH to obtain network information from the node. ssh root@10.223.134.70 ‘iw wlan0 info’ Lists the current configuration of wlan0 ssh root@10.223.134.70 ‘iw ...
    • Remote Management Guide for Smart Radio –Appendix D – Common CLI Commands

      Appendix D – Common CLI Commands This section provides commands commonly used in the Smart Radio for configuration and diagnostics. UCI The UCI system is used for configuration. Most UCI files are found at /etc/config/. This is a slow method of ...
    • 1. Introduction to the Smart Radio Configuration Guide

      Introduction The purpose of this guide is to aid in the software configuration of the Smart Radio. This guide is organized as follows. 1.      Smart Radio Settings (For all models) 2.      Model Specific Configuration 3.      System Configuration ...