WebThing Event

Hello,

  1. Do I understand it correctly that I want to use Event instead of Property because it gets logged? (Eg. Thing is turned on and back off and I can miss that. With Event the information will be preserved.)

  2. I would like to have a WebThing with a capability of https://iot.mozilla.org/schemas/#TemperatureSensor but with Event (if I correctly understand it as described above in 1)) as Overheated. I tried to add example code from the Light (I even changed the whole Thing to be Light) but it did not work - I did not see any Events the Gateway UI. Should it work (add Event to TemperatureSensor)?

  3. Generaly it is unclear to me how much I need to conform to https://iot.mozilla.org/schemas/ to have my Things working with Gateway? Do I need to fit to existing definitions (eg. my “thermostat” does not work by temperature but by time schedule - I understand it kind of is not THERMOstat, but it is the closest predefined WebThing, but required TargetTemperature which does not make sense) or can I define my own combination of Capabilities/Actions/Events?

  4. As I am mostly creating my Webthings I wonder if there is some best practice what type of logic should be in the Thing itself and what should be in the Gateway (eg. Should the Thing generate Overheated Event or should I make rule in the Gateway that watches the Temperature if it rises above safe level)?

Thanks for your help or suggestions,

Tomas

1 Like
  1. Do I understand it correctly that I want to use Event instead of Property because it gets logged? (Eg. Thing is turned on and back off and I can miss that. With Event the information will be preserved.)

No, that’s not the intent of events. Events are asynchronous occurrences that are not necessarily property-related. What you want to do is enable the Logs experiment in Settings, and then add a new log for your property on the Logs screen.

  1. I would like to have a WebThing with a capability of https://iot.mozilla.org/schemas/#TemperatureSensor but with Event (if I correctly understand it as described above in 1)) as Overheated. I tried to add example code from the Light (I even changed the whole Thing to be Light) but it did not work - I did not see any Events the Gateway UI. Should it work (add Event to TemperatureSensor)?

To see events, you’ll open up the properties view for your thing, click the three-dot icon in the bottom right, then click “Event Log”.

  1. Generaly it is unclear to me how much I need to conform to https://iot.mozilla.org/schemas/ to have my Things working with Gateway? Do I need to fit to existing definitions (eg. my “thermostat” does not work by temperature but by time schedule - I understand it kind of is not THERMOstat, but it is the closest predefined WebThing, but required TargetTemperature which does not make sense) or can I define my own combination of Capabilities/Actions/Events?

Your web thing doesn’t have to use any schemas at all. A UI will be generated for you based on property types and such. However, using schemas will help the UI to generate specialized property and thing UIs, such as the nice thermostat icon.

  1. As I am mostly creating my Webthings I wonder if there is some best practice what type of logic should be in the Thing itself and what should be in the Gateway (eg. Should the Thing generate Overheated Event or should I make rule in the Gateway that watches the Temperature if it rises above safe level)?

It entirely depends on context. For this specific example, I’d say your overheated event makes sense to put at the web thing level, since it’s specific to the hardware. At the gateway level, you might want to set an alert at a lower number to let you know when your kids have been messing with the thermostat, for example.

It does not seem very practial to me to scroll peridically thru log to see if the property value was not out of range. Or am I missing something?

Yes, this is what I tried. But the thing in the gateway was not loading the exported event. Can I debug this somehow?

That’s great. Is there some overview how are Capabilities and Properties rendered in Gateway UI?

Yes, I was looking for some guidance. So far I came with rule if it is “critical” it should be part of the thing so the things are self-sufficient/independent and can provide full functionality even without the gateway (altough with less comfort).

Thanks!

What you want to do is enable the Logs experiment in Settings, and then add a new log for your property on the Logs screen.

It does not seem very practial to me to scroll peridically thru log to see if the property value was not out of range. Or am I missing something?

Is there really any difference between doing that and periodically checking the event log?

To see events, you’ll open up the properties view for your thing, click the three-dot icon in the bottom right, then click “Event Log”.

Yes, this is what I tried. But the thing in the gateway was not loading the exported event. Can I debug this somehow?

What are you building your web thing with (i.e. what library)? Can you post the thing description that is generated by your web thing?

Your web thing doesn’t have to use any schemas at all. A UI will be generated for you based on property types and such. However, using schemas will help the UI to generate specialized property and thing UIs, such as the nice thermostat icon.

That’s great. Is there some overview how are Capabilities and Properties rendered in Gateway UI?

If you install the Virtual Things add-on, you can play with all of the currently supported schemas.

It entirely depends on context.

Yes, I was looking for some guidance. So far I came with rule if it is “critical” it should be part of the thing so the things are self-sufficient/independent and can provide full functionality even without the gateway (altough with less comfort).

Yes, pretty much. Your web things should be able to stand alone, with no need for a gateway, such that (in theory) any client could communicate with your web thing and get any necessary information directly from it.

I would say yes. And I thought that Gateway UI might even somehow signalize new event on the thing (change of color or dot like Android notifications) but I never saw it working.

Custom code - I am prototyping it with RaspberryPi + PHP.

http://rpi.lan/iot/kot.php

{
  "@context": "https://iot.mozilla.org/schemas/",
  "@type": ["TemperatureSensor"],
  "id": "http://rpi.lan/iot/kot.php",
  "title":"Kotel",
  "properties": {
    "KOT1": {
      "@type": "TemperatureProperty",
      "type": "number",
      "unit": "degree celsius",
      "title": "KomĂ­n",
      "readOnly": true,
      "links": [{"href": "/iot/kot_prop.php?id=KOT1"}]
    }
  },
  "events": {
    "overheated": {
      "@type": "OverheatedEvent",
      "type": "number",
      "unit": "degree celsius",
      "title": "Přetopeno",
      "links": [{"href": "/iot/kot_evnt.php?id=OVERHEATED"}]
    }
  },
  "links": [
    {
      "rel": "properties",
      "href": "/iot/kot_prop.php"
    }
  ]
}

http://rpi.lan/iot/kot_evnt.php?id=OVERHEATED

[
  {
    "overheated": {
      "data": 102,
      "timestamp": "2019-12-26T18:28:35+00:00"
    }
  },
  {
    "overheated": {
      "data": 101,
      "timestamp": "2017-01-24T13:02:45+00:00"
    }
  }
]

Everything else works fine. But no Events in the Event Log.

Perfect thanks!

When a new event occurs, and you have the properties UI open, a little toast pop-up will be displayed at the bottom of the screen with event info.

I’m guessing the issue is that you’re missing an events link in the top-level links array, something like:

  "links": [
    {
      "rel": "properties",
      "href": "/iot/kot_prop.php"
    },
    {
      "rel": "events",
      "href": "/iot/kot_evnt.php"
    }
  ]

Yes, this was the issue now it works ok, thanks!

That is strange how it works as the top-level link is not necessary for Properties.

That’s just an artifact of how the gateway interacts with web things, and of previous versions of the spec.

Anyway, glad it’s working now!