Cloudino Library for Arduino

Javier Solis edited this page Oct 21, 2017 · 2 revisions

The Cloudino Class

As a part of this library it is presented the Class: Cloudino. This class contains several methods that allows Arduino’s users establish a communication bridge between their projects (Arduino boards) and the Cloud Services of Cloudino. It is worth pointing that this Class provides a unique tool that offers the possibility to reprogram and debug code to update specific tasks of our remote devices.

The first step to use this library into your project is to include it as a header into the code and generate a global variable that will be used to invoke the methods of this Class.

#include <Cloudino.h>
Cloudino cdino;

The Begin and Loop method

Arduino is an open source platform focused in microcontroller devices. It allows to automate, in a very easy way, different electronical projects [1]. In terms of software, Arduino is a system that allows to load new code to a board using two basic methods:

  • void setup()
  • void loop()

The setup() method of Arduino is invoked when the device is started or after a reset action is executed. The loop() method will be invoked within a continuous cycle, and it will persist till the device be shut down or after a reset action is executed.

In the setup() method it is established the way that the Arduino board will work. Into this step the Wifi Cloud Connector hardware device of Cloudino (WCC) must be configured as well, in order to establish its initial conditions. Once the WCC is configured it is necessary to invoke the void begin() method of Cloudino Class to properly start the WCC device.

After the initial conditions of the WCC device were set; it is necessary to invoked the loop() method of Cloudino (cdino.loop()) inside the loop() method of Arduino, it is done in this way because it is the manner that we properly incorporate the functions of Cloudino platform into Arduino’s code.

Please see the next lines of code:

void setup()
{
   // TODO: 
   cdino.begin();
}

void loop() //this is the void loop() method of Arduino

{
   cdino.loop(); // this is the void loop() method of Cloudino
   // TODO:
}

The Print method.

Once the Arduino board is programed it can send or receive messages from the Cloud, by this protocol it is possible to interact with physical objects and get information about the variables that they are measuring and set a possible response. Cloudino has a console of messages where they can be seen, like a ‘hello world’ message, which traditionally indicates that everything is running properly. So, using this tool it is possible to make debugging from the Cloud side without being connected to a wire like typically is done using the Arduino configuration.

In order to send a message to the console of Cloudino it is necessary to use the print() method of Cloudino (cdino.print()). If we go to the portal of Cloudino and look for the specific WCC device in which we are working on, in its console section, we will be able to see the messages that an Arduino device is sending by using the print() method. Remember that, if we use the cdino.print() method the WCC device will always be sending information to the server, but it is important to be in the correct place in the web platform to see it.

Please see the next line of code:

cdino.print("Hola Mundo!");

The “on” and “post” method

Into its setup section, Cloudino permits to set some Cloud services in order to interact with a given device. In the portal, Cloudino.io, it is necessary to register any device in order to obtain a “token”, which is an access code to have a right entry to a specific device. In addition this password also generates a link between a registered user with a WCC device. Under this approach, the WCC is able to show actualized states that are being captured by the sensors that are connected to its ports, in the same manner, it can respond to messages that are sent from the Cloud.

To receive messages from the server, it is necessary to add the method “on” of Cloudino class inside the setup() method of Arduino. This call requires to know which topic is going to be subscribed and which method should be invoked when the message is received. This method will receive a string with the message sent from the portal to the device. In the same manner to send a message from the device to the portal, the post() method of Cloudino receives a topic and the message to be sent.

Please see the next lines of code:

#include  <Cloudino.h>

Cloudino cdino;

void led(String msg)
{
  if(msg=="on")digitalWrite(13, HIGH);
  else digitalWrite(13, LOW);
  cdino.post("led",msg);
}

void setup()
{
  pinMode(13, OUTPUT);
  cdino.on("led",led);
  cdino.begin();
}

void loop()
{
  cdino.loop();
}

The “Timers”

Another interesting function is the timer() method of Cloudino, there are three modalities that we can use:

  1. The temporized interval
  2. The “n” times interval
  3. The “n” times interval followed by a second method

In order to call these three functions it is just necessary to invoke them: setInterval, setTimeout and setTimer. All of this functions receive a positive 'long type value' to define, in milliseconds, the time interval, also they receive the name of the method to be executed. In a particular case, the setTimer function also receives a positive ‘integer type value’ to define the number of times the interval is going to be repeated. Optionally a second method can be invoked to be executed at the end of the repetitions.

Please see the next lines of code:

#include <Cloudino.h>

Cloudino cdino;

const int ledPin =  13;      // the number of the LED pin
int ledState = LOW;          // ledState used to set the LED

void blink()
{
    // if the LED is off turn it on and vice-versa:
    if (ledState == LOW)
      ledState = HIGH;
    else
      ledState = LOW;
    // set the LED with the ledState of the variable:
    digitalWrite(ledPin, ledState);  
}

void setBlink1()
{
  cdino.setTimer(200,blink,4,setBlink2);
}

void setBlink2()
{
  cdino.setTimer(50,blink,4,setBlink1);
}

void setup() {
  pinMode(ledPin, OUTPUT);  
  setBlink1();
  cdino.begin();
}

Cloudino or specifically the Wifi Cloud Connector is a device that allows user to link its projects to cloud services, its particularity is that it has a set of preprogrammed IoT protocols that allow an easy connection to internet. Cloudino is an open source project that can be built by users, its WCC just need an ESP8266 chip and the firmware of Cloudino to be used, this firmware can be found here.

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.