I am looking to turn on an LED if "bob" returned and better yet find a way to tie in the status of online to bob.
i guess i'm really just looking for some direction, maybe a link that shows me how to manipulate data coming into the serial monitor.
if that's even possible
This is the code i’m using, is the data coming through my usb cable or through the ethernet?
i assumed it was coming from the ethernet, but i guess i could be wrong.
//zoomkat 11-13-10
//simple ethernet client test code
//for use with IDE 0021 and W5100 ethernet shield
//modify the arduino lan ip address as needed
//open serial monitor to see what the arduino receives
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192, 168, 1, 100 };
byte server[] = { 65, 23, 97, 190 }; // zoomkat
Client client(server, 80);
void setup()
{
Ethernet.begin(mac, ip);
Serial.begin(9600);
Serial.println("starting simple arduino client test");
Serial.println();
delay(1000);
Serial.println("connecting...");
if (client.connect()) {
Serial.println("connected");
client.println("GET http://server.net/serverpage.asp");
client.println();
} else {
Serial.println("connection failed");
}
}
void loop()
{
if (client.available()) {
char c = client.read();
String stringOne = c;
Serial.print(stringOne);
}
if (!client.connected()) {
Serial.println();
Serial.println("disconnecting.");
client.stop();
for(;;);
}
}
Any Serial.print function call writes data over the USB connection to your computer (I'm assuming you have your Arduino plugged in to your computer and no other device connected to the UART).
Any client.print function call writes data through SPI to the ethernet shield which sends the data over the ethernet connection.
Ok, it looks like i may need to take a step back then?
I'm trying to have a LED turn on if a certain value is returned from the page.
Do i need to handle the data in a different way?
i know i don't have to print it but could i run a condition off of the "stringOne" variable to turn on a LED?
if not, i need to find out how to access the data coming back from the page
if (client.available()) {
char c = client.read();
String stringOne = c;
Serial.print(stringOne);
}
All that this is going to do is print the incoming ethernet data out to your serial monitor. Yes, you can do a condition check on that incoming data, which is probably what you want to do.
Keep in mind though that if you're crafting a new String object from just one character, you can probably just keep the datatype as a "char" and save your program time and memory by omitting the String object.
If you want to build up a longer String, which is a perfectly reasonable thing to do, then declare a String outside of setup() and loop()
Try casting client.read() to a char? If that fails, cast to a const char?
What you’re getting are the ASCII values of certain characters. You can check an ASCII table to see just what that data is, although figuring out how to get your string to know that it should append character data instead of number data is probably a better use of your time.
Wait, what happened to the code I wrote? Lol, that would have worked for you!
The important bits are: declare your String outside setup() and loop(), and concatenate to your String rather than just setting it (use += instead of =).
Here's that code again, with a cast to "const char" - hopefully the compiler will know you want to add character data instead of numbers this way.
I understand why it is writing it one char at a time, because i’m doing the output in the loop but what i don’t get is when i output the variable outside the loop all i get is a bunch of blanks. (non stop, it seems)
i’m pretty sure this is the only thing getting returned from the page.
(
T
h
e
c
a
u
s
e
)
X
t
r
e
m
e
b
u
b
b
a
:
i
n
-
g
a
m
e
<
b
r
>
c
h
a
z
z
y
1
8
6
4
:
i
n
-
g
a
m
e
<
b
r
>
2
In this case, the variable incoming is defined inside the loop. Because of variable scope, the variable "no longer exists" once the program leaves the scope it was defined in (which is the "if" block in this case).
Ok, so if i understand you correctly that if statement should work the first time around?(if my output was “turn on LED”) if so shouldn’t i still be able to output the “incoming” variable once before it gets overwritten? nevermind, i think i understand that part
Example of using indexOf string function to check for a substring in readString.
if(readString.indexOf("on") >0)//checks for on
{
digitalWrite(4, HIGH); // set pin 4 high
Serial.println("Led On");
}
if(readString.indexOf("off") >0)//checks for off
{
digitalWrite(4, LOW); // set pin 4 low
Serial.println("Led Off");
}
At some point you gotta just dig in, read the tutorials, read the docs, and read auxiliary articles pertaining to your issue. If your issue is that you don't know how to program in C/C++, read beginners C/C++ articles.
At some point you gotta just dig in, read the tutorials, read the docs, and read auxiliary articles pertaining to your issue. If your issue is that you don't know how to program in C/C++, read beginners C/C++ articles.
At some point, you have to understand that you can not destroy the hardware by loading a sketch on it and trying to run it. Personal observation is much more useful than asking questions like that last one on the forum.