Hello All,
I just started playing around with the Ethernet Shield W5100 for Arduino.
I found an example for receiving TCP IP information. I am using VVVV TCP Client for sending data.
Question 1:
I am not sure why or if this is needed, but it seems the example is setting a client = server.available().
Does this do anything or could server be used in the place of client everywhere in the example?
I'm just not sure if changing to an EthernetClient variable from an EthernetServer type has some benefit.
Question 2:
When I try to send data to the Arduino, it seems to take a long time to connect, and I am never sure when the connection has been made until the Serial.print starts showing.
Is there a way to know how long the connection should take or to verify that there is a connection before sending data that will be lost?
Question 3:
When I send a message ( example <255,000,100> ) I have the char array set to size 11 so it can get the RGB information. When this information prints, I randomly receive an extra character at the end of the message. I don't think this is coming from VVVV and I am not sure how the message can have 12 characters when the array is set to only hold 11.
#include <Ethernet.h>
byte mac[] = {0x54, 0x52, 0x49, 0x41, 0x44, 0x00};
byte ip[] = {192, 168, 2, 99};
byte gateway[] = {192, 168, 0, 1};
byte subnet[] = {255, 255, 0, 0};
EthernetServer server(4444);
EthernetClient client;
int sizeMessage = 11;
void setup() {
Serial.begin(9600);
Ethernet.begin(mac, ip, gateway, subnet);
server.begin();
client = server.available();
}
void loop() {
char inByte;
char message[sizeMessage];
int bytes;
while(!client){
client = server.available();
}
if(client.available()){
inByte = client.read();
if(inByte == '<'){
bytes = client.readBytesUntil('>', message, sizeMessage);
Serial.println(message);
//Serial.print("Number of Bytes = ");
//Serial.println(bytes);
}
}
}
Thank you all in advance for the help!
Let me know if you need anymore information.
Kind regards,
Jake