NeuroQ: IoT Box Quick Guide

This topic explains how to connect your PC to the LAN port on the NeuroQ IoT box. It also contains a sequence diagram, a process definition and some sample code.

Connect to IoT Box via LAN Port

  1. Connect your PC to LAN port on IoT box using an ethernet cable.

  2. Plug the power supply to the IoT box to power it on.
  3. Open http://192.168.101.204 in your browser and enter the username and password. The default is admin/admin.
  4. Click Advanced > Agent Config to configure the Anylink Cloud address in MQTT Publish and MQTT Subscription section and click Save button at the bottom once finished.
​ 5. Click Advanced > Network Config to configure your network connection to Anylink Cloud.
  1. Select Ethernet if you use WAN port on IoT box to connect to Anylink Cloud, or select WiFi if you use WiFi to connect to IoT Cloud. If network connection is correct, the upper right corner Cloud Connection status will be displayed as Connected.
​ 7. Login to Anylink Cloud to make sure your NeuroQ IoT box is registered in the Cloud. You can find serial number of the NeuroQ box on the back side of the box.

Configure IoT box to Communicate with Instrument


Once you connect your NeuroQ IoT box to the Anylink Cloud, you can deploy configuration file from Anylink Cloud to NeuroQ box via the REST API (Please refer to this REST API for details).

2.1 Sequence diagram



2.2 Process description

  1. Use the API /remoteAgent/sendAnylinkXML (please refer to this REST API for details) to send the xml configuration file to Anylink.
  2. After anylink receives the xml configuration file, it needs to restart to load the new configuration.
  3. After anylink restarts, it will reregister to the IoT cloud.
  4. Call the interface /agent/register (please refer to Cloud REST API for details) for details) to query the registration result of anylink. If anylink is reregistered successfully, it means the xml file be sent successfully and the whole process will end.

2.3 Sample code (JAVA)

private final String BASE_URL = "http://staging.anylink.io:8600";
​
@Test
public void sendModuleConfigTest()
{
    String url = BASE_URL + "/remoteAgent/sendAnylinkXML";
    JSONObject param = new JSONObject();
    param.put("token", "0293bd56-af76-449c-8f5d-1dcfe4772dc0");
    param.put("filetype", "config_xml");
    param.put("serialnumber", 1401868);
    param.put("content", "<agent n=\"Agent-1401868\" id=\"1401868\" flag=\"SET-TASKS\" port=\"-1\" timezone=\"UTC\" version=\"3.6.6\">\n" +
            "  <model n=\"ra-model\">\n" +
            "    <device n=\"ra-device\" id=\"1023\" ip=\"127.0.0.1\">\n" +
            "      <driver n=\"T.IDrv.Task:libtremoteplc\" config=\"1\">\n" +
            "        <commDataItems>\n" +
            "          <dataItem freq=\"120000\" id=\"1\" n=\"CSQ\" rw=\"0\" report=\"1\" type=\"a\" vtype=\"\" addr=\"\" config=\"\"/>\n" +
            "        </commDataItems>\n" +
            "      </driver>\n" +
            "    </device>\n" +
            "  </model>\n" +
            "  <task>\n" +
            "    <TaskDriver>\n" +
            "      <driver n=\"T.IDrv.Task:libcontrol\" config=\"10001\"/>\n" +
            "    </TaskDriver>\n" +
            "    <TaskDriver>\n" +
            "      <driver n=\"T.IDrv.Task:libtremoteplc\" config=\"1\"/>\n" +
            "    </TaskDriver>\n" +
            "    <TaskDriver>\n" +
            "      <driver n=\"T.IDrv.Task:libzigbee\" config=\"NULL;115200;8;N;1;0;1;0;0;localhost;10001;6;60;1;10000;3\"/>\n" +
            "    </TaskDriver>\n" +
            "    <TaskDriver>\n" +
            "      <driver n=\"T.IDrv.Task:libkmqtt\" config=\"40.121.212.65;1883;40.121.212.65;1883;60;2;1;0;;;;0;\"/>\n" +
            "    </TaskDriver>\n" +
            "  </task>\n" +
            "  <model n=\"test\" id=\"1\" d=\"IDrv.Custom:libDModbus\" config=\"tcp;192.168.100.38;520;200;100;20\" devicedriver=\"Modbus-TCP\">\n" +
            "    <device n=\"device\" id=\"1\" ip=\"192.168.1.1\" type=\"test\">\n" +
            "      <driver n=\"IDrv.Custom:libDModbus\" config=\"tcp;192.168.100.38;520;200;100;20\" id=\"1\">\n" +
            "        <commDataItems>\n" +
            "          <dataItem id=\"2\" n=\"a\" alias=\"a\" config=\"1;1;100;1;BOOLEAN;0;0;1\" type=\"b\" rw=\"1\" freq=\"60000\" report=\"1\"/>\n" +
            "          <dataItem id=\"3\" n=\"b\" alias=\"b\" config=\"1;1;100;1;BOOLEAN;0;0;1\" type=\"b\" rw=\"1\" freq=\"60000\" report=\"1\"/>\n" +
            "        </commDataItems>\n" +
            "      </driver>\n" +
            "    </device>\n" +
            "  </model>\n" +
            "</agent>");
    String postResult = post(url, param.toJSONString());
    JSONObject postResultJSON = JSONObject.parseObject(postResult);
    if(postResultJSON != null && postResultJSON.getInteger("status") == 100){
        System.out.println("SUCCESS");
    }else{
        System.out.println("FAILED");
    }
}
​
public String post(String urlStr, String messageOut) {
    HttpURLConnection httpConn = null;
    URL url = null;
    String messageIn="";
    try {
        url = new URL(urlStr);
        httpConn = (HttpURLConnection) url.openConnection();
        httpConn.setRequestMethod("POST");
        httpConn.setDoInput(true);
        httpConn.setDoOutput(true);
        httpConn.setRequestProperty("Accept-Charset", "UTF-8");
        httpConn.setRequestProperty("Content-Type", "application/json");
        @Cleanup PrintWriter out = new PrintWriter(httpConn.getOutputStream());
        out.println(messageOut);
        out.flush();
​
        @Cleanup InputStreamReader isReader = new InputStreamReader(httpConn.getInputStream(),"utf-8");
        @Cleanup BufferedReader bin = new BufferedReader(isReader);
​
        StringBuffer buff = new StringBuffer();
        String line;
        while ((line = bin.readLine()) != null) {
            buff.append(line);
        }
        messageIn = buff.toString();
​
    } catch (ConnectException ce) {
        ce.printStackTrace();
    }  catch (Exception e) {
        e.printStackTrace();
    }finally {
        if(httpConn!=null) {
            httpConn.disconnect();
            httpConn = null;
        }
    }
    return messageIn;
}