Skip to main content

Example: waste management

This is an example of how you can build an entire waste management app based leveraging Connhex Resources.

Connhex Resources: truck as a resource.

Resources

This example shows a base resource (truck) and its related resources (gateway, weighing scale). You can either specify attributes (e.g. truck has a license plate) or relationships (e.g. truck has one weighing scale).

Relationships

  • truck

    • has one on-board gateway
    • has one weighing scale
  • gateway

  • scale

    • has one serial number
    • has one model
    • has one manufacturer
    • has one maximum weight

Attributes

Here are the attributes of the truck resource:

  • licensePlate
    • is a string
  • serialNumber
    • is a string

JSON Schemas

Let's see an example of modeling the truck resource using JSON-Schema.

{
"schema": {
"$id": "https://connhex.com/example/truck.schema.json",
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"licensePlate": {
"type": "string",
"title": "License plate"
},
"serial": {
"type": "string",
"title": "Serial number"
},
"gateway": {
"type": "string",
"title": "gateway",
"connhex": {
"id": "gateway"
}
},
"scale": {
"type": "string",
"title": "scale",
"connhex": {
"id": "scale"
}
}
}
}
}

With respect to the pool example, we can see that gateway and scale are single references: each truck is associated to exactly one gateway and one scale.

The scale resource would be represented by:

{
"schema": {
"$id": "https://connhex.com/example/scale.schema.json",
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"serial": {
"type": "string",
"title": "Serial number"
},
"manufacturer": {
"type": "string",
"title": "Manufacturer name"
},
"model": {
"type": "string",
"title": "Model"
},
"maxWeight": {
"type": "number",
"title": "Maximum weight"
}
}
}
}
Manufacturer

Once again, you can go as deep as you want with the relationships between resources. For example, you could add a manufacturer resource to the scale resource. The manufacturer resource could have a name and a contact (email, phone, etc.).

Historicization

Fun fact

This whole historicization concept came out from a real use case: a waste management application.

Let's see a practical use case of the historicization feature. Suppose you need to track over time how much waste is collected from a given truck. Partial weights are collected by the weighing scale and sent to the gateway. The gateway then sends the data to the cloud.

Then a truck get its gateway replaced: the new weighings need to be associated to the same truck. By simply updating the resource association, this is performed out of the box.

Guess what happens next? The old gateway is mounted on another truck. The old weighings would now be associated to the new truck: simply changing the association prevents this problem.

Without using Connhex Resources

Of course, you could implement this logic yourself. But you would need to:

  • potentially migrate all the recordings
  • keep track of the old and new resources
  • adjust the queries to fetch data

The alternative is letting Connhex Resources do the heavy lifting for you: you'll just need to define resources.