Index: rtos_arduino/trunk/arduino_lib/libraries/Ciao/examples/CiaoRestClient/CiaoRestClient.ino
===================================================================
--- rtos_arduino/trunk/arduino_lib/libraries/Ciao/examples/CiaoRestClient/CiaoRestClient.ino	(revision 175)
+++ rtos_arduino/trunk/arduino_lib/libraries/Ciao/examples/CiaoRestClient/CiaoRestClient.ino	(revision 224)
@@ -3,13 +3,16 @@
 
 #define CONNECTOR     "rest" 
-#define SERVER_ADDR   "192.168.0.100" // change ip address with your server ip address
+#define SERVER_ADDR   "192.168.1.1" // change ip address with your server ip address
 
-int buttonState = LOW; //this variable tracks the state of the button, low if not pressed, high if pressed
-int ledState = -1; //this variable tracks the state of the LED, negative if off, positive if on
+int buttonState; //this variable tracks the state of the button, low if not pressed, high if pressed
+int ledState = HIGH; //this variable tracks the state of the LED, negative if off, positive if on
 long lastDebounceTime = 0;  // the last time the output pin was toggled
 long debounceDelay = 50;    // the debounce time; increase if the output flickers
+String command = "/arduino/mode/13/output";
+int previous_value = LOW;
 
 void setup() {
   Ciao.begin();
+  Ciao.write(CONNECTOR, SERVER_ADDR, command);
   pinMode(2, INPUT);
   
@@ -20,32 +23,29 @@
   //sample the state of the button - is it pressed or not?
   buttonState = digitalRead(2);
- 
+  
   //filter out any noise by setting a time buffer
-  if ( (millis() - lastDebounceTime) > debounceDelay) {
- 
-    //if the button has been pressed, lets toggle the LED from "off to on" or "on to off"
-    if ( (buttonState == HIGH) && (ledState < 0) ) {
- 
-      CiaoData data = Ciao.write(CONNECTOR, SERVER_ADDR, "/arduino/digital/12/1"); //turn LED on
-      ledState = -ledState; //now the LED is on, we need to change the state
-      lastDebounceTime = millis(); //set the current time
+  if ( (buttonState == HIGH) && (previous_value == LOW) && (millis() - lastDebounceTime) > debounceDelay ) {
+    if (ledState == HIGH){
+      command = "/arduino/digital/13/0";
+      ledState = LOW;
     }
-    else if ( (buttonState == HIGH) && (ledState > 0) ) {
- 
-      CiaoData data = Ciao.write(CONNECTOR, SERVER_ADDR, "/arduino/digital/12/0"); //turn LED off
-      ledState = -ledState; //now the LED is off, we need to change the state
-      lastDebounceTime = millis(); //set the current time
-        
-      if (!data.isEmpty()){
-        Ciao.println( "State: " + String (data.get(1)) );
-        Ciao.println( "Response: " + String (data.get(2)) );
-      }
-      else{ 
-        Ciao.println ("Write Error");
-      }
-              
+    else{
+      command = "/arduino/digital/13/1";
+      ledState = HIGH;
     }
- 
+     
+    lastDebounceTime = millis(); //set the current time
+    CiaoData data = Ciao.write(CONNECTOR, SERVER_ADDR, command);  
+    if (!data.isEmpty()){
+      Ciao.println( "State: " + String (data.get(1)) );
+      Ciao.println( "Response: " + String (data.get(2)) );
+    }
+    else{ 
+      Ciao.println ("Write Error");
+    }
+
   }
  
+  previous_value = buttonState;
+ 
 }
Index: rtos_arduino/trunk/arduino_lib/libraries/Ciao/examples/CiaoRestServer/CiaoRestServer.ino
===================================================================
--- rtos_arduino/trunk/arduino_lib/libraries/Ciao/examples/CiaoRestServer/CiaoRestServer.ino	(revision 175)
+++ rtos_arduino/trunk/arduino_lib/libraries/Ciao/examples/CiaoRestServer/CiaoRestServer.ino	(revision 224)
@@ -1,26 +1,31 @@
 /*
 
- This sketch uses the xmpp connector to receive command for the MCU from a xmpp client.
+ This sketch uses the restserver connector receive rest calls. It allows access to
+ the analog and digital pin of the board via rest calls.
+
+ supported boards: Yun,Tian.
 
  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)
- * "ledon"              -> turn on led 13
- * "ledoff"             -> 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
-   
+ * "/arduino/digital/PIN"       -> to read a digital PIN
+ * "/arduino/digital/PIN/VALUE" -> to write a digital PIN (VALUE: 1/0)
+ * "/arduino/analog/PIN/VALUE"  -> to write in a PWM PIN(VALUE range: 0 - 255);
+ * "/arduino/analog/PIN"        -> to read a analog PIN
+ * "/arduino/servo/PIN/VALUE"   -> to write angle in a SERVO PIN(VALUE range: 0 - 180);
+ * "/arduino/mode/PIN/VALUE"    -> to set the PIN mode (VALUE: input / output)
+
+ Example:
+ "/arduino/mode/13/output" -> pinMode(13, OUTPUT)
+ "/arduino/digital/13/1"     -> digitalWrite(13, HIGH)
+
+
+ NOTE: be sure to activate and configure restserver connector on Linino OS
+  http://labs.arduino.org/Ciao
+
  created September 2015
  by andrea[at]arduino[dot]org
- 
+
  */
- 
+
 #include <Ciao.h>
 #include <Servo.h>
@@ -35,14 +40,14 @@
 void loop() {
 
-  CiaoData data = Ciao.read("restserver");   
-  if(!data.isEmpty()){  
+  CiaoData data = Ciao.read("restserver");
+  if(!data.isEmpty()){
     String id = data.get(0);
     String sender = data.get(1);
     String message = data.get(2);
-    
+
     message.toUpperCase();
-    
+
     String command[3];
-          
+
     splitString(message,"/",command,3);
     execute(command,id);
@@ -71,7 +76,7 @@
 void servoCommand(String cmd[], String id){
    int pin, value;
-  
+
   pin = (cmd[1]).toInt();
-  
+
   if (cmd[2] != "-1") {
     value = (cmd[2]).toInt();
@@ -85,12 +90,12 @@
   }
   else
-    Ciao.writeResponse("restserver",id,"Invalid command");  
+    Ciao.writeResponse("restserver",id,"Invalid command");
 }
 
 void digitalCommand(String cmd[], String id) {
   int pin, value;
-  
+
   pin = (cmd[1]).toInt();
-  
+
   if (cmd[2] != "-1") {
     value = (cmd[2]).toInt();
@@ -99,5 +104,5 @@
       Ciao.writeResponse("restserver",id,"Pin D"+String(pin)+" ON");
     else if(value == 0)
-      Ciao.writeResponse("restserver",id,"Pin D"+String(pin)+" OFF");   
+      Ciao.writeResponse("restserver",id,"Pin D"+String(pin)+" OFF");
   }
   else if (cmd[2] == "-1") {
@@ -111,5 +116,5 @@
 
   pin = (cmd[1]).toInt();
-  
+
   if (cmd[2] != "-1") {
     value =(cmd[2]).toInt();
@@ -127,5 +132,5 @@
 
   pin = (cmd[1]).toInt();
-  
+
   if (cmd[2] == "INPUT") {
     pinMode(pin, INPUT);
Index: rtos_arduino/trunk/arduino_lib/libraries/Ciao/keywords.txt
===================================================================
--- rtos_arduino/trunk/arduino_lib/libraries/Ciao/keywords.txt	(revision 175)
+++ rtos_arduino/trunk/arduino_lib/libraries/Ciao/keywords.txt	(revision 224)
@@ -7,8 +7,8 @@
 #######################################
 
-Ciao		KEYWORD3
-CiaoData	KEYWORD3
-Wifi		KEYWORD3
-WifiData	KEYWORD3
+Ciao  KEYWORD3
+CiaoData  KEYWORD3
+Wifi  KEYWORD3
+WifiData  KEYWORD3
 
 #######################################
@@ -16,9 +16,10 @@
 #######################################
 
-begin			KEYWORD2
-writeResponse	KEYWORD2
-available		KEYWORD2
-read			KEYWORD2
-write			KEYWORD2
-bool			KEYWORD2
+writeResponse KEYWORD2
+available KEYWORD2
+read  KEYWORD2
+write KEYWORD2
 
+#######################################
+# Constants (LITERAL1)
+#######################################
Index: rtos_arduino/trunk/arduino_lib/libraries/Ciao/library.properties
===================================================================
--- rtos_arduino/trunk/arduino_lib/libraries/Ciao/library.properties	(revision 175)
+++ rtos_arduino/trunk/arduino_lib/libraries/Ciao/library.properties	(revision 224)
@@ -1,4 +1,4 @@
 name=Ciao
-version=1.0
+version=0.0.3
 author=Arduino srl
 maintainer=Arduino srl<info@arduino.org>
Index: rtos_arduino/trunk/arduino_lib/libraries/Ciao/src/Ciao.h
===================================================================
--- rtos_arduino/trunk/arduino_lib/libraries/Ciao/src/Ciao.h	(revision 175)
+++ rtos_arduino/trunk/arduino_lib/libraries/Ciao/src/Ciao.h	(revision 224)
@@ -30,11 +30,8 @@
 
 #include <Arduino.h>
+#include <Stream.h>
 #include "lib/CiaoData.h"
 #if defined(__AVR_ATmega328P__)
-#include "lib/rest.h"
 #include "lib/SC16IS750.h"
-#include "lib/espduino.h"
-#else
-#include <Stream.h>
 #endif
 
@@ -44,5 +41,5 @@
 #define BAUDRATE 250000
 #elif defined(ARDUINO_ARCH_SAMD)
-#define BAUDRATE 115200
+#define BAUDRATE 4000000
 #endif
 
@@ -55,18 +52,10 @@
 		CiaoData parse( String, String);
 		void println(String log){};
-		#if defined(__AVR_ATmega32U4__) 
 		CiaoClass(Stream &_stream);
-		#elif defined(ARDUINO_ARCH_SAMD)
-		CiaoClass(Serial_ stream);
-		#endif
 
 	private:
 		void dropAll();
 		bool started;
-		#if defined(__AVR_ATmega32U4__)
 		Stream &stream;
-		#elif defined(ARDUINO_ARCH_SAMD)
-		Serial_ stream;
-		#endif
 };
 
@@ -80,7 +69,7 @@
 		}
 		#elif defined(ARDUINO_ARCH_SAMD)
-		SerialCiaoClass(Serial_ serial)
-			: CiaoClass(serial){
-			// Empty	
+		SerialCiaoClass(Serial_ &_serial)
+			: CiaoClass(_serial), serial(_serial) {
+			// Empty
 		}
 		#endif
@@ -93,5 +82,5 @@
 		HardwareSerial &serial;
 		#elif defined(ARDUINO_ARCH_SAMD)
-		Serial_ serial;
+		Serial_ &serial;
 		#endif
 };
@@ -103,17 +92,21 @@
 #else
 
-// class CiaoData {
-// 	public:
-		
-// 		char* get(int index){
-// 			return msg_split[index];
-// 		}
-  
-// 	public:
-// 		char* msg_split[3];
-		
-// };
+class ArduinoWifiClass : public WifiData
+{
 
-class CiaoClass {
+	public:
+		void begin();		
+
+		boolean connected();
+		void connect(char* , char*);
+
+		void powerON();
+		void powerOFF();
+
+
+};
+
+class CiaoClass : public WifiData
+{
 	public:
 		void begin();
@@ -124,10 +117,10 @@
 		CiaoData write( char*, char*, String );            // ârestâ, âhostnameâ, âStringoneâ,		
 		CiaoData write( char*, char*, String, char*);      // ârestâ, âhostnameâ, âStringoneâ, âmethodâ
-		
-		void print(String str);
-		void println(String str);
 	
 };
+
+
 extern CiaoClass Ciao;
+extern ArduinoWifiClass Wifi;
 
 #endif
Index: rtos_arduino/trunk/arduino_lib/libraries/Ciao/src/lib/Ciao.cpp
===================================================================
--- rtos_arduino/trunk/arduino_lib/libraries/Ciao/src/lib/Ciao.cpp	(revision 175)
+++ rtos_arduino/trunk/arduino_lib/libraries/Ciao/src/lib/Ciao.cpp	(revision 224)
@@ -24,18 +24,13 @@
 */
 
-#include "Ciao.h"
 
 #if defined(__AVR_ATmega32U4__) || defined(ARDUINO_ARCH_SAMD)
 
-#if defined(__AVR_ATmega32U4__)
+#include "Ciao.h"
+
 CiaoClass::CiaoClass(Stream &_stream) :
 	stream(_stream), started(false) {
   // Empty
 }
-#elif defined(ARDUINO_ARCH_SAMD)
-CiaoClass::CiaoClass(Serial_ stream){
-  // Empty
-}
-#endif
 
 void CiaoClass::begin() {
@@ -60,8 +55,6 @@
     }
 	do{ 
-		#if defined(__AVR_ATmega32U4__)
 		stream.print(F("run-ciao\n"));				//start bridge python
 		stream.readStringUntil(END_TX_CHAR);
-		#endif
 		delay(3000);
 		stream.println("ciao;r;status");				//check if bridge python is running
Index: rtos_arduino/trunk/arduino_lib/libraries/Ciao/src/lib/SC16IS750.cpp
===================================================================
--- rtos_arduino/trunk/arduino_lib/libraries/Ciao/src/lib/SC16IS750.cpp	(revision 175)
+++ rtos_arduino/trunk/arduino_lib/libraries/Ciao/src/lib/SC16IS750.cpp	(revision 224)
@@ -27,13 +27,7 @@
 #define WIRE Wire
 
-
-WifiData::WifiData(uint8_t prtcl, uint8_t addr_sspin)
-{
-    protocol = prtcl;
-    if ( protocol == SC16IS750_PROTOCOL_I2C ) {
-        device_address_sspin = (addr_sspin>>1);
-    } else {
-        device_address_sspin = addr_sspin;
-    }
+WifiData::WifiData()
+{
+    device_address_sspin = (SC16IS750_ADDRESS_AA >> 1);
     peek_flag = 0;
 }
@@ -41,7 +35,6 @@
 void WifiData::begin(uint32_t baud)
 {
-    //Serial.println("1111111111111111");
+
     if ( protocol == SC16IS750_PROTOCOL_I2C) {
-    //Serial.println("22222222222222");
         WIRE.begin();
     } 
Index: rtos_arduino/trunk/arduino_lib/libraries/Ciao/src/lib/SC16IS750.h
===================================================================
--- rtos_arduino/trunk/arduino_lib/libraries/Ciao/src/lib/SC16IS750.h	(revision 175)
+++ rtos_arduino/trunk/arduino_lib/libraries/Ciao/src/lib/SC16IS750.h	(revision 224)
@@ -104,10 +104,11 @@
 #define     SC16IS750_PROTOCOL_I2C  (0)
 #define     SC16IS750_PROTOCOL_I2C  (0)
-#define     END     "<!--~-->"
+#define     DELIMITER     "<!--~-->"
+#define     EOL           '\0'
 
 class WifiData : public Stream
 { 
     public:
-        WifiData(uint8_t prtcl = SC16IS750_PROTOCOL_I2C, uint8_t addr = SC16IS750_ADDRESS_AD);
+	WifiData();
         void begin(uint32_t baud);                               
         int read();
Index: rtos_arduino/trunk/arduino_lib/libraries/Ciao/src/lib/espduino.cpp
===================================================================
--- rtos_arduino/trunk/arduino_lib/libraries/Ciao/src/lib/espduino.cpp	(revision 175)
+++ rtos_arduino/trunk/arduino_lib/libraries/Ciao/src/lib/espduino.cpp	(revision 224)
@@ -188,6 +188,6 @@
 }
 
-ESP::ESP(Stream *serial, int chip_pd):
-_serial(serial), _chip_pd(chip_pd)
+ESP::ESP(Stream *serial):
+_serial(serial)
 {
   _debugEn = false;
@@ -195,11 +195,5 @@
 }
 
-ESP::ESP(Stream *serial, Stream* debug, int chip_pd):
-_serial(serial), _debug(debug), _chip_pd(chip_pd)
-{
-    _debugEn = true;
-    //_serial = _debug;
-    init();
-}
+
 void ESP::enable()
 {
Index: rtos_arduino/trunk/arduino_lib/libraries/Ciao/src/lib/espduino.h
===================================================================
--- rtos_arduino/trunk/arduino_lib/libraries/Ciao/src/lib/espduino.h	(revision 175)
+++ rtos_arduino/trunk/arduino_lib/libraries/Ciao/src/lib/espduino.h	(revision 224)
@@ -92,6 +92,6 @@
 {
 public:
-  ESP(Stream *serial, Stream* debug, int chip_pd);
-  ESP(Stream *serial, int chip_pd);
+  //ESP(Stream *serial, Stream* debug, int chip_pd);
+  ESP(Stream *serial); //ok
   Stream *_debug;
 
Index: rtos_arduino/trunk/arduino_lib/libraries/Ciao/src/lib/wifi.cpp
===================================================================
--- rtos_arduino/trunk/arduino_lib/libraries/Ciao/src/lib/wifi.cpp	(revision 224)
+++ rtos_arduino/trunk/arduino_lib/libraries/Ciao/src/lib/wifi.cpp	(revision 224)
@@ -0,0 +1,192 @@
+/*
+****************************************************************************
+* Copyright (c) 2015 Arduino srl. All right reserved.
+*
+* File : wifi.cpp
+* Date : 2016/02/16
+* Revision : 0.0.1 $
+* Author: adriano[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
+  version 2.1 of the License, or (at your option) any later version.
+
+  This library is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public
+  License along with this library; if not, write to the Free Software
+  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+
+#include <stdarg.h>
+#include <stdio.h>
+
+#include "Ciao.h"
+#include "crc16.h"
+#include "rest.h"
+#include "espduino.h"
+#include "ringbuf.h"
+#include "FP.h"
+#include "string.h"
+
+#if defined(__AVR_ATmega328P__)
+
+WifiData espSerial;
+ESP esp(&espSerial);
+REST rest(&esp);
+
+boolean wifiConnected = false;
+
+ArduinoWifiClass Wifi;
+CiaoClass Ciao;
+
+void wifiCb(void* response)
+{
+	uint32_t status;
+	RESPONSE res(response);
+
+	if(res.getArgc() == 1) {
+		res.popArgs((uint8_t*)&status, 4);
+		if(status == STATION_GOT_IP){
+			espSerial.println("DBG: Internet Connected");
+			wifiConnected = true;
+		}
+		else {
+			wifiConnected = false;
+		}
+	}
+}
+
+void ArduinoWifiClass::powerON(){ 		
+}
+void ArduinoWifiClass::powerOFF(){ 		
+}
+
+void ArduinoWifiClass::connect(char* ssid,char* pwd){
+	esp.wifiConnect(ssid, pwd);
+}
+boolean ArduinoWifiClass::connected(){
+	return wifiConnected;
+}
+
+void WifiBegin(short isCiao) {
+	espSerial.begin(9600);
+	if(espSerial.ping()!=1) {
+		espSerial.println("DBG: esp not found");
+		while(1);
+	}
+	else {
+		//espSerial.println("device found");
+	}
+	//put GPIO control here !!!
+	esp.enable();
+	delay(1000);
+	esp.reset();
+	delay(1000);
+	while(!esp.ready());
+	if (isCiao == 0)
+		esp.wifiCb.attach(&wifiCb);
+
+	espSerial.println("\nDBG: UnoWiFi Start");
+}
+void ArduinoWifiClass::begin() {
+	WifiBegin(0);	
+}
+
+// -----------CIAO---------------------
+
+void CiaoClass::begin() {
+	
+        WifiBegin(1);
+	rest.begin("google.com");
+	rest.get("/");
+	delay(3000);
+}
+CiaoData responseREAD(){
+	CiaoData data;
+	delay(400);
+	char response[64] = "";
+	char cstr[8] = "";
+
+	int ret = rest.getResponse(response, 64);
+	//espSerial.println(ret);
+
+	snprintf(cstr,8,"%d",ret);
+
+		data.msg_split[0]="id";
+		data.msg_split[1]=cstr;
+		data.msg_split[2]=response;
+				
+	return data;
+}
+CiaoData requestPOST(char* hostname, String stringone){
+	rest.begin(hostname);
+	//delay(1000);	fix
+	//esp.process(); 
+	rest.post((const char*) stringone.c_str(),0);
+	return responseREAD(); 
+}
+
+CiaoData requestGET(char* hostname, String stringone){
+
+	rest.begin(hostname);
+	//delay(1000);   fix
+	//esp.process(); 
+	rest.get((const char*) stringone.c_str());
+	return responseREAD(); 
+}
+
+CiaoData PassThroughM(char* connector,char* hostname, String stringone, char* method){
+  
+	short mode = 0;
+	if (!strcmp(connector, "rest")){
+		mode = 0;
+	}
+	else if (!strcmp(connector, "mqtt")){
+		mode = 1;
+	}
+	else {
+		CiaoData data;				
+		data.msg_split[0]="";
+		data.msg_split[1]="";
+		data.msg_split[2]="Protocol Error";
+		return data;
+	}
+	
+	if (mode == 0){ 
+		if (!strcmp(method, "GET")){
+			return requestGET(hostname, stringone); 
+		}
+		else if (!strcmp(method, "POST")){
+			return requestPOST(hostname, stringone); 
+		}
+		else{
+			CiaoData data;				
+			data.msg_split[0]="";
+			data.msg_split[1]="";
+			data.msg_split[2]="Method Error";
+			return data;
+		}   
+	}
+}
+
+CiaoData CiaoClass::write(char* connector,char* hostname, String stringone, char* method) {
+	return PassThroughM(connector, hostname, stringone, method);
+}
+CiaoData CiaoClass::read(char* connector,char* hostname, String stringone, char* method) {
+	return PassThroughM(connector, hostname, stringone, method);
+}
+CiaoData CiaoClass::write(char* connector,char* hostname, String stringone) {
+	return PassThroughM(connector, hostname, stringone, "GET");
+}
+CiaoData CiaoClass::read(char* connector,char* hostname, String stringone) {
+	return PassThroughM(connector, hostname, stringone, "GET");
+}
+
+#endif
