Hi everybody,
I finally succeded in making my Android Phone and my Arduino Uno + Wifly Shield communicate. So for now, I can connect my Samsung Galaxy S to my Arduino and then send the values of the accelerometer (that's an example, it can send values, that's the important thing).
Well now, what i'm trying to do is to read these values and make the Arduino react according to them. I mean, if the SmartPhone sends a value like "<1", then it means a servo has to be started, or whatever. In fact, I guess it's only parsing but I can't get it to work :-/ I tried to use the TextFinder Library but I got a problem : Here's the code which is provided as an example (adapted for WiFly, because it was for Ethernet Shield):
/*
* WebServerParsing
*
* Respond to requests in the URL to change digital and analog output ports
* show the number of ports changed and the value of the analog input pins.
*
* the following url turns digital pin 2 on and 3 off, analog output on pin 9 is set to 128, pin 11 to 255
* only onen parm http://192.168.1.177/2
*
* http://192.168.1.177/?pinD2=1&pinD3=0&pinA9=128&pinA11=255
*/
#if ARDUINO > 18
#include <SPI.h> // needed for Arduino versions later than 0018
#endif
#include <WiFly.h>
#include <TextFinder.h>
char ssid[] = "WIFI-ECOLE-WPA";
char passphrase[] = "WifiCampus";
Server server(80);
void setup()
{
Serial.begin(9600);
WiFly.begin();
if (!WiFly.join(ssid, passphrase))
{
Serial.println("Association failed.");
while (1) {
// Hang on failure.
}
}
Serial.begin(9600);
Serial.print("IP: ");
Serial.println(WiFly.ip());
server.begin();
Serial.println("ready");
}
void loop()
{
Client client = server.available();
if (client) {
TextFinder finder(client );
// an http request ends with a blank line
// boolean current_line_is_blank = true;
while (client.connected()) {
if (client.available()) {
int digitalRequests = 0; // counters to show the number of pin change requests
int analogRequests = 0;
if( finder.find("GET /") ) {
// find tokens starting with "pin" and stop on the first blank line
while(finder.findUntil("pin", "\n\r")){
char type = client.read(); // D or A
int pin = finder.getValue();
int val = finder.getValue();
if( type == 'D') {
Serial.print("Digital pin ");
pinMode(pin, OUTPUT);
digitalWrite(pin, val);
digitalRequests++;
}
else if( type == 'A'){
Serial.print("Analog pin ");
analogWrite(pin, val);
analogRequests++;
}
else {
Serial.print("Unexpected type ");
Serial.print(type);
}
Serial.print(pin);
Serial.print("=");
Serial.println(val);
}
}
Serial.println();
// when we get here the findUntil has detected the blank line (a lf followed by cr)
// so the http request has ended and we can send a reply
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
// output the number of pins handled by the request
client.print(digitalRequests);
client.print(" digital pin(s) written");
client.println("
");
client.print(analogRequests);
client.print(" analog pin(s) written");
client.println("
");
client.println("
");
// output the value of each analog input pin
for (int i = 0; i < 6; i++) {
client.print("analog input ");
client.print(i);
client.print(" is ");
client.print(analogRead(i));
client.println("
");
}
break;
}
}
// give the web browser time to receive the data
delay(1);
client.stop();
}
}
But here's what I get :
error: no matching function for call to 'TextFinder::TextFinder(Client&)'
They use it like that here though : http://www.arduino.cc/playground/Code/TextFinder
As a consequence, i'm wondering what's the problem. It does work with Ethernet and not with WiFly ? I'm a little bit lost...
Thank you very much and have a nice and sunny day