← Edge App Academy

Edge App Academy · 5 / 5

Add alarms to the plant monitor

Finish the deployment-ready definition and distinguish authoring from installation.

YOUR TASK

Make this happen

3 steps
  1. Add plant/+/alarm as a second subscription routed to receive and connect it to the same broker. Add 30-second keepalive, keep certificate verification enabled, and preserve the health trigger.

  2. Keep the working capabilities from the previous lesson and connect the new pieces to the same solution.

  3. Check the complete solution, then inspect any unmet requirements.

This step starts with the earlier solution and one new challenge. Each lesson keeps its own draft.

Read the starter files

main.cococo

edge_app_document "main" {
  format = "1"
  handle = "plant-monitor"
  name = "Plant monitor"
  handlers = [edge_app_handler.receive, edge_app_handler.health]
  mqttBrokers = [edge_app_mqtt_broker.plant]
  configSchema = {
    type = "object"
    properties = {
      MQTT_URL = {
        type = "string"
      }
      MQTT_USERNAME = {
        type = "string"
      }
      MQTT_PASSWORD = {
        type = "string"
        writeOnly = true
      }
      MQTT_CA = {
        type = "string"
        writeOnly = true
      }
    }
    required = ["MQTT_URL", "MQTT_USERNAME", "MQTT_PASSWORD", "MQTT_CA"]
    additionalProperties = false
  }
  triggers = [{
    kind = "CRON"
    name = "health"
    schedule = "*/5 * * * *"
    handler = "health"
  }]
}

handlers.cococo

edge_app_handler "receive" {
  name = "receive"
  source = file("scripts/receive.lua")
}

scripts/receive.lua

bridge.log.info(params.topic)
return params.payload

broker.cococo

edge_app_mqtt_broker "plant" {
  name = "plant"
  url = "$${config:MQTT_URL}"
  qos = 1
  subscriptions = [edge_app_mqtt_subscription.state]
  username = "$${config:MQTT_USERNAME}"
  password = {
    config = "MQTT_PASSWORD"
  }
  tls = {
    caCertPem = {
      config = "MQTT_CA"
    }
  }
}

subscription.cococo

edge_app_mqtt_subscription "state" {
  topic = "plant/+/state"
  handler = "receive"
}

health.cococo

edge_app_handler "health" {
  name = "health"
  source = "return { alive = true }"
}

alarms.cococo

edge_app_mqtt_subscription "alarms" {
  # TODO: add topic — see the task above.
  # TODO: add handler — see the task above.
}
Supplied supporting files

Reference: edge-apps · getting-startededge-apps · definitionsedge-apps · scripts-triggersedge-apps · mqtt-opcuaedge-apps · industrialedge-apps · exec-httpedge-apps · diagnosticsedge-apps · reference