Arduino Function: Ciao SHELL Connector

Description

Arduino Ciao is a easy-to-use and powerful technology that enables Arduino sketches to communicate intuitively with the "outside World".
It aims to simplify interaction between Microcontroller and Linino OS.

It’s compatible with all version of LininoOS but you will need to install it manually.
See here for installation instructions.

Ciao provides already some "internal" Connectors like MQTT, Shell, File, Rest, Rest Server and other available on github.com/arduino-org repository.

The "internal" Connectors can be used setting up few parameters on LininoOS side and few lines on a Arduino sketch.

In particular here it is shown the Shell Connector
This Connector allows to execute Shell commands for Linux side from an Arduino sketch.
Below the steps that you should follow to use the Shell Connector:

  1. setup Shell Connector;
  2. enable the Connector;
  3. write a simple sketch;
  4. upload the sketch and enjoy.

Setup connector

Before using Ciao Shell Connector you have to configure it properly, this can be done by editing its configuration file.

You can find Shell Connector configuration file at the following path: /usr/lib/python2.7/ciao/connectors/shell/shell.json.conf

{
 "name":"shell",
 "description":"Shell connector for the Ciao Core",
 "authors":["Arduino Team <swdev@arduino.org>;"],
 "repository":"https://github.com/arduino-org/Ciao",
 "version":"0.0.1",
 "params": {
                  "working_directory":"/root",
                  "read_max_size":1024
                  },
 "log":{
          "level":"debug"
          }
}


The parameters at the beginning are for internal use, do NOT edit them (name, description, version, ciao) unless you know exactly what you are doing.

The configurable part is the one identified by "params" key:

  • “working_directory”: specifies the current working directory from where the command is executed.
  • “read_max_size”: specifies the max byte value that Connector can read.

Enable connector

Each Ciao Connector must have a configuration file for the Ciao Core, this simple file is mandatory to enable the connector.

To enable Shell Connector please edit the file at the following path: /usr/lib/python2.7/ciao/conf/shell.ciao.json.conf

{
 "name":"shell",
 "enabled":true,
 "type":"managed",
 [...]
}


The key enabled must be set to true (boolean value).
This is the only parameter you are required to edit in order to enable the Shell Connector. Once done Ciao Core will be ready and configured to use Shell Connector.

Let's write a simple Arduino sketch to use it.

Write a simple sketch


The example below shows how to use Shell Connector to get system date and time from Linino OS, using the command date.

#include <Ciao.h>

void setup() {
                   //init Ciao
                   Ciao.begin();
                   Serial.begin(9600);
                    }
void loop() {
                  //Run commands in Linino OS to get date
                  CiaoData data = Ciao.write("shell","date");
                  if(!data.isEmpty()){
                                              //Get data back
                                              String usage = data.get(2);
                                              Serial.println(usage);
                                              }
                  delay(10000);
                  }

For more information or examples about Ciao Connectors visit: https://github.com/arduino-org/Ciao/tree/master/ciao/connectors

Written by Arduino.org