Hey everyone, im a bit of a noob when it comes to programming so id love some help! ![]()
I have successfully made my mini tcp server on my computer to input the text that i type for it to appear in my arduino serial, but now what i want to do is when my arduino receives a certain piece of text lets say "hello" for it to turn a pin on or off on the arduino.
Here is my text so far, i just need some command and programming guidance in what to type. Thanks ! <3
#include <SPI.h>
#include <Ethernet.h>
int led = 13;
// 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 };
IPAddress serverIP(192,168,1,100); // IP Adress to our Server
int serverPort=8888;
// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to
EthernetClient client;
void setup() {
pinMode(led, OUTPUT);
Serial.begin(9600);
// 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:
for(;;)
;
}
// give the Ethernet shield a second to initialize:
delay(1000);
Serial.println("connecting to Server ...");
// if you get a connection to the Server
if (client.connect(serverIP, serverPort)) {
Serial.println("connected");//report it to the Serial
String msg="Hello Server";//Message to be sent
Serial.println("sending Message:"+msg);//log to serial
client.println(msg);//send the message
}
else {
// if you didn't get a connection to the server:
Serial.println("connection failed");
}
}
void loop()
{
// if there are incoming bytes available
// from the server, read them and print them:
if (client.available()) {
char c = client.read();
Serial.print(c);
}
if (client.available()) {
char x = client.read("x"); // This is where i think i need to write the commands, but as you can see the client.read("x") dosent work
}
// if the server's disconnected, stop the client:
if (!client.connected()) {
Serial.println();
Serial.println("disconnected");
client.stop();
// do nothing forevermore:
for(;;)
;
}
}