Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Widget Connector
overlayyoutube
_templatecom/atlassian/confluence/extra/widgetconnector/templates/youtube.vm
width400px
urlhttps://www.youtube.com/watch?v=a4VUn_XGZD8&feature=youtu.be
height300px

Pico as an

...

internet citizen

A pico (quoting from Rebuilding KRL):

...

Picos respond to events and queries using two different URL schemesformats. Events are sent to a pico using the Sky Event API. Queries are made using the Sky Cloud API

...

Breaking this URL into components:

  • "http://" identifies HTTP as the protocol

  • "localhost:3000" is the domain name and port of the pico engine which hosts the pico

  • "sky/event" identifies this as an event for the pico

  • "ckcvuri6r0017conl4siq0q3r" is one of the pico's event channel identifiers (ECI) (yours will be different)

  • "1556" is an arbitrary string which serves as an event identifier (EID) and correlation ID. (useful when looking at logs)

  • "echo" identifies the domain of the event

  • "hello" identifies the type of the event

queries

Here is a sample URL that sends a query to a pico:

...

This URL shares some components with the URL above for an event. The new components are:

  • "sky/cloud" identifies this as a query for the pico

  • "ckcvuri6r0017conl4siq0q3r" is one of the pico's event channel identifier or ECIidentifiers (ECI) (yours will be different)

  • "hello_world" is the ruleset identifier or RID

  • "hello" is the name of a shared function from that ruleset

  • "obj" is the name of an argument that the function expects

  • "Bob" is the value for that argument

Create a Channel

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

...

Since a pico is a first-class Internet internet citizen, there are many ways in which you can send it an event. We will look at two of these three ways:

...

You can enter the event URL in postman, and click the Send button. Note the result below:

...

Using logs

Look at the console from which you started your pico engine.

You should see entries like these:

Code Block
{"level":50,"time":"2020-07-21T12:42:00.593Z","picoId":"ckc...",...,"event":{"eci":"ckc...","domain":"echo","name":"hello","data":...
{"level":50,"time":"2020-07-21T12:42:00.595Z","picoId":"ckc...","txnId":"ckc...","msg":"txnStart"}
{"level":50,"time":"2020-07-21T12:42:00.595Z","picoId":"ckc...",..."msg":"fired"}
{"level":50,"time":"2020-07-21T12:42:00.596Z","picoId":"ckc...","txnId":"ckc...","msg":"txnDone"}

This console log may be useful in debugging events.

Send a query through your channel

...

Send a query through your channel

Create a URL for your Pico which uses your "hello_world" channel identifier. It will look something like

...

Congratulations! You know how to send queries to a pico, either directly using a URL, or through the "Testing" tab of the UI.

...

Using logs

KRL provides an operator, klog(), which allows us to print information into the logs. 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. Finally, it returns the value of the expression on which it operates, unchanged. This makes it easy to add to or remove from your KRL code without changing its meaning.

...

Here we see the logging for a query and an event.

Note that since the UI works by sending events and queries to the io.pioclabs.pico-engine-ui ruleset, you’ll also see those events and queries in the output. If anyone is interested in contributing to the React code that implements the UI to filter the logs, it is open source.

Congratulations!

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

...