From d055fc6e1cfb8110814731f1fde0b73f9974805a Mon Sep 17 00:00:00 2001 From: sebba Date: Fri, 18 Sep 2015 12:30:45 +0200 Subject: [PATCH] Updating Ciao library --- libraries/Ciao/README.adoc | 12 +- .../CiaoArduinoXMPP/CiaoArduinoXMPP.ino | 43 +++++ .../CiaoBluemixMQTT/CiaoBluemixMQTT.ino | 46 ++++++ .../CiaoCommandXMPP/CiaoCommandXMPP.ino | 152 ++++++++++++++++++ libraries/Ciao/keywords.txt | 32 ---- libraries/Ciao/library.properties | 10 +- libraries/Ciao/src/Ciao.cpp | 6 +- libraries/Ciao/src/Ciao.h | 3 +- libraries/Ciao/src/CiaoData.h | 3 +- 9 files changed, 260 insertions(+), 47 deletions(-) create mode 100644 libraries/Ciao/examples/CiaoArduinoXMPP/CiaoArduinoXMPP.ino create mode 100644 libraries/Ciao/examples/CiaoBluemixMQTT/CiaoBluemixMQTT.ino create mode 100644 libraries/Ciao/examples/CiaoCommandXMPP/CiaoCommandXMPP.ino diff --git a/libraries/Ciao/README.adoc b/libraries/Ciao/README.adoc index 9229d3e1..c98a27c3 100644 --- a/libraries/Ciao/README.adoc +++ b/libraries/Ciao/README.adoc @@ -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 diff --git a/libraries/Ciao/examples/CiaoArduinoXMPP/CiaoArduinoXMPP.ino b/libraries/Ciao/examples/CiaoArduinoXMPP/CiaoArduinoXMPP.ino new file mode 100644 index 00000000..abe30c8f --- /dev/null +++ b/libraries/Ciao/examples/CiaoArduinoXMPP/CiaoArduinoXMPP.ino @@ -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 + +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)]); + } +} + diff --git a/libraries/Ciao/examples/CiaoBluemixMQTT/CiaoBluemixMQTT.ino b/libraries/Ciao/examples/CiaoBluemixMQTT/CiaoBluemixMQTT.ino new file mode 100644 index 00000000..76d876e8 --- /dev/null +++ b/libraries/Ciao/examples/CiaoBluemixMQTT/CiaoBluemixMQTT.ino @@ -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 + +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); + +} \ No newline at end of file diff --git a/libraries/Ciao/examples/CiaoCommandXMPP/CiaoCommandXMPP.ino b/libraries/Ciao/examples/CiaoCommandXMPP/CiaoCommandXMPP.ino new file mode 100644 index 00000000..48b139d8 --- /dev/null +++ b/libraries/Ciao/examples/CiaoCommandXMPP/CiaoCommandXMPP.ino @@ -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 +#include + +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"); +} \ No newline at end of file diff --git a/libraries/Ciao/keywords.txt b/libraries/Ciao/keywords.txt index 47c9c348..2d0f1687 100644 --- a/libraries/Ciao/keywords.txt +++ b/libraries/Ciao/keywords.txt @@ -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 diff --git a/libraries/Ciao/library.properties b/libraries/Ciao/library.properties index eead82a6..ce7d8d72 100644 --- a/libraries/Ciao/library.properties +++ b/libraries/Ciao/library.properties @@ -1,9 +1,9 @@ name=Ciao version=1.0 -author=Arduino -maintainer=Arduino -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 +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=* diff --git a/libraries/Ciao/src/Ciao.cpp b/libraries/Ciao/src/Ciao.cpp index 86d725d1..1493ce57 100644 --- a/libraries/Ciao/src/Ciao.cpp +++ b/libraries/Ciao/src/Ciao.cpp @@ -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 diff --git a/libraries/Ciao/src/Ciao.h b/libraries/Ciao/src/Ciao.h index 53465742..df04f118 100644 --- a/libraries/Ciao/src/Ciao.h +++ b/libraries/Ciao/src/Ciao.h @@ -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 * **************************************************************************** diff --git a/libraries/Ciao/src/CiaoData.h b/libraries/Ciao/src/CiaoData.h index db9582d8..afed1ad5 100644 --- a/libraries/Ciao/src/CiaoData.h +++ b/libraries/Ciao/src/CiaoData.h @@ -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 * ****************************************************************************