cablelabs / lpwanserver

LPWAN Provisioning & Management Server
https://lpwanserver.com
Apache License 2.0
39 stars 11 forks source link

TTN and Loriot NetworkProtocol Updates #347

Open rhythnic opened 4 years ago

rhythnic commented 4 years ago

Update TTN and Loriot handlers to the new API for NetworkProtocols. Remove the ttn dependency. This would allow us to use node-alpine and have a much smaller Docker image. Also, the ttn package is deprecated. If supporting TTN v2 isn't viable without ttn, consider supporting only v3. /app/networkProtocols/handlers. See /app/networkProtocols/handlers/ChirpStack/ChirpStack.js as a reference implementation. The actual handler is in the folder named by the version, but the parent class holds most of the logic. Versions will go away once #325 is implemented, and the parent class, e.g. /app/networkProtocols/ChirpStack/ChirpStack.js, will be the sole handler for a network.

TTN and Loriot don't support device profiles. As such, a strategy needs to be put in place to derive device profiles from pulled devices, and to push/merge device profile settings to devices on TTN or Loriot. See #356. Disregard device profiles until that issue is implemented. Focus on applications and devices and mapping networkSettings property names. The device properties intended for Device Profiles will be omitted for now.

The API for a NetworkProtocol might change a little, but it will look like the one below.

class NetworkProtocol extends EventEmitter {
  // *******************************************************************
  // Utility Methods
  // *******************************************************************
  submitUplink (args) {
    return new Promise((resolve, reject) => {
      let id = uuidv4()
      this.once(`uplink:fail:${id}`, reject)
      this.once(`uplink:ok:${id}`, resolve)
      this.emit('uplink', { id, args })
    })
  }
  // *******************************************************************
  // Session Methods
  // *******************************************************************
  async connect () {}
  async disconnect () {}
  async test () {}
  // *******************************************************************
  // Application Methods
  // *******************************************************************
  async listAllApplications () {}
  async createApplication () {}
  async updateApplication () {}
  async removeApplication () {}
  async startApplication () {}
  async stopApplication () {}
  async buildApplication () {}
  // *******************************************************************
  // Device Profile Methods
  // *******************************************************************
  async listAllDeviceProfiles () {}
  async createDeviceProfile () {}
  async updateDeviceProfile () {}
  async removeDeviceProfile () {}
  async buildDeviceProfile () {}
  // *******************************************************************
  // Device Methods
  // *******************************************************************
  async listAllApplicationDevices () {}
  async createDevice () {}
  async updateDevice () {}
  async removeDevice () {}
  async buildDevice () {}
  async handleUplink (args) {
    return this.submitUplink(args)
  }
  async passDataToDevice () {}
}