Need help to create client. Using arduino Ethernetshield and UDP

Hello. I have some code here, that store the Digitalread value of a switch I have hooked up. I need some help with the client. Any suggestion on how I can get the value from the server and to the Client? I have tried to make a python script, and I think It work, but I cannot acutally see if the Switch has been pressed or not. When you want to send the information digitalRead capture, what Is it? A string? Look at my code, and maybe you get what I want. This is the server side:

#include <Ethernet.h> //Load Ethernet Library
#include <EthernetUdp.h> //Load the Udp Library
#include <SPI.h> //Load SPI Library

#include "Wire.h" //imports the wire library

int Switch;

byte mac[] ={ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xEE}; //Assign mac address
IPAddress ip(10, 0, 0, 13); //Assign the IP Adress
unsigned int localPort = 100; // Assign a port to talk over
char packetBuffer[UDP_TX_PACKET_MAX_SIZE]; //dimensian a char array to hold our data packet
String datReq; //String for our data
int packetSize; //Size of the packet
EthernetUDP Udp; // Create a UDP Object

void setup() {
  Serial.begin(9600); //Initialize Serial Port 
  Ethernet.begin( mac, ip); //Inialize the Ethernet
  Udp.begin(localPort); //Initialize Udp
  delay(1500); //delay
  pinMode(3, INPUT);


void loop() {
  packetSize =Udp.parsePacket(); //Reads the packet size

  if(packetSize>0) { //if packetSize is >0, that means someone has sent a request, UDP_TX_PACKET_MAX_SIZE); //Read the data request
    String datReq(packetBuffer); //Convert char array packetBuffer into a string called datReq
    if (datReq =="Switch") { //Do the following if Switch is requested
      Switch = digitalRead(3); //Read the switch statement

      Udp.beginPacket(Udp.remoteIP(), Udp.remotePort()); //Initialize packet send
      Udp.print(Switch); //Send the Switch data
      Udp.endPacket(); //End the packet

  memset(packetBuffer, 0, UDP_TX_PACKET_MAX_SIZE); //clear out the packetBuffer array

The Switch variable is an integer converted to a string. That is what you are sending. The packet should contain the integer value converted to a string. It should be a '1' or '0'.

edit: I have UDP "client" C code for a Linux (Ubuntu) box.

So on the server side, what should I change? Can you show with some code, then I understand it better? :slight_smile: Thanks!

No change on the Arduino side if a text 1 or 0 is what you want to send.

Yes, I want to send 1 when the switch is pressed and 0 when the button is not pressed. But I need some help in the client, to ask for the switch statement. Is the switch a 0 or 1? And then print this information in the client. I need some code help with that If you have some extra time? If you can help me out, I can pay you 50 $ If I get this to work? :slight_smile:

I have a little extra time. What language and operating system are you using?