Description

There is related API available to invoke on Milesight gateway, user can follow below steps to test related API by Postman.

Milesight Gateways provides HTTP API for LoRaWAN configurations. This article will describe how to invoke these APIs via Postman software.


Requirement

  • Milesight Gateway: UG56, UG65, UG67
  • Postman Software (or any other API tool)
  • Web Browser: take Chrome as example


Configuration

API Authentication

It is necessary to require a token to call HTTP API of gateway. Note that this token is only valid in 24 hours and need to require again after 24 hours. The authentication type is Bearer Token.

Method 1: get token via browser

Step 1Open the web GUI of gateway via browser, click the three dots at the top right, click More tools > Developer tools.

 

 

Step 2: type the username and password to log in the gateway and watch the log of Network section.

 

Step 3: find the login file and copy the token content.

Note: the authentication type is Bearer Token not JWT.

 

 

Method 2: get token via API

Step 1Open Postman software to type this API and replace the {gatewayIP} as real gateway IP address: 

https://{gatewayIP}:8080/api/internal/login

Step 2. Set the method as POST, type the body for authentication. Click Send to get the token.

Note: the authentication type is Bearer Token not JWT.

 

 

The body contents are different based on the firmware versions:

(1) For 60.0.0.42-r5/56.0.0.4 and later:

{
    "username": "admin",
    "password": "sI/7ewBCeWunDs6JXXtSHg=="
}

Note: the password is AES encrypted value. AES encryption settings:

Parameter

Option

Encryption cipher mode

CBC

Encryption Key Size

128 bits

IV (initial Vector)

2222222222222222

Secret key

1111111111111111

Output format

Base64

Example: https://anycript.com/crypto

 

 

 

(2) For 60.0.0.42-r4/56.0.0.3-r1 and before:

{
    "username": "apiuser",
    "password": "password"
}


API Test

Step 1. Download API command json file at the end of this article.

Step 2. Open Postman, Click File > Import > Import File to upload and import the API command file.

Step 3. After importing it, we can see Collection interface generate a API file.


Step 4. Click eye icon at the top-right corner to create an environment to save all parameter values.

Click Add to create a new environment, name this environment and add variables as required.

In this example, there are three variables:

bearerToken: paste the token from previous steps

baseUrl: IP address of gateway. If the port is not 8080, it is necessary to add the port.

organizationID: 1


Step 5. Choose the environment created, select the API from left list, click Send to get response directly. For some commands which needs to fill in the query params or body, please refer to API document.



Examples:

1) Get the list of devices



2) Send downlink command to a device

Type the device EUI to send downlink:

Configure the downlink content as below:

  • confirmed: false or true. When choosing true, end-device will reply ACK message packet to server after it receives this downlink command. Else, it won’t do any reply about it.
  • data: The downlink command to control corresponding device, get it from related device user guide or manufacturer.
  • fPort: The port which LoRaWAN devices receive downlinks, it can be checked from related sensor user guide or manufacturer. For Milesight end devices, the port is 85 by default.

Here, we modify the body content like below to change report interval of WS525 to 1 min:

{
    "confirmed": true,
    "data": "/wM8AA==",
    "fPort": 85
}

Then click Send, if we accessing to gateway web GUI, go to Network Server > Packets this time, we will see gateway received downlink packet, and then get a ACK reply from sensor soon.

Note: User can get related downlink command from sensor manufacturer, remember to converse downlink command to Base64 format data content first. You can converse downlink data format form below website: https://conv.darkbyte.ru/