Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: mostly typo fixes

...

After completing this lesson, you will be able to:

  • explain how a Pico pico is a first-class Internet citizen
  • explain channels and use the "My Picos" page to manage them
  • send events and queries to a Pico pico using a browser, the event console, and the "Testing" tab
  • use logs
  • use the klog() operator

...

Pico as an Internet citizen

A Pico pico (quoting from Rebuilding KRL):

  • is capable of receiving events and queries on Internet channels,
  • interacts with other picos, even if they're hosted on another instance of the evaluator somewhere else on the Internet, and
  • can call and be called from Internet-hosted APIs.

The Pico pico has multiple URL's that can be used to query its state and send it events. HTTP is used as its the transport protocol.

events

Here is a sample URL that sends an event to a Pico pico like the one you created in the node pico-engine quickstart:

...

  • "http://" identifies HTTP as the protocol
  • "localhost:8084" is the domain name and port of the pico-engine which hosts the Picopico
  • "sky/event" identifies this as an event for the Picopico
  • "citdel5gz00012aaoo5ucc613" is the pico's event channel identifier (ECI)
  • "5" is an arbitrary string which serves as the an event identifier (EID)
  • "echo" identifies the domain of the event
  • "hello" identifies the type of the event

...

  • "sky/cloud" identifies this as a query for the Picopico
  • "hello_world" is the ruleset name
  • "hello" is the name of a shared function from that ruleset
  • "obj" is the name of the argument that the function expects
  • "Bob" is the value for that argument

...

As you can see in the URL for events and queries, channels are the way in which a Pico pico can be identified by the pico-engine.

...

Sending events through the channel

Since a Pico pico is a first-class Internet citizen, there are many ways in which you can send it an event.

...

While developing a ruleset, you can use the "My Picos" page which can provide a simple UI for your event. To do so, you must modify the ruleset to define and share the name "__testing" and  and bind it to a structure which represents the events and queries you wish to test.

...

Notice that we have added a new name "__testing" (double underscore) to the "global" section block of the ruleset.

This name must also be shared, so we add it to the "shares" entry in the "meta" section block of the ruleset. The "shares" keyword is followed by a comma-separated list of names defined in the globals section which we wish to use outside of the ruleset. Those names not mentioned in "shares" are for the private use of the the ruleset and are not exposed to other rulesetsoutside the ruleset.

The value bound to "__testing" is  is a structure that describes those portions of our ruleset that we wish to expose in the "Testing" tab. You do not need to expose every aspect of your ruleset, but only those that you wish to appear in the "Testing" tab.

...

Congratulations! You know how to send queries to a Picopico, either directly using a URL, or through the UI.

More about logs

KRL provides an operator, klog(), which allows us to print information into the log file. It is an operator, rather than a statement, so it is applied to an expression. It prints into the log the message passed to it as an argument, followed by the value of the expression on which it operates.

...

Code Block
  rule hello_world {
    select when echo hello
    pre {
      name = event:attr("name").klog("our passed in Namename: ")
    }
    send_directive("say") with
      something = "Hello " + name
  }

...

Let's also modify the structure bound to "__testing", as follows:

Code Block
    __testing = { "queries": [ { "name": "hello", "args": [ "obj" ] },
                               { "name": "__testing" } ],
                  "events": [ { "domain": "echo", "type": "hello",
                                "attrs": [ "name" ] } ]
                }

...

Code Block
[KLOG] our passed in Namename:  Bob

Congratulations!

You now know how to send events to, and make queries of, a Picopico. You have also learned some debugging techniques.

Next, learn about persistence, the "P" of Picopico, by working through Lesson 2. Pico state.

...