This repository has been archived by the owner on Feb 21, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
sebba
committed
Sep 18, 2015
1 parent
6e0a524
commit d055fc6
Showing
9 changed files
with
260 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
libraries/Ciao/examples/CiaoArduinoXMPP/CiaoArduinoXMPP.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
46
libraries/Ciao/examples/CiaoBluemixMQTT/CiaoBluemixMQTT.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
152
libraries/Ciao/examples/CiaoCommandXMPP/CiaoCommandXMPP.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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=* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters