Ciao MQTT Bluemix

This example uses Ciao MQTT connector. The sketch sends via MQTT brightness and temperature information that will be shown graphically on the blueMix IBM system. Upload your sketch and then connect to the webpage: https://quickstart.internetofthings.ibmcloud.com/#/device/BlueMixTest902345/sensor/

Hardware Required

Circuit

There is no circuit for this example.

Yun Fritzing

image developed using Fritzing. For more circuit examples, see the Fritzing project page

Code


/*

  Arduino Ciao example

 This sketch uses Ciao mqtt connector. Sketch sends via MQTT brightness and temperature information that will be shown graphically in the blueMix IBM system.

 Upload your sketch an than connect to the webpage:

 https://quickstart.internetofthings.ibmcloud.com/#/device/BlueMixTest902345/sensor/

  NOTE: be sure to activate and configure mqtt connector on Linino OS.

       http://www.arduino.org/learning/reference/ciao-library

 created September 2015

 by andrea[at]arduino[dot]org

 */

#include <Ciao.h>

int ctrl=0;
void setup()
{

  Ciao.begin();  //Start the serial connection with the computer

                       //to view the result open the serial monitor

  pinMode(9,OUTPUT);
}

void loop()                     // run over and over again
{

   //getting the voltage reading from the temperature sensor

   int readingTemp = analogRead(A0);

   // converting readingTemp to voltage

   float voltage = readingTemp * 4.56;

   voltage /= 1024;

   // now print out the temperature

   float temperatureC = (voltage - 0.5) * 100 ;

   int readingLum = analogRead(A2);

   analogWrite(9,map(readingLum,0,1023,0,255));

   if (ctrl>=10){

     Ciao.write("mqtt","iot-2/evt/status/fmt/json","{\"d\": {\"temperature\":"+String(temperatureC)+",\"luminosity\":"+String(readingLum)+"}}");

     ctrl=0;

   }

   ctrl++;

   delay(100);

}

See Also

  • FileOverwrite? : Open a file in write mode, overwriting it

  • FileRead? : Open a file, reads its contents and shows it via serial

  • RestClient? : How to implement Rest Client

  • ThingSpeak? : Interaction between the Ciao Library and the Thingspeak Cloud

  • ThingSpeakTalkBackRecv? : Interaction between the Ciao Library and the Thingspeak Cloud

  • ThingSpeakTalkBackSend? : Interaction between the Ciao Library and the Thingspeak Cloud

  • RestServer? : Allows access to the analog and digital pin of the board via rest calls

  • BoardModel? : Get board model, using awk command

  • CPUUsage? : Get the CPU usage every one minute, by reading /proc/stat system file

  • Date? : Get the system current date