Hello!
I'm trying to modify a program to read a website and activate a pin if a message is found.
I'm having trouble with the comparison, and from looking around it seems it is stored as a pointer or something like that. How can I fix this?
#include <SPI.h>
#include <Ethernet.h>
boolean requested; // whether you've made a request since connecting
long lastAttemptTime = 0; // last time you connected to the server, in milliseconds
boolean garage_status = false;
String currentLine = ""; // string to hold the text from server
String tweet = ""; // string to hold the tweet
boolean readingTweet = false;
String out="";
// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
// if you don't want to use DNS (and reduce your sketch size)
// use the numeric IP instead of the name for the server:
//IPAddress server(74,125,232,128); // numeric IP for Google (no DNS)
char server[] = "gusat92.wix.com"; // name address for Google (using DNS)
// Set the static IP address to use if the DHCP fails to assign
IPAddress ip(10,32,153,88);
// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;
void setup() {
// Open serial communications and wait for port to open:
pinMode(2, OUTPUT);
Serial.begin(9600);
currentLine.reserve(256);
tweet.reserve(150);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
// start the Ethernet connection:
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
// no point in carrying on, so do nothing forevermore:
// try to congifure using IP address instead of DHCP:
Ethernet.begin(mac, ip);
}
// give the Ethernet shield a second to initialize:
delay(1000);
Serial.println("connecting...");
// if you get a connection, report back via serial:
if (client.connect(server, 80)) {
Serial.println("connected");
// Make a HTTP request:
client.println("GET /garage?_escaped_fragment_ HTTP/1.1");
client.println("Host: gusat92.wix.com");
client.println("Connection: close");
client.println();
}
else {
// kf you didn't get a connection to the server:
Serial.println("connection failed");
}
}
void loop()
{
if (client.connected()) {
if (client.available()) {
// read incoming bytes:
char inChar = client.read();
// add incoming byte to end of line:
currentLine += inChar;
// if you get a newline, clear the line:
if (inChar == '\n') {
currentLine = "";
}
// if the current line ends with <text>, it will
// be followed by the tweet:
if ( currentLine.endsWith("\"Text\">")) {
// tweet is beginning. Clear the tweet string:
readingTweet = true;
tweet = "";
}
// if you're currently reading the bytes of a tweet,
// add them to the tweet String:
if (readingTweet) {//
if (inChar != '&') {
String(tweet + inChar);
}
else {
// if you got a "<" character,
// you've reached the end of the tweet:
readingTweet = false;
Serial.println(tweet);
out=String(tweet);
Serial.println(tweet.length());
//if(strcmp(" <h2 class=\"font_2\">Opener", " <h2 class=\"font_2\">Opener")==0){
if(strcmp(out, out)==0){//PART GIVING ME TROUBLE
digitalWrite(2, HIGH);
delay(5000);
Serial.println("LED ON!");
garage_status=true;
digitalWrite(2, LOW);
}
else {Serial.println("no out");}
if(tweet != " <h2 class=\"font_2\">Closer" && garage_status==true){
digitalWrite(3, HIGH);
delay(5000);
Serial.println("LED OFF!");
garage_status=false;
digitalWrite(3, LOW);
}
// close the connection to the server:
client.stop();
}
}
}
}
}
It gives me this error message
sketch_nov24cr.ino: In function 'void loop()':
sketch_nov24cr:114: error: cannot convert 'String' to 'const char*' for argument '1' to 'int strcmp(const char*, const char*)'
Any help will be greatly appreciated!!!!!!