Skip to content

ashramwen/kii-mt7688-agent

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

70 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

kii-mt7688-agent

Creating a build

webpack

The build artifacts will be stored in the dist/ directory.

Deploy

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 ws@1.1.2

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.

User Access Token Generation

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"

Configuration

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.

Serving

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

MQTT

Now the agent supports MQTT.

node main.js --mqtt

Also gc mode is

node --expose-gc main.js --mqtt

Development

# Install the dependencies
npm install

Force to upgrade kii-gateway-agent manually

# upgrade kii-gateway-agent
npm install kii-gateway-agent@latest

Gateway Replacement

In order to replace a gateway while keeping the data and identity of its current endnode devices, the following steps need to be executed:

  1. 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}"
  1. Connect the endnode devices to a new gateway
  2. 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.