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

Commit d055fc6

Browse files
author
sebba
committed
Updating Ciao library
1 parent 6e0a524 commit d055fc6

File tree

9 files changed

+260
-47
lines changed

9 files changed

+260
-47
lines changed

libraries/Ciao/README.adoc

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
= Bridge Library for Arduino =
1+
= Ciao Library for Arduino =
22

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

5-
For more information about this library please visit us at
6-
http://arduino.cc/en/Reference/YunBridgeLibrary
6+
For more information about this library please visit us at:
7+
8+
http://labs.arduino.org/Ciao
79

810
== License ==
911

10-
Copyright (c) Arduino LLC. All right reserved.
12+
Copyright (c) Arduino srl. All right reserved.
1113

1214
This library is free software; you can redistribute it and/or
1315
modify it under the terms of the GNU Lesser General Public
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
Arduino Ciao example
3+
4+
This sketch uses ciao xmpp connector. It sends back “hello world” message to the xmpp client when receives “ciao” from it.
5+
6+
Be sure to set the xmpp client in the "USER" field used to receive the response by MCU.
7+
8+
Possible commands to send from the xmpp client:
9+
* "ciao" -> random answers in 5 different languages
10+
11+
created September 2015
12+
by andrea[at]arduino[dot]org
13+
14+
15+
NOTE: be sure to activate and configure xmpp connector on Linino OS
16+
http://labs.arduino.org/Ciao
17+
18+
*/
19+
20+
#include <Ciao.h>
21+
22+
String USER="user@domain";
23+
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" };
24+
25+
void setup() {
26+
Ciao.begin();
27+
}
28+
29+
void loop() {
30+
31+
CiaoData data = Ciao.read("xmpp");
32+
33+
if(!data.isEmpty()){
34+
String id = data.get(0);
35+
String sender = data.get(1);
36+
String message = data.get(2);
37+
38+
message.toLowerCase();
39+
if(message == "ciao" )
40+
Ciao.write("xmpp", USER,mess[random(0,5)]);
41+
}
42+
}
43+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
Arduino Ciao example
3+
4+
This sketch uses Ciao mqtt connector. Sketch sends via MQTT brightness and temperature information that will be shown graphically in the blueMix IBM system.
5+
Upload your sketch an than connect to the webpage:
6+
https://quickstart.internetofthings.ibmcloud.com/#/device/BlueMixTest902345/sensor/
7+
8+
NOTE: be sure to activate and configure mqtt connector on Linino OS.
9+
http://labs.arduino.org/Ciao
10+
11+
created September 2015
12+
by andrea[at]arduino[dot]org
13+
14+
*/
15+
16+
#include <Ciao.h>
17+
18+
int ctrl=0;
19+
void setup()
20+
{
21+
Ciao.begin(); //Start the serial connection with the computer
22+
//to view the result open the serial monitor
23+
pinMode(9,OUTPUT);
24+
}
25+
26+
void loop() // run over and over again
27+
{
28+
//getting the voltage reading from the temperature sensor
29+
int readingTemp = analogRead(A0);
30+
// converting readingTemp to voltage
31+
float voltage = readingTemp * 4.56;
32+
voltage /= 1024;
33+
// now print out the temperature
34+
float temperatureC = (voltage - 0.5) * 100 ;
35+
int readingLum = analogRead(A2);
36+
37+
analogWrite(9,map(readingLum,0,1023,0,255));
38+
39+
if (ctrl>=10){
40+
Ciao.write("mqtt","iot-2/evt/status/fmt/json","{\"d\": {\"temperature\":"+String(temperatureC)+",\"luminosity\":"+String(readingLum)+"}}");
41+
ctrl=0;
42+
}
43+
ctrl++;
44+
delay(100);
45+
46+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
/*
2+
3+
This sketch uses the xmpp connector to receive command for the MCU from a xmpp client.
4+
5+
Possible commands to send from the xmpp client:
6+
7+
* "digital/PIN" -> to read a digital PIN
8+
* "digital/PIN/VALUE" -> to write a digital PIN (VALUE: 1/0)
9+
* "analog/PIN/VALUE" -> to write in a PWM PIN(VALUE range: 0 - 255);
10+
* "analog/PIN" -> to read a analog PIN
11+
* "servo/PIN/VALUE" -> to write angle in a SERVO PIN(VALUE range: 0 - 180);
12+
* "mode/PIN/VALUE" -> to set the PIN mode (VALUE: input / output)
13+
* "led on" -> turn on led 13
14+
* "led off" -> turn off led 13
15+
* "ciao" -> random answers in 5 different languages
16+
17+
NOTE: be sure to activate and configure xmpp connector on Linino OS
18+
http://labs.arduino.org/Ciao
19+
20+
created September 2015
21+
by andrea[at]arduino[dot]org
22+
23+
*/
24+
25+
#include <Ciao.h>
26+
#include <Servo.h>
27+
28+
Servo servo;
29+
30+
void setup() {
31+
32+
Ciao.begin();
33+
}
34+
35+
void loop() {
36+
37+
CiaoData data = Ciao.read("xmpp");
38+
if(!data.isEmpty()){
39+
String id = data.get(0);
40+
String sender = data.get(1);
41+
String message = data.get(2);
42+
43+
message.toUpperCase();
44+
45+
if(message == "LED ON"){
46+
digitalWrite(13,HIGH);
47+
Ciao.writeResponse("xmpp",id,"Led D13 ON");
48+
}
49+
50+
else if(message == "LED OFF"){
51+
digitalWrite(13,LOW);
52+
Ciao.writeResponse("xmpp",id,"Led D13 OFF");
53+
}
54+
else{
55+
String command[3];
56+
57+
splitString(message,"/",command,3);
58+
execute(command,id);
59+
}
60+
}
61+
}
62+
63+
void execute(String cmd[], String id) {
64+
65+
if (cmd[0] == "DIGITAL") {
66+
digitalCommand(cmd,id);
67+
}
68+
else if (cmd[0] == "ANALOG") {
69+
analogCommand(cmd,id);
70+
}
71+
else if (cmd[0] == "SERVO") {
72+
servoCommand(cmd,id);
73+
}
74+
else if (cmd[0] == "MODE") {
75+
setMode(cmd,id);
76+
}
77+
else
78+
Ciao.writeResponse("xmpp",id,"sorry, i don't understand :(");
79+
}
80+
81+
void servoCommand(String cmd[], String id){
82+
int pin, value;
83+
84+
pin = (cmd[1]).toInt();
85+
86+
if (cmd[2] != "-1") {
87+
value = (cmd[2]).toInt();
88+
if(value <= 180 && value >=0){
89+
servo.attach(pin);
90+
servo.write(value);
91+
Ciao.writeResponse("xmpp",id,"Servo D"+String(pin)+" set to "+String(value)+" degrees");
92+
}
93+
else
94+
Ciao.writeResponse("xmpp",id,"Invalid angle value");
95+
}
96+
else
97+
Ciao.writeResponse("xmpp",id,"Invalid command");
98+
}
99+
100+
void digitalCommand(String cmd[], String id) {
101+
int pin, value;
102+
103+
pin = (cmd[1]).toInt();
104+
105+
if (cmd[2] != "-1") {
106+
value = (cmd[2]).toInt();
107+
digitalWrite(pin, value);
108+
if (value == 1)
109+
Ciao.writeResponse("xmpp",id,"Pin D"+String(pin)+" ON");
110+
else if(value == 0)
111+
Ciao.writeResponse("xmpp",id,"Pin D"+String(pin)+" OFF");
112+
}
113+
else if (cmd[2] == "-1") {
114+
value = digitalRead(pin);
115+
Ciao.writeResponse("xmpp",id,"D"+String(pin)+" value = "+String(value));
116+
}
117+
}
118+
119+
void analogCommand(String cmd[], String id) {
120+
int pin, value;
121+
122+
pin = (cmd[1]).toInt();
123+
124+
if (cmd[2] != "-1") {
125+
value =(cmd[2]).toInt();
126+
analogWrite(pin, value);
127+
Ciao.writeResponse("xmpp",id,"D"+String(pin)+" set to analog");
128+
}
129+
else if (cmd[2] == "-1") {
130+
value = analogRead(pin);
131+
Ciao.writeResponse("xmpp",id,"A"+String(pin)+" value = "+String(value));
132+
}
133+
}
134+
135+
void setMode(String cmd[], String id) {
136+
int pin;
137+
138+
pin = (cmd[1]).toInt();
139+
140+
if (cmd[2] == "INPUT") {
141+
pinMode(pin, INPUT);
142+
Ciao.writeResponse("xmpp",id," pin D"+String(pin)+" set in INPUT mode");
143+
return;
144+
}
145+
146+
if (cmd[2] == "OUTPUT") {
147+
pinMode(pin, OUTPUT);
148+
Ciao.writeResponse("xmpp",id," pin D"+String(pin)+" set in OUTPUT mode");
149+
return;
150+
}
151+
Ciao.writeResponse("xmpp",id,"invalid mode");
152+
}

libraries/Ciao/keywords.txt

-32
Original file line numberDiff line numberDiff line change
@@ -18,38 +18,6 @@ begin KEYWORD2
1818
writeResponse KEYWORD2
1919
available KEYWORD2
2020
read KEYWORD2
21-
peek KEYWORD2
2221
write KEYWORD2
23-
flush KEYWORD2
2422
bool KEYWORD2
2523

26-
# Bridge Class
27-
split_command KEYWORD2
28-
get KEYWORD2
29-
30-
# Console Class
31-
buffer KEYWORD2
32-
noBuffer KEYWORD2
33-
connected KEYWORD2
34-
35-
# FileIO Class
36-
File KEYWORD2
37-
seek KEYWORD2
38-
position KEYWORD2
39-
size KEYWORD2
40-
close KEYWORD2
41-
name KEYWORD2
42-
isDirectory KEYWORD2
43-
openNextFile KEYWORD2
44-
rewindDirectory KEYWORD2
45-
46-
47-
48-
49-
#######################################
50-
# Constants (LITERAL1)
51-
#######################################
52-
53-
FILE_READ LITERAL1
54-
FILE_WRITE LITERAL1
55-
FILE_APPEND LITERAL1

libraries/Ciao/library.properties

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
name=Ciao
22
version=1.0
3-
author=Arduino
4-
maintainer=Arduino <[email protected]>
5-
sentence=Enables the communication between the Linux processor and the AVR. For Arduino Yún and Yún Mini.
6-
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.
3+
author=Arduino srl
4+
maintainer=Arduino srl<[email protected]>
5+
sentence=Enables the communication between the Linux processor and the AVR. For Arduino Yún, Yún Mini and Linino One.
6+
paragraph=
77
category=Communication
8-
url=http://arduino.org/en/Reference/YunBridgeLibrary
8+
url=http://labs.arduino.org/Ciao
99
architectures=*

libraries/Ciao/src/Ciao.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
* Copyright (c) 2015 Arduino srl. All right reserved.
44
*
55
* File : Ciao.cpp
6-
* Date : 2015/07/03
6+
* Date : 2015/09/17
77
* Revision : 0.0.1 $
8-
*
8+
* Author: andrea[at]arduino[dot]org
9+
*
910
****************************************************************************
10-
1111
This library is free software; you can redistribute it and/or
1212
modify it under the terms of the GNU Lesser General Public
1313
License as published by the Free Software Foundation; either

libraries/Ciao/src/Ciao.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
* Copyright (c) 2015 Arduino srl. All right reserved.
44
*
55
* File : Ciao.h
6-
* Date : 2015/07/03
6+
* Date : 2015/09/17
77
* Revision : 0.0.1 $
8+
* Author: andrea[at]arduino[dot]org
89
*
910
****************************************************************************
1011

libraries/Ciao/src/CiaoData.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
* Copyright (c) 2015 Arduino srl. All right reserved.
44
*
55
* File : CiaoData.h
6-
* Date : 2015/07/03
6+
* Date : 2015/09/17
77
* Revision : 0.0.1 $
8+
* Author: andrea[at]arduino[dot]org
89
*
910
****************************************************************************
1011

0 commit comments

Comments
 (0)