Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: first draft of conciseness

This page will guide you through the steps necessary to obtain and operate your own pico engine.

Learning Objectives

After completing this Quickstart lesson, you will be able to:

  • understand important concepts about programming in KRL including ruleset structure
  • know how to install and operate the node pico engineknow how to use the "My Picos" page to
  • manage picos with the pico engine developer UI.
  • understand basic KRL ruleset structure
  • register a ruleset know how to with a pico engine
  • install a ruleset to in a picobecome familiar with using the "My Picos" page to work with your picos

Contents

Table of Contents
maxLevel2

Concepts

Getting started with KRL can be a big leap because there are so many things that are different about programming in KRL:

...

To complete the Quickstart, you will need

  1. An code editor
  2. Git on your machine
  3. A pico engine

Install and run the pico-engine

Prerequisite: you will need to install node (also known as Node.js) on your machine. Be sure that you are installing at least version 6. The installation includes npm, the node package manager, which you will use to install the pico engine. (Node.js is a trademark of Joyent, Inc. and is used with its permission. Picolabs is not endorsed by or affiliated with Joyent.)

...

  1. git (optional)
  2. node.js version 6 or greater with npm

Install and run the pico-engine

Use npm to install and start the node pico engine.

Code Block
$ npm install -g pico-engine
$ pico-engine
http://localhost:8080

The node pico engine will spend some time initializing internal data structures before it starts its web server. After doing this, it will start a web server on port the developer UI at http://localhost:8080.

Note that the web server displays the URL of its document root, ex. "http://localhost:8080" and then continues to run. As we will see later, messages will be   Messages are logged to this console, so it is best do not to close this the command line window. 

The Primary, or Owner, Pico

During the The pico engine initialization, it creates starts with a primary pico , naming it named "Owner Pico" and then registers four rulesets and installs two of them in the owner pico. These are .  The Owner Pico is setup with the minimum required rulesets for running the pico and the developer UI. You can visit the developer UI , "My Picos", at the address on which the pico engine is listeningat http://localhost:8080 and see the Owner Pico.

Your The owner pico is represented by a rounded rectangle, which is placed on a canvas, allowing you to change its size and placement. Keep this tab open for use in registering and installing your ruleset, below.

...

Hello World KRL

...

Overall Structure of a KRL Ruleset

...

Ruleset

The hello world ruleset is an example of basic KRL ruleset structure.

Code Block
titlehellow_world.krl

...

code
linenumberstrue
ruleset hello_world {
  meta {
    name "Hello World"
    description <<
A first ruleset for the Quickstart
>>
    author "Phil Windley"
    logging on
    shares hello
  }
 
  global {
    hello = function(obj) {
      msg = "Hello " + obj;
      msg
    }
  }
 
  rule hello_world {
    select when echo hello
    send_directive("say", {"something": "Hello World"})
  }
 
}

...

Lines 19-22: A ruleset usually contains one or more rules. In this case there is one rule named hello_world which will be watching for events with domain echo and type hello.

Registering and Installing Your Ruleset

A recommended workflow for writing KRL is found in KRL Programming Workflow. Please read and set up a workflow using your favorite editor and GitThis example uses github as a host

Registering When you Register a ruleset means to make it available to , the pico engine , which parses and compiles the KRL source code into JavaScript and caches this as a node moduleand makes the uniqe ruleset ID avalible to install inside picos.

Installing a ruleset to a pico is properly a user function, but as a developer, you are functioning in both user and developer capacitiesinside a pico enables the pico engine to evaluate each rule on that pico when corisponding events are raised to that pico.

View your Owner Pico by visiting the "My Picos" page (linked from the "Pico Bootstrap" page), as shown above.

...

If you're using something like GitHub to host your rulesets, be sure that you supply the "raw" URL. The raw URL returns the file without any page chrome.  For example, this is a raw and cooked example of the same ruleset.  If you're hosting your rulesets on Amazon S3, be sure the URL is public and can be retrieved using a browser. 

...