WiFLy Shield : convert incoming datas into command

Hi everyone,

Everything works finally perfect, I succeded in connecting my Android Phone to my Arduino using a self-made TCP Server and I can transmit commands between both. My problem now is that I would like my Arduino to… “understand” what it is receiving. I mean, for example I would like to send my Arduino “up”, which would run the motors. At the moment I use SpiUartTerminal and I thought I just had to add conditions in the loop, like:

void loop() {

  while(SpiSerial.available() > 0) {
    Serial.print(SpiSerial.read(), BYTE);

  // Here add a condition like if SpiSerial.read() == "up", handle the motor, but it can't be since the read() function return an Integer. And I think this loop isn't in the right place is it ? ^^
  }
  
  if(Serial.available()) {
    SpiSerial.print(Serial.read(), BYTE);
  }

Well that’s just very simple, but what I just wrote is totally wrong because SpiSerial.read() is an Int whereas up is a string, so would anyone have an idea how I could make my 2 devices understand eachother ? :slight_smile: Like making a big dictionnary of functions so it will be like a sinergy ^^

Maybe the TexFinder Library ? I tried to run the WebServer but it couldn’t being compiled because of this line : TextFinder finder(client); . It says there’s no matching function.

Thank you, you helped me a lot for this project and I hope I would be once able to help you back.

By the way, here’s the code I’m trying to debug:

#include "WiFly.h"
#include "Credentials.h"
#include "TextFinder.h"


Server server(80);


int instruction;

void setup() {
  WiFly.begin();

  if (!WiFly.join(ssid, passphrase)) {
    while (1) {
      // Hang on failure
    }
  }

  Serial.begin(38400);
  Serial.print("IP: ");
  Serial.println(WiFly.ip());
  
  server.begin();
}

void loop() {
  Client client = server.available();
  if (client) {
    TextFinder finder(client);              // It doesn't work here...
    while (client.connected()) {
      if (client.available()) 
      {
        
        if(Serial.available() > 0)
        {
           finder.find("@"); 
           instruction = finder.getValue();
           ParseInstruction(instruction);
        }
      }
    }
    // give the web browser time to receive the data
    delay(100);
    client.stop();
  }
  
  else
  {
      while(SpiSerial.available() > 0) 
      {
        Serial.print(SpiSerial.read(), BYTE);
      }
  
      if(Serial.available()) 
      { // Outgoing data
        SpiSerial.print(Serial.read(), BYTE);
      }
    
  }
}

void ParseInstruction(int instr)
{

  switch(instr)
  {
    case 1:
    // Here's the code
    break;
    
    case 2:
     // Here's the code
    break;
    
    default:
     // Here's the code
    break;
  }
  
}

However, I can’t bind my TextFinder to my client, even if I used an instruction available here: http://www.arduino.cc/playground/Code/TextFinder , so, this one:

TextFinder finder(client);

Here’s the error I get :

WiFly_WebServer:29: error: no matching function for call to ‘TextFinder::TextFinder(Client&)’

I understand the error, TextFinder parameters() are either Stream and an Integer, either a const. However, I don’t understand why it should work on the Arduino Official Website and not here…

Sorry for the double post, I got an error when I tried to edit my first message…

EDIT: I think there’s a conflict between WiFly Library’s client and Ethernet Library’s client…

I too would like to use TextFinder with the WiFly library. Did you find a solution to allow you to do so?