Mod edit:
@zxcore every time you post VB .NET (no space) the forum software creates a link to an online shop with that domain name. This makes your post seem like spam. After a lot of consideration I decided that you are not intentionally posting spam. I have gone through your posts and edited each instance of VB .NET to remove the link. Please in future type it with a space.
Thank you.
Needing some Assistance on getting my if-Else if Seeing my Buffers, below is my Code i have, and the screenshot depict the VB .NET application i have written to send the Arduino Numbers i have defined f1 f2 f3 f4 and it is never printing the lines Serial.println("xx received via UDP!"); for various numbers. i only get packetBuffer = 24 anyone help me out. Thanks so much
#include <Ethernet.h>
//DEFINITIONS-----------------------------------------
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; //mac adress
IPAddress ip(192, 168, 111, 231); //ip address
unsigned int localPort = 8888; //udp port to listen for packets on
char packetBuffer[UDP_TX_PACKET_MAX_SIZE];
EthernetUDP Udp; //creates Udp instance
char f1 = 10; //char to compare packetBuffer to
char f2 = 44; //char to compare packetBuffer to
char f3 = 60; //char to compare packetBuffer to
char f4 = 24; //char to compare packetBuffer to
void setup() {
Ethernet.init(10); //sets CS pin for ethernet shield
Ethernet.begin(mac, ip); //initializes ethernet with mac and ip addresses
Serial.begin(9600); //initializes serial connection. Waits for serial to be available (native usb only).
while (!Serial) {
;
}
//Checks for presence of Ethernet shield. Halts if no ethernet hardware present.
if (Ethernet.hardwareStatus() == EthernetNoHardware) {
Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :(");
while (true) {
delay(1);
}
}
//Checks for presence of etherner link.Halts if no link present.
if (Ethernet.linkStatus() == LinkOFF) {
Serial.println("Ethernet cable is not connected.");
}
Udp.begin(localPort); //begins udp on port specified above.
}
void loop() {
int packetSize = Udp.parsePacket();
if (packetSize) { //if data available, prints following;
Serial.println("----------------------------------------------");
Serial.print("Received packet of size ");
Serial.println(packetSize);
Serial.print("From ");
IPAddress remote = Udp.remoteIP();
for (int i = 0; i < 4; i++) {
Serial.print(remote[i], DEC);
if (i < 3) {
Serial.print(".");
}
}
Serial.print(", port ");
Serial.println(Udp.remotePort());
Udp.read(packetBuffer, UDP_TX_PACKET_MAX_SIZE);
Serial.print("packetBuffer = ");
Serial.println(packetBuffer);
if (packetBuffer[0] == f1) {
Serial.println("Contents:"); //10
Serial.println("10 received via UDP!");
} else if(packetBuffer[0] == f2) {
Serial.println("Contents"); //44
Serial.println("44 received via UDP!");
} else if (packetBuffer[0] == f3) {
Serial.println("Contents"); //60
Serial.println("60 received via UDP!");
} else if (packetBuffer[0] == f4) {
Serial.println("Contents"); //24
Serial.println("24 received via UDP!");
} else {
if (packetBuffer[0] == f3) {
Serial.println("Contents"); //60
Serial.println("60 received via UDP!");// Serial.println("SOMETHING WENT WRONG");
}
Serial.println("----------------------------------------------");
Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
Udp.write("acknowledged", 13);
Udp.flush();
Udp.endPacket();
}
}
}