Pages: [1] 2   Go Down
Author Topic: String comparison  (Read 3274 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 14
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hopefully I am just doing something really stupid but I can't get the string comparison to work. I have tried with const, define, string with and without the extra space at the end but I just can't get the first or second if to run

Code:
#include <String.h>
#include <NewSoftSerial.h>

#define enable_code "3E0018105F69 "  //change this ID with your own card TAG
#define disable_code "3E00187E97CF "

NewSoftSerial RFID(2, 3);
String msg = String(60);
String ID = String(60); //string to store allowed cards
char c;

void setup()  
{
  Serial.begin(9600);
  Serial.println("Serial Ready");

  RFID.begin(9600);
  Serial.println("RFID Ready");
}

void loop()
{
  while(RFID.available()>0)
  {
    c=RFID.read();
    msg += c;
    Serial.println(msg);  //Uncomment to view your tag ID
  }
  if(msg == enable_code) add();
  if(msg == disable_code) del();  
  if(msg.length()>10) verifica();
  msg="";
}

void add()
{
  Serial.print("What TAG do you wanna grant access?: ");
  msg="";
  while(msg.length()<13)
  {
    while(RFID.available()>0)
    {
      c=RFID.read();
      msg += c;
    }
  }
  if(ID == msg)
  {
    Serial.println("\nAccess already granted for this card.");
    msg="";
  }
  else
  {
    Serial.print("Card: ");
    Serial.println(msg);
    ID += msg;
    ID += ",";
    Serial.print("ID: ");
    Serial.println(ID);
    msg="";
    Serial.println("Access granted for this card.");
  }
}

void del()
{
  msg="";
  Serial.print("What TAG do you wanna deny access?: ");
  while(msg.length()<13)
  {
    while(RFID.available()>0)
    {
      c=RFID.read();
      msg += c;
    }
  }
  if(ID == msg)
  {
    Serial.println(msg);
    Serial.println("TAG found. Access for this card denied.");
    //ID.replace(card,"");
    int pos=ID.indexOf(msg);
    msg="";
    msg += (ID.substring(0,pos));
    msg += (ID.substring(pos+15,ID.length()));
    ID="";
    ID += msg;
    //Serial.print("ID: ");
    //Serial.println(ID);
  } else Serial.println("\nTAG not found or already denied");
  msg="";
}

void verifica()
{
    if(ID == msg) Serial.println("Access granted.");
    else Serial.println("Access denied.");
}

I am guessing i am doing something really dumb but i have searched and searched and can't find an answer.
Logged

UK
Offline Offline
God Member
*****
Karma: 13
Posts: 903
Twitter: @simonmonk2
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

I may be completely wrong about this, but it looks all wrong, and somewhat Java-esque.

C is an old language, and you cannot just compare strings using ==. The == will just see if both strings start at the same memory address. You need to use strcmp.

But, you seem to be creating strings using +=, does this compile? As far as I am aware, you have to do all that kind of thing the hard way, writing things into buffers. I wouldn't even try to do any dynamic memory allocation on an Arduino. You can't afford memory leaks when you only have 1K  smiley

http://en.wikipedia.org/wiki/String.h
Logged

--
My New Arduino Book: http://www.arduinobook.com

0
Offline Offline
Edison Member
*
Karma: 0
Posts: 1103
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

When you install WString in your IDE you will get 8 examples with it - do look at them!
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 14
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It compiles fine with arduino 19 (strings is included in 19) and the string contains the correct data it is the first 2 if statements that do not seem to come back true but the last one does and prints the access denied error.

The info I got for the string.h is from the arduino website I do not have the wstring
« Last Edit: September 10, 2010, 10:43:37 am by Delfairen » Logged

0
Offline Offline
Tesla Member
***
Karma: 145
Posts: 9634
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
The info I got for the string.h is from the arduino website I do not have the wstring

http://www.arduino.cc/en/Tutorial/TextString
Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

0
Offline Offline
Newbie
*
Karma: 0
Posts: 14
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Still doesn't match on it.

Code:
#include <String.h>
#include <NewSoftSerial.h>

#define enable_code "3E0018105F69 "  //change this ID with your own card TAG
#define disable_code "3E00187E97CF "

NewSoftSerial RFID(2, 3);
String msg = String(60);
String ID = String(60); //string to store allowed cards
char c;

void setup()  
{
  Serial.begin(9600);
  Serial.println("Serial Ready");

  RFID.begin(9600);
  Serial.println("RFID Ready");
}

void loop()
{
  while(RFID.available()>0)
  {
    c=RFID.read();
    msg += c;
    Serial.println(msg);  //Uncomment to view your tag ID
  }
  if(msg.equals("3E0018105F69")) {add();}
  if(msg == disable_code) del();  
  if(msg.length()>10) verifica();
  msg="";
}

void add()
{
  Serial.print("What TAG do you wanna grant access?: ");
  msg="";
  while(msg.length()<13)
  {
    while(RFID.available()>0)
    {
      c=RFID.read();
      msg += c;
    }
  }
  if(ID == msg)
  {
    Serial.println("\nAccess already granted for this card.");
    msg="";
  }
  else
  {
    Serial.print("Card: ");
    Serial.println(msg);
    ID += msg;
    ID += ",";
    Serial.print("ID: ");
    Serial.println(ID);
    msg="";
    Serial.println("Access granted for this card.");
  }
}

void del()
{
  msg="";
  Serial.print("What TAG do you wanna deny access?: ");
  while(msg.length()<13)
  {
    while(RFID.available()>0)
    {
      c=RFID.read();
      msg += c;
    }
  }
  if(ID == msg)
  {
    Serial.println(msg);
    Serial.println("TAG found. Access for this card denied.");
    //ID.replace(card,"");
    int pos=ID.indexOf(msg);
    msg="";
    msg += (ID.substring(0,pos));
    msg += (ID.substring(pos+15,ID.length()));
    ID="";
    ID += msg;
    //Serial.print("ID: ");
    //Serial.println(ID);
  } else Serial.println("\nTAG not found or already denied");
  msg="";
}

void verifica()
{
    if(ID == msg) Serial.println("Access granted.");
    else Serial.println("Access denied.");
}

and the serial output

3
3E
3E0
3E00
3E001
3E0018
3E00181
3E001810
3E0018105
3E0018105F
3E0018105F6
3E0018105F69
3E0018105F69
Access denied.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 14
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

adding string from http://www.arduino.cc/en/Tutorial/TextString then adding contains instead of equals as below

Code:
if(msg.contains("3E0018105F69"))
{
add();
}

as per the example code in the string folder gives the following error when trying to compile

RFID.cpp: In function 'void loop()':
rfid:28: error: 'class String' has no member named 'contains'
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 14
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Trying to run the example code from the libraries/String/examples/StringContains

gives the following errors

C:\Program Files (x86)\arduino-0019\libraries\String\WString.cpp:34: error: prototype for 'String::String(int)' does not match any in class 'String'
C:\Program Files (x86)\arduino-0019\hardware\arduino\cores\arduino/WString.h:39: error: candidates are: String::String(long unsigned int, int)
C:\Program Files (x86)\arduino-0019\hardware\arduino\cores\arduino/WString.h:38: error:                 String::String(long int, int)
C:\Program Files (x86)\arduino-0019\hardware\arduino\cores\arduino/WString.h:37: error:                 String::String(unsigned int, int)
C:\Program Files (x86)\arduino-0019\hardware\arduino\cores\arduino/WString.h:36: error:                 String::String(int, int)
C:\Program Files (x86)\arduino-0019\hardware\arduino\cores\arduino/WString.h:35: error:                 String::String(unsigned char)
C:\Program Files (x86)\arduino-0019\hardware\arduino\cores\arduino/WString.h:34: error:                 String::String(char)
C:\Program Files (x86)\arduino-0019\hardware\arduino\cores\arduino/WString.h:33: error:                 String::String(const String&)
C:\Program Files (x86)\arduino-0019\hardware\arduino\cores\arduino/WString.h:32: error:                 String::String(const char*)
C:\Program Files (x86)\arduino-0019\libraries\String\WString.cpp: In constructor 'String::String(const char*)':
C:\Program Files (x86)\arduino-0019\libraries\String\WString.cpp:50: error: '_array' was not declared in this scope
C:\Program Files (x86)\arduino-0019\libraries\String\WString.cpp:52: error: 'setArray' was not declared in this scope
C:\Program Files (x86)\arduino-0019\libraries\String\WString.cpp: In copy constructor 'String::String(const String&)':
C:\Program Files (x86)\arduino-0019\libraries\String\WString.cpp:60: error: '_array' was not declared in this scope
C:\Program Files (x86)\arduino-0019\libraries\String\WString.cpp:61: error: 'clear' was not declared in this scope
C:\Program Files (x86)\arduino-0019\libraries\String\WString.cpp:62: error: 'const class String' has no member named '_array'
C:\Program Files (x86)\arduino-0019\libraries\String\WString.cpp:62: error: 'setArray' was not declared in this scope
C:\Program Files (x86)\arduino-0019\libraries\String\WString.cpp: In member function 'const String& String::operator=(const String&)':
C:\Program Files (x86)\arduino-0019\libraries\String\WString.cpp:77: error: '_array' was not declared in this scope
C:\Program Files (x86)\arduino-0019\libraries\String\WString.cpp:83: error: 'clear' was not declared in this scope
C:\Program Files (x86)\arduino-0019\libraries\String\WString.cpp:84: error: 'const class String' has no member named '_array'
C:\Program Files (x86)\arduino-0019\libraries\String\WString.cpp:84: error: 'setArray' was not declared in this scope
C:\Program Files (x86)\arduino-0019\libraries\String\WString.cpp: At global scope:
C:\Program Files (x86)\arduino-0019\libraries\String\WString.cpp:90: error: prototype for 'const String& String::operator=(const char*)' does not match any in class 'String'
C:\Program Files (x86)\arduino-0019\libraries\String\WString.cpp:70: error: candidate is: const String& String::operator=(const String&)
C:\Program Files (x86)\arduino-0019\libraries\String\WString.cpp:107: error: prototype for 'const String& String::operator+=(const char*)' does not match any in class 'String'
C:\Program Files (x86)\arduino-0019\hardware\arduino\cores\arduino/WString.h:44: error: candidate is: const String& String::operator+=(const String&)
C:\Program Files (x86)\arduino-0019\libraries\String\WString.cpp:127: error: prototype for 'const String& String::operator+=(char)' does not match any in class 'String'
C:\Program Files (x86)\arduino-0019\hardware\arduino\cores\arduino/WString.h:44: error: candidate is: const String& String::operator+=(const String&)
C:\Program Files (x86)\arduino-0019\libraries\String\WString.cpp:145: error: prototype for 'const String& String::operator+=(int)' does not match any in class 'String'
C:\Program Files (x86)\arduino-0019\hardware\arduino\cores\arduino/WString.h:44: error: candidate is: const String& String::operator+=(const String&)
C:\Program Files (x86)\arduino-0019\libraries\String\WString.cpp:159: error: prototype for 'const String& String::operator+=(long int)' does not match any in class 'String'
C:\Program Files (x86)\arduino-0019\hardware\arduino\cores\arduino/WString.h:44: error: candidate is: const String& String::operator+=(const String&)
C:\Program Files (x86)\arduino-0019\libraries\String\WString.cpp: In member function 'const String& String::operator+=(const String&)':
C:\Program Files (x86)\arduino-0019\libraries\String\WString.cpp:176: error: '_array' was not declared in this scope
C:\Program Files (x86)\arduino-0019\libraries\String\WString.cpp:179: error: 'setArray' was not declared in this scope
C:\Program Files (x86)\arduino-0019\libraries\String\WString.cpp:183: error: '_array' was not declared in this scope
C:\Program Files (x86)\arduino-0019\libraries\String\WString.cpp:183: error: 'const class String' has no member named '_array'
C:\Program Files (x86)\arduino-0019\libraries\String\WString.cpp: At global scope:
C:\Program Files (x86)\arduino-0019\libraries\String\WString.cpp:191: error: no 'const String& String::append(char)' member function declared in class 'String'
C:\Program Files (x86)\arduino-0019\libraries\String\WString.cpp:196: error: no 'const String& String::append(char*)' member function declared in class 'String'
C:\Program Files (x86)\arduino-0019\libraries\String\WString.cpp:201: error: no 'const String& String::append(const String&)' member function declared in class 'String'
C:\Program Files (x86)\arduino-0019\libraries\String\WString.cpp:206: error: no 'const String& String::append(int, int)' member function declared in class 'String'
C:\Program Files (x86)\arduino-0019\libraries\String\WString.cpp:217: error: no 'const String& String::append(long int, int)' member function declared in class 'String'
C:\Program Files (x86)\arduino-0019\libraries\String\WString.cpp:226: error: no 'const String& String::append(int)' member function declared in class 'String'
C:\Program Files (x86)\arduino-0019\libraries\String\WString.cpp:234: error: no 'const String& String::append(long int)' member function declared in class 'String'
C:\Program Files (x86)\arduino-0019\libraries\String\WString.cpp:323: error: prototype for 'char String::charAt(int)' does not match any in class 'String'
C:\Program Files (x86)\arduino-0019\hardware\arduino\cores\arduino/WString.h:57: error: candidate is: char String::charAt(unsigned int) const
C:\Program Files (x86)\arduino-0019\libraries\String\WString.cpp:339: error: prototype for 'void String::setCharAt(int, char)' does not match any in class 'String'
C:\Program Files (x86)\arduino-0019\hardware\arduino\cores\arduino/WString.h:71: error: candidate is: void String::setCharAt(unsigned int, char)
C:\Program Files (x86)\arduino-0019\libraries\String\WString.cpp:355: error: prototype for 'boolean String::equals(char*)' does not match any in class 'String'
C:\Program Files (x86)\arduino-0019\hardware\arduino\cores\arduino/WString.h:60: error: candidate is: unsigned char String::equals(const String&) const
C:\Program Files (x86)\arduino-0019\libraries\String\WString.cpp:366: error: prototype for 'boolean String::equals(const String&)' does not match any in class 'String'
C:\Program Files (x86)\arduino-0019\hardware\arduino\cores\arduino/WString.h:60: error: candidate is: unsigned char String::equals(const String&) const
C:\Program Files (x86)\arduino-0019\libraries\String\WString.cpp:372: error: no 'boolean String::contains(char*)' member function declared in class 'String'
C:\Program Files (x86)\arduino-0019\libraries\String\WString.cpp:380: error: prototype for 'byte* String::getBytes()' does not match any in class 'String'
C:\Program Files (x86)\arduino-0019\hardware\arduino\cores\arduino/WString.h:79: error: candidate is: void String::getBytes(unsigned char*, unsigned int)
C:\Program Files (x86)\arduino-0019\libraries\String\WString.cpp:386: error: no 'void String::setArray(const char*)' member function declared in class 'String'
C:\Program Files (x86)\arduino-0019\libraries\String\WString.cpp:396: error: prototype for 'int String::indexOf(int)' does not match any in class 'String'
C:\Program Files (x86)\arduino-0019\hardware\arduino\cores\arduino/WString.h:65: error: candidates are: int String::indexOf(const String&, unsigned int) const
C:\Program Files (x86)\arduino-0019\hardware\arduino\cores\arduino/WString.h:64: error:                 int String::indexOf(const String&) const
C:\Program Files (x86)\arduino-0019\hardware\arduino\cores\arduino/WString.h:63: error:                 int String::indexOf(char, unsigned int) const
C:\Program Files (x86)\arduino-0019\hardware\arduino\cores\arduino/WString.h:62: error:                 int String::indexOf(char) const
C:\Program Files (x86)\arduino-0019\libraries\String\WString.cpp:402: error: prototype for 'int String::indexOf(const String&)' does not match any in class 'String'
C:\Program Files (x86)\arduino-0019\hardware\arduino\cores\arduino/WString.h:65: error: candidates are: int String::indexOf(const String&, unsigned int) const
C:\Program Files (x86)\arduino-0019\hardware\arduino\cores\arduino/WString.h:64: error:                 int String::indexOf(const String&) const
C:\P
« Last Edit: September 10, 2010, 02:44:24 pm by Delfairen » Logged

0
Offline Offline
Tesla Member
***
Karma: 145
Posts: 9634
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Below is some code I made for testing. I added the if contains function to find if a string contains "woohoo". You can send strings containing woohoo using the serial monitor to see if it is found in the string.

Code:
//zoomkat 9-9-10 simple delimited ',' string parce
//from serial port input (via serial monitor)
//and print result out serial port
// CR/LF could also be a delimiter
// http://www.arduino.cc/en/Tutorial/TextString for WString.h

#include <WString.h> //provides easy string handling
String readString = String(100);

void setup() {
      Serial.begin(9600);
        }

void loop() {

        //expect a string like wer,qwe rty,123 456,hyre kjhg,
        //or like hello world,who are you?,bye!,
        while (Serial.available()) {
        delay(10);  //small delay to allow input buffer to fill
          if (Serial.available() >0) {
        char c = Serial.read();  //gets one byte from serial buffer
        if (c == ',') {break;}  //breaks out of capture loop to print readstring
        readString.append(c); } //makes the string readString
        }
      
      if (readString.length() >0) {
      Serial.println(readString); //prints string to serial port out
      
         if(readString.contains("woohoo")) {
         Serial.println("I found woohoo!"); }
      
      readString=""; //clears variable for new input
      }
   }

Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

0
Offline Offline
Newbie
*
Karma: 0
Posts: 14
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Where do you get wstring. the textstring page now contains string not wstring.
Logged

0
Offline Offline
Tesla Member
***
Karma: 145
Posts: 9634
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Where do you get wstring. the textstring page now contains string not wstring.

Wstring is inside the string.zip file you download from the textstring page.
Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

0
Offline Offline
Newbie
*
Karma: 0
Posts: 14
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I download string.zip again and it contains a folder called string with the wstring.h and wstring.cpp in it. If I include wstring.h as per your example it errors out with

C:\Program Files (x86)\arduino-0019\libraries\String\WString.cpp:34: error: prototype for 'String::String(int)' does not match any in class 'String'
C:\Program Files (x86)\arduino-0019\hardware\arduino\cores\arduino/WString.h:39: error: candidates are: String::String(long unsigned int, int)
C:\Program Files (x86)\arduino-0019\hardware\arduino\cores\arduino/WString.h:38: error:                 String::String(long int, int)
C:\Program Files (x86)\arduino-0019\hardware\arduino\cores\arduino/WString.h:37: error:                 String::String(unsigned int, int)
C:\Program Files (x86)\arduino-0019\hardware\arduino\cores\arduino/WString.h:36: error:                 String::String(int, int)
C:\Program Files (x86)\arduino-0019\hardware\arduino\cores\arduino/WString.h:35: error:                 String::String(unsigned char)
C:\Program Files (x86)\arduino-0019\hardware\arduino\cores\arduino/WString.h:34: error:                 String::String(char)
C:\Program Files (x86)\arduino-0019\hardware\arduino\cores\arduino/WString.h:33: error:                 String::String(const String&)
C:\Program Files (x86)\arduino-0019\hardware\arduino\cores\arduino/WString.h:32: error:                 String::String(const char*)
C:\Program Files (x86)\arduino-0019\libraries\String\WString.cpp: In constructor 'String::String(const char*)':
C:\Program Files (x86)\arduino-0019\libraries\String\WString.cpp:50: error: '_array' was not declared in this scope
C:\Program Files (x86)\arduino-0019\libraries\String\WString.cpp:52: error: 'setArray' was not declared in this scope
C:\Program Files (x86)\arduino-0019\libraries\String\WString.cpp: In copy constructor 'String::String(const String&)':
C:\Program Files (x86)\arduino-0019\libraries\String\WString.cpp:60: error: '_array' was not declared in this scope
C:\Program Files (x86)\arduino-0019\libraries\String\WString.cpp:61: error: 'clear' was not declared in this scope
C:\Program Files (x86)\arduino-0019\libraries\String\WString.cpp:62: error: 'const class String' has no member named '_array'
C:\Program Files (x86)\arduino-0019\libraries\String\WString.cpp:62: error: 'setArray' was not declared in this scope
C:\Program Files (x86)\arduino-0019\libraries\String\WString.cpp: In member function 'const String& String::operator=(const String&)':
C:\Program Files (x86)\arduino-0019\libraries\String\WString.cpp:77: error: '_array' was not declared in this scope
C:\Program Files (x86)\arduino-0019\libraries\String\WString.cpp:83: error: 'clear' was not declared in this scope
C:\Program Files (x86)\arduino-0019\libraries\String\WString.cpp:84: error: 'const class String' has no member named '_array'
C:\Program Files (x86)\arduino-0019\libraries\String\WString.cpp:84: error: 'setArray' was not declared in this scope
C:\Program Files (x86)\arduino-0019\libraries\String\WString.cpp: At global scope:
C:\Program Files (x86)\arduino-0019\libraries\String\WString.cpp:90: error: prototype for 'const String& String::operator=(const char*)' does not match any in class 'String'
C:\Program Files (x86)\arduino-0019\libraries\String\WString.cpp:70: error: candidate is: const String& String::operator=(const String&)
C:\Program Files (x86)\arduino-0019\libraries\String\WString.cpp:107: error: prototype for 'const String& String::operator+=(const char*)' does not match any in class 'String'
C:\Program Files (x86)\arduino-0019\hardware\arduino\cores\arduino/WString.h:44: error: candidate is: const String& String::operator+=(const String&)
C:\Program Files (x86)\arduino-0019\libraries\String\WString.cpp:127: error: prototype for 'const String& String::operator+=(char)' does not match any in class 'String'
C:\Program Files (x86)\arduino-0019\hardware\arduino\cores\arduino/WString.h:44: error: candidate is: const String& String::operator+=(const String&)
C:\Program Files (x86)\arduino-0019\libraries\String\WString.cpp:145: error: prototype for 'const String& String::operator+=(int)' does not match any in class 'String'
C:\Program Files (x86)\arduino-0019\hardware\arduino\cores\arduino/WString.h:44: error: candidate is: const String& String::operator+=(const String&)
C:\Program Files (x86)\arduino-0019\libraries\String\WString.cpp:159: error: prototype for 'const String& String::operator+=(long int)' does not match any in class 'String'
C:\Program Files (x86)\arduino-0019\hardware\arduino\cores\arduino/WString.h:44: error: candidate is: const String& String::operator+=(const String&)
C:\Program Files (x86)\arduino-0019\libraries\String\WString.cpp: In member function 'const String& String::operator+=(const String&)':
C:\Program Files (x86)\arduino-0019\libraries\String\WString.cpp:176: error: '_array' was not declared in this scope
C:\Program Files (x86)\arduino-0019\libraries\String\WString.cpp:179: error: 'setArray' was not declared in this scope
C:\Program Files (x86)\arduino-0019\libraries\String\WString.cpp:183: error: '_array' was not declared in this scope
C:\Program Files (x86)\arduino-0019\libraries\String\WString.cpp:183: error: 'const class String' has no member named '_array'
C:\Program Files (x86)\arduino-0019\libraries\String\WString.cpp: At global scope:
C:\Program Files (x86)\arduino-0019\libraries\String\WString.cpp:191: error: no 'const String& String::append(char)' member function declared in class 'String'
C:\Program Files (x86)\arduino-0019\libraries\String\WString.cpp:196: error: no 'const String& String::append(char*)' member function declared in class 'String'
C:\Program Files (x86)\arduino-0019\libraries\String\WString.cpp:201: error: no 'const String& String::append(const String&)' member function declared in class 'String'
C:\Program Files (x86)\arduino-0019\libraries\String\WString.cpp:206: error: no 'const String& String::append(int, int)' member function declared in class 'String'
C:\Program Files (x86)\arduino-0019\libraries\String\WString.cpp:217: error: no 'const String& String::append(long int, int)' member function declared in class 'String'
C:\Program Files (x86)\arduino-0019\libraries\String\WString.cpp:226: error: no 'const String& String::append(int)' member function declared in class 'String'
C:\Program Files (x86)\arduino-0019\libraries\String\WString.cpp:234: error: no 'const String& String::append(long int)' member function declared in class 'String'
C:\Program Files (x86)\arduino-0019\libraries\String\WString.cpp:323: error: prototype for 'char String::charAt(int)' does not match any in class 'String'
C:\Program Files (x86)\arduino-0019\hardware\arduino\cores\arduino/WString.h:57: error: candidate is: char String::charAt(unsigned int) const
C:\Program Files (x86)\arduino-0019\libraries\String\WString.cpp:339: error: prototype for 'void String::setCharAt(int, char)' does not match any in class 'String'
C:\Program Files (x86)\arduino-0019\hardware\arduino\cores\arduino/WString.h:71: error: candidate is: void String::setCharAt(unsigned int, char)
C:\Program Files (x86)\arduino-0019\libraries\String\WString.cpp:355: error: prototype for 'boolean String::equals(char*)' does not match any in class 'String'
C:\Program Files (x86)\arduino-0019\hardware\arduino\cores\arduino/WString.h:60: error: candidate is: unsigned char String::equals(const String&) const
C:\Program Files (x86)\arduino-0019\libraries\String\WString.cpp:366: error: prototype for 'boolean String::equals(const String&)' does not match any in class 'String'
C:\Program Files (x86)\arduino-0019\hardware\arduino\cores\arduino/WString.h:60: error: candidate is: unsigned char String::equals(const String&) const
C:\Program Files (x86)\arduino-0019\libraries\String\WString.cpp:372: error: no 'boolean String::contains(char*)' member function declared in class 'String'
C:\Program Files (x86)\arduino-0019\libraries\String\WString.cpp:380: error: prototype for 'byte* String::getBytes()' does not match any in class 'String'
C:\Program Files (x86)\arduino-0019\hardware\arduino\cores\arduino/WString.h:79: error: candidate is: void String::getBytes(unsigned char*, unsigned int)
C:\Program Files (x86)\arduino-0019\libraries\String\WString.cpp:386: error: no 'void String::setArray(const char*)' member function declared in class 'String'
C:\Program Files (x86)\arduino-0019\libraries\String\WString.cpp:396: error: prototype for 'int String::indexOf(int)' does not match any in class 'String'
C:\Program Files (x86)\arduino-0019\hardware\arduino\cores\arduino/WString.h:65: error: candidates are: int String::indexOf(const String&, unsigned int) const
C:\Program Files (x86)\arduino-0019\hardware\arduino\cores\arduino/WString.h:64: error:                 int String::indexOf(const String&) const
C:\Program Files (x86)\arduino-0019\hardware\arduino\cores\arduino/WString.h:63: error:                 int String::indexOf(char, unsigned int) const
C:\Program Files (x86)\arduino-0019\hardware\arduino\cores\arduino/WString.h:62: error:                 int String::indexOf(char) const
C:\Program Files (x86)\arduino-0019\libraries\String\WString.cpp:402: error: prototype for 'int String::indexOf(const String&)' does not match any in class 'String'
C:\Program Files (x86)\arduino-0019\hardware\arduino\cores\arduino/WString.h:65: error: candidates are: int String::indexOf(const String&, unsigned int) const
C:\Program Files (x86)\arduino-0019\hardware\arduino\cores\arduino/WString.h:64: error:              
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 14
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

wstring seems to work in arduino 18 but not arduino 19
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 14
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
#include <WString.h>
#include <NewSoftSerial.h>

//#define enable_code "3E0018105F69 "  //change this ID with your own card TAG
//#define disable_code "3E00187E97CF "

NewSoftSerial RFID(2, 3);
String msg = String(60);
String ID = String(60); //string to store allowed cards
char c;

void setup()  
{
  Serial.begin(9600);
  Serial.println("Serial Ready");

  RFID.begin(9600);
  Serial.println("RFID Ready");
}

void loop()
{
  while(RFID.available()>0)
  {
    c=RFID.read();
    msg += c;
    Serial.println(msg);  //Uncomment to view your tag ID
  }
  if(msg.contains("E0018105F69")) add();
  if(msg.contains("E00187E97CF")) del();  
  if(msg.length()>10) verifica();
  msg="";
}

void add()
{
  Serial.print("What TAG do you wanna grant access?: ");
  msg="";
  while(msg.length()<13)
  {
    while(RFID.available()>0)
    {
      c=RFID.read();
      msg += c;
    }
  }
  if(ID == msg)
  {
    Serial.println("\nAccess already granted for this card.");
    msg="";
  }
  else
  {
    Serial.print("Card: ");
    Serial.println(msg);
    ID += msg;
    ID += ",";
    Serial.print("ID: ");
    Serial.println(ID);
    msg="";
    Serial.println("Access granted for this card.");
  }
}

void del()
{
  msg="";
  Serial.print("What TAG do you wanna deny access?: ");
  while(msg.length()<13)
  {
    while(RFID.available()>0)
    {
      c=RFID.read();
      msg += c;
    }
  }
  if(ID == msg)
  {
    Serial.println(msg);
    Serial.println("TAG found. Access for this card denied.");
    //ID.replace(card,"");
    int pos=ID.indexOf(msg);
    msg="";
    msg += (ID.substring(0,pos));
    msg += (ID.substring(pos+15,ID.length()));
    ID="";
    ID += msg;
    //Serial.print("ID: ");
    //Serial.println(ID);
  } else Serial.println("\nTAG not found or already denied");
  msg="";
}

void verifica()
{
    if(ID == msg) Serial.println("Access granted.");
    else Serial.println("Access denied.");
}

Works in arduino 18. I guess I'll carry on looking at 19 and try and figure out why the wstring library doesn't work although I see they added the string class in 19

http://arduino.cc/en/Main/ReleaseNotes
Logged

0
Offline Offline
Tesla Member
***
Karma: 145
Posts: 9634
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
wstring seems to work in arduino 18 but not arduino 19

From what I've read, version 19 has string handling, but good code examples aren't really available yet. 19 also apparently changes something such that an additional library is needed when using the ethernet library, which just increases some overhead for me.  
Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

Pages: [1] 2   Go Up
Jump to: