Table of Contents | ||
---|---|---|
|
...
A pico channel is represented by an ECI (Event Channel Identifier). It is a unique token, a string, such as "ckiz680qq000a7u2r8myeezof"
. To use a channel, a programmer only needs the ECI itself and the location of the engine the pico is located. Then, following the Sky Event API or Sky Cloud API queries and events can be sent. Mechanisms within KRL have this built in, such as the event library and Wrangler's skyQuery.
...
Notice that checking the box beside a channel's ECI shows the policies of the channel.
The ECI "
ckj080ny8008ffi2r1n1b2kr0"
can be given to trustworthy actors, giving them the ability to use the full capabilities of the lamp_ruleset to control the lamp.
On the other hand the ECI "
ckj081v5a0093fi2r9es49i77"
could be more widely published so that less-trusted actors can check the lamp's state. Such actors would not be able to send any events to the Lamp pico.
If any actor misbehaves, you can simply delete the channel and recreate it, with a different ECI. Even though the read-only ECI gives access only to a single query, an actor might misbehave by mounted a distributed denial of service attack on the pico-engine. Again, you can eliminate the attack simply by deleting that channel. After recreating it, you can give the new ECI to good actors, and they can resume their legitimate work.
Programmatic creation of a channel
...
Channels can be created asynchronously by raising the wrangler:new_channel_request
event. Wrangler enforces that all channels with the same type must have a unique name. On a successful channel creation, a wrangler:channel_created event will be raised by Wrangler.
Creation Example
Channels can be created asynchronously by raising thewrangler:new_channel_request
event. Wrangler enforces that all channels with the same type must have a unique name. On a successful channel creation, a wrangler:channel_created event will be raised by Wrangler.
Code Block | ||
---|---|---|
| ||
raise wrangler event "new_channel_request" attributes { "tags":["lamp","read-only"], "eventPolicy":{"allow": [], "deny": [{"domain": "*", "name": "*"}]}, "queryPolicy":{"allow":[{"rid": meta:rid, "name": "IsLampOn"}], "deny": []}, "co_id":meta:rid // Added attributes get passed through } |
...
Code Block | ||
---|---|---|
| ||
rule onNewTestChannel { select when wrangler channel_created where event:attr("co_id") == meta:rid pre { newChannel = event:attr("channel").klog("New channel") channelID = newChannel{"id"} } } /* [KLOG] New channel { "id": "ckj081v5a0093fi2r9es49i77", "tags": [ "lamp", "read-only" ], "eventPolicy": { "allow": [], "deny": [ { "domain": "*", "name": "*" } ] }, "queryPolicy": { "allow": [ { "rid": "lamp_ruleset", "name": "IsLampOn" } ], "deny": [] }, "familyChannelPicoID": null } */ |
Deleting a Channel
Deleting a channel occurs in much the same way that creating one does. The client raises a wrangler:channel_deletion_request
event with attributes that are either the tags, or the ECI of the channel they wish to delete. If invalid attributes are provided a wrangler:channel_deletion_failed
event will be raised by Wrangler.
Deletion Example
Code Block | ||
---|---|---|
| ||
raise wrangler event "channel_deletion_request" attributes { "tags":["lamp","read-only"], "co_id":meta:rid } |
...
A pico channel has certain attributes that each serve a unique purpose in identifying and using that channel. A map containing these attributes is often given to the client by Wrangler, such as when creating and deleting channels.
ID
The channel ID is the globally unique identifier for a channel. It is also known by the initialism "ECI" (Event Channel Identifier). Anyone who knows the ECI and has network access to the engine that the pico with the channel lives on can send events and queries to the channel.
Tags
The channel has one or more tags as a way to identify the channel without knowing its ECI. This allows easier manipulation of the channels that the KRL programmer cares about.
...
- event library
- Allows sending an event to a specific channel on any host, including the local engine.
- If another host is specified will use HTTP.
- HTTP
- Sky Event API
- Sky Cloud API
- skyQuery (which uses the Sky Cloud API)
- The pico engine UI testing tab (which uses Sky Cloud and Sky Event)
- Raising an event in the postlude
- Occurs on the
meta:eci
channel (the same channel used to reach the rule containing the postlude)
- Occurs on the
Channels API
...
A list of the functions, actions, received events (that Wrangler responds to) and raised events (that Wrangler raises) and in-depth descriptions of when to use them can be found in the Wrangler page.