Skip to content
This repository has been archived by the owner on Feb 21, 2020. It is now read-only.

Commit

Permalink
Updating Ciao library
Browse files Browse the repository at this point in the history
  • Loading branch information
sebba committed Sep 18, 2015
1 parent 6e0a524 commit d055fc6
Show file tree
Hide file tree
Showing 9 changed files with 260 additions and 47 deletions.
12 changes: 7 additions & 5 deletions libraries/Ciao/README.adoc
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
= Bridge Library for Arduino =
= Ciao Library for Arduino =

The Bridge library simplifies communication between the ATmega32U4 and the AR9331.
The Ciao Library allows you to send and receive data outside the microcontroller,
through a serial communication, in a simple and intuitive way.

For more information about this library please visit us at
http://arduino.cc/en/Reference/YunBridgeLibrary
For more information about this library please visit us at:

http://labs.arduino.org/Ciao

== License ==

Copyright (c) Arduino LLC. All right reserved.
Copyright (c) Arduino srl. All right reserved.

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
Expand Down
43 changes: 43 additions & 0 deletions libraries/Ciao/examples/CiaoArduinoXMPP/CiaoArduinoXMPP.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
Arduino Ciao example
This sketch uses ciao xmpp connector. It sends back “hello world” message to the xmpp client when receives “ciao” from it.
Be sure to set the xmpp client in the "USER" field used to receive the response by MCU.
Possible commands to send from the xmpp client:
* "ciao" -> random answers in 5 different languages
created September 2015
by andrea[at]arduino[dot]org
NOTE: be sure to activate and configure xmpp connector on Linino OS
http://labs.arduino.org/Ciao
*/

#include <Ciao.h>

String USER="user@domain";
String mess[5]={"Hi, I am MCU :-P","hallo , ik ben MCU :-P","bonjour, je suis MCU :-P","Ciao, io sono MCU :-P","Kon'nichiwa, watashi wa MCU yo :-P" };

void setup() {
Ciao.begin();
}

void loop() {

CiaoData data = Ciao.read("xmpp");

if(!data.isEmpty()){
String id = data.get(0);
String sender = data.get(1);
String message = data.get(2);

message.toLowerCase();
if(message == "ciao" )
Ciao.write("xmpp", USER,mess[random(0,5)]);
}
}

46 changes: 46 additions & 0 deletions libraries/Ciao/examples/CiaoBluemixMQTT/CiaoBluemixMQTT.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
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://labs.arduino.org/Ciao
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);

}
152 changes: 152 additions & 0 deletions libraries/Ciao/examples/CiaoCommandXMPP/CiaoCommandXMPP.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
/*
This sketch uses the xmpp connector to receive command for the MCU from a xmpp client.
Possible commands to send from the xmpp client:
* "digital/PIN" -> to read a digital PIN
* "digital/PIN/VALUE" -> to write a digital PIN (VALUE: 1/0)
* "analog/PIN/VALUE" -> to write in a PWM PIN(VALUE range: 0 - 255);
* "analog/PIN" -> to read a analog PIN
* "servo/PIN/VALUE" -> to write angle in a SERVO PIN(VALUE range: 0 - 180);
* "mode/PIN/VALUE" -> to set the PIN mode (VALUE: input / output)
* "led on" -> turn on led 13
* "led off" -> turn off led 13
* "ciao" -> random answers in 5 different languages
NOTE: be sure to activate and configure xmpp connector on Linino OS
http://labs.arduino.org/Ciao
created September 2015
by andrea[at]arduino[dot]org
*/

#include <Ciao.h>
#include <Servo.h>

Servo servo;

void setup() {

Ciao.begin();
}

void loop() {

CiaoData data = Ciao.read("xmpp");
if(!data.isEmpty()){
String id = data.get(0);
String sender = data.get(1);
String message = data.get(2);

message.toUpperCase();

if(message == "LED ON"){
digitalWrite(13,HIGH);
Ciao.writeResponse("xmpp",id,"Led D13 ON");
}

else if(message == "LED OFF"){
digitalWrite(13,LOW);
Ciao.writeResponse("xmpp",id,"Led D13 OFF");
}
else{
String command[3];

splitString(message,"/",command,3);
execute(command,id);
}
}
}

void execute(String cmd[], String id) {

if (cmd[0] == "DIGITAL") {
digitalCommand(cmd,id);
}
else if (cmd[0] == "ANALOG") {
analogCommand(cmd,id);
}
else if (cmd[0] == "SERVO") {
servoCommand(cmd,id);
}
else if (cmd[0] == "MODE") {
setMode(cmd,id);
}
else
Ciao.writeResponse("xmpp",id,"sorry, i don't understand :(");
}

void servoCommand(String cmd[], String id){
int pin, value;

pin = (cmd[1]).toInt();

if (cmd[2] != "-1") {
value = (cmd[2]).toInt();
if(value <= 180 && value >=0){
servo.attach(pin);
servo.write(value);
Ciao.writeResponse("xmpp",id,"Servo D"+String(pin)+" set to "+String(value)+" degrees");
}
else
Ciao.writeResponse("xmpp",id,"Invalid angle value");
}
else
Ciao.writeResponse("xmpp",id,"Invalid command");
}

void digitalCommand(String cmd[], String id) {
int pin, value;

pin = (cmd[1]).toInt();

if (cmd[2] != "-1") {
value = (cmd[2]).toInt();
digitalWrite(pin, value);
if (value == 1)
Ciao.writeResponse("xmpp",id,"Pin D"+String(pin)+" ON");
else if(value == 0)
Ciao.writeResponse("xmpp",id,"Pin D"+String(pin)+" OFF");
}
else if (cmd[2] == "-1") {
value = digitalRead(pin);
Ciao.writeResponse("xmpp",id,"D"+String(pin)+" value = "+String(value));
}
}

void analogCommand(String cmd[], String id) {
int pin, value;

pin = (cmd[1]).toInt();

if (cmd[2] != "-1") {
value =(cmd[2]).toInt();
analogWrite(pin, value);
Ciao.writeResponse("xmpp",id,"D"+String(pin)+" set to analog");
}
else if (cmd[2] == "-1") {
value = analogRead(pin);
Ciao.writeResponse("xmpp",id,"A"+String(pin)+" value = "+String(value));
}
}

void setMode(String cmd[], String id) {
int pin;

pin = (cmd[1]).toInt();

if (cmd[2] == "INPUT") {
pinMode(pin, INPUT);
Ciao.writeResponse("xmpp",id," pin D"+String(pin)+" set in INPUT mode");
return;
}

if (cmd[2] == "OUTPUT") {
pinMode(pin, OUTPUT);
Ciao.writeResponse("xmpp",id," pin D"+String(pin)+" set in OUTPUT mode");
return;
}
Ciao.writeResponse("xmpp",id,"invalid mode");
}
32 changes: 0 additions & 32 deletions libraries/Ciao/keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,38 +18,6 @@ begin KEYWORD2
writeResponse KEYWORD2
available KEYWORD2
read KEYWORD2
peek KEYWORD2
write KEYWORD2
flush KEYWORD2
bool KEYWORD2

# Bridge Class
split_command KEYWORD2
get KEYWORD2

# Console Class
buffer KEYWORD2
noBuffer KEYWORD2
connected KEYWORD2

# FileIO Class
File KEYWORD2
seek KEYWORD2
position KEYWORD2
size KEYWORD2
close KEYWORD2
name KEYWORD2
isDirectory KEYWORD2
openNextFile KEYWORD2
rewindDirectory KEYWORD2




#######################################
# Constants (LITERAL1)
#######################################

FILE_READ LITERAL1
FILE_WRITE LITERAL1
FILE_APPEND LITERAL1
10 changes: 5 additions & 5 deletions libraries/Ciao/library.properties
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name=Ciao
version=1.0
author=Arduino
maintainer=Arduino <[email protected]>
sentence=Enables the communication between the Linux processor and the AVR. For Arduino Yún and Yún Mini.
paragraph=The Bridge library feature: access to the shared storage, run and manage linux processes, open a remote console, access to the linux file system, including the SD card, enstablish http clients or servers.
author=Arduino srl
maintainer=Arduino srl<[email protected]>
sentence=Enables the communication between the Linux processor and the AVR. For Arduino Yún, Yún Mini and Linino One.
paragraph=
category=Communication
url=http://arduino.org/en/Reference/YunBridgeLibrary
url=http://labs.arduino.org/Ciao
architectures=*
6 changes: 3 additions & 3 deletions libraries/Ciao/src/Ciao.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
* Copyright (c) 2015 Arduino srl. All right reserved.
*
* File : Ciao.cpp
* Date : 2015/07/03
* Date : 2015/09/17
* Revision : 0.0.1 $
*
* Author: andrea[at]arduino[dot]org
*
****************************************************************************
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
Expand Down
3 changes: 2 additions & 1 deletion libraries/Ciao/src/Ciao.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
* Copyright (c) 2015 Arduino srl. All right reserved.
*
* File : Ciao.h
* Date : 2015/07/03
* Date : 2015/09/17
* Revision : 0.0.1 $
* Author: andrea[at]arduino[dot]org
*
****************************************************************************
Expand Down
3 changes: 2 additions & 1 deletion libraries/Ciao/src/CiaoData.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
* Copyright (c) 2015 Arduino srl. All right reserved.
*
* File : CiaoData.h
* Date : 2015/07/03
* Date : 2015/09/17
* Revision : 0.0.1 $
* Author: andrea[at]arduino[dot]org
*
****************************************************************************
Expand Down

0 comments on commit d055fc6

Please sign in to comment.