- Creating a build
- Deploy
- User Access Token Generation
- Configuration
- Serving
- MQTT
- Development
- Upgrade kii-gateway-agent
- Gateway Replacement
webpack
The build artifacts will be stored in the dist/
directory.
In the dist/
directory,
├── main.js # main js file
├── package.json # specifics of npm's package.json handling
└── resource
├── db.json # configuration
└── stateCache.json # cache data
All we need are in the dist
folder.
Copy these files with their structure into the gateway.
Also We need to install some additional packages manually in the gateway.
npm install express
npm install jju
npm install [email protected]
or we can just use
npm install # will install the depedencies set in the package.json
All of them can NOT be bundled into the dist.
curl -X POST -H "Content-Type: application/json" -d '{
"grant_type": "password",
"username": {username},
"password": {password}
}' "https://api-sg.kii.com/api/apps/{appID}/oauth2/token"
Before serving the service, we have to configure resource/db.json
first.
{
"app": {
"appID": "appID",
"appKey": "appKey",
"site": "https://api-sg.kii.com"
},
"user": {
"ownerToken": "ownerToken",
"userID": "userID"
},
...
}
The app
and user
sections need to be set.
After deploy and configuration, we can run it.
node main.js
In some old node, we may need to force garbage collection manually.
Just add the option: --expose-gc
node --expose-gc main.js
Now the agent supports MQTT.
node main.js --mqtt
Also gc mode is
node --expose-gc main.js --mqtt
# Install the dependencies
npm install
# upgrade kii-gateway-agent
npm install kii-gateway-agent@latest
In order to replace a gateway while keeping the data and identity of its current endnode devices, the following steps need to be executed:
- Unpair relationship of existing gateway and endnode
curl -X DELETE -H "Authorization: Bearer {accessToken}" "https://api-sg.kii.com/thing-if/apps/{appID}/things/{gatewayThingID}/end-nodes/{endnodeThingID}"
- Connect the endnode devices to a new gateway
- Follow the instruction of this page on the new gateway. If you copy the code files from the old gateway, please not forget to clean the
db.json
file so that gateway and endnode information is deleted.