I have two Arduino UNOs with Ethernet shields and I am attempting to send a token from one to the other.
Both seem to initialize fine in setup.
But whenever I send a packet, I get an error occuring during the write function.
I’ve listed and attached both sketches. The “…console” sketch never sees a “packetsize” greater than zero.
I am sure it is something simple, but I’ve spent weeks debugging this problem…
Any ideas?
// sends a message first
#include <SPI.h>
#include <Ethernet.h>
// #include <EthernetUdp2.h>#define localID 10 // local
#define remoteID 20 // remote
#define localPORT 8888 // Port
#define EthMegPin 53
#define debugDelay 2500
#define Halt while(true)
#define Forever while(true)
#define aWait 2000// define UDP object
EthernetUDP sendUdp;char UDPRecvBuffer[UDP_TX_PACKET_MAX_SIZE];
char UDPSendBuffer = “ack”;
byte mac = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, localID };IPAddress local_IP(10, 1, 1, localID);
IPAddress remote_IP(10, 1, 1, remoteID);
int packetSize;
byte localScriptToken = 0;
int remote_message = 100;void setup() {
Serial.begin(9600);pinMode(EthMegPin, OUTPUT);
digitalWrite(EthMegPin, HIGH);
// Ethernet.init(10); // Most Arduino shields// localID read in setup
// mac[5] = localID;
// local_IP[3] = localID;
// remote_IP[3] = remoteID;
for (int i = 0; i < 4; i++) {
Serial.print(local_IP*);*
- if (i < 3) Serial.print(", ");*
- }; Serial.println(" <-local");*
- IPAddress remote_IP(10, 1, 1, remoteID);*
- for (int i = 0; i < 4; i++) {*
Serial.print(remote_IP*);
_ if (i < 3) Serial.print(", “);_
_ }; Serial.println(” <-remote");_
_ Serial.println();_
Ethernet.begin(mac, local_IP);
_ // Check for Ethernet hardware present*_
* if (Ethernet.hardwareStatus() == EthernetNoHardware) {*
* Serial.println(“Setup: Ethernet shield was not found. Sorry, can’t run without hardware. :(”);*
* Halt;*
* } else {*
* Serial.println(“Setup: Found Ethernet Shield”);*
* }*
* if (Ethernet.linkStatus() == LinkOFF) {*
* Serial.println(“Setup: Ethernet cable is not connected.”);*
* Halt;*
* } else {*
* Serial.println(“Setup: Cable connected”);*
* }*
* int Udp_Conn = sendUdp.begin(localPORT);
if (Udp_Conn) {
_ Serial.print(“Setup: UDP port connection successful to “);_
_ Serial.println(localPORT);_
_ }_
_ else {_
_ Serial.print(“Setup: UDP port connection failed to “);_
_ Serial.println(localPORT);_
_ Halt;_
_ }_
_ Serial.println();_
_}_
void loop() {
// int UdpConn = sendUdp.beginPacket(remote_IP, sendUdp.remotePort());
int UdpConn = sendUdp.beginPacket(remote_IP, localPORT);
_ for (int i = 0; i < 4; i++) {_
Serial.print(remote_IP);
_ if (i < 3) Serial.print(”, “);
}; Serial.print(”:”);
Serial.print(localPORT);
Serial.println(”: <-remote”);
if (UdpConn) {
Serial.println(“Loop: Begin packet successful”);
}
else {_
Serial.println(“Loop: UDP packet begin failed. Host not found");*
* for (int i = 0; i < 4; i++) {_
Serial.print(local_IP);
_ if (i < 3) Serial.print(”, “);
}; Serial.println(” <-local");
for (int i = 0; i < 4; i++) {_
Serial.print(remote_IP);
_ if (i < 3) Serial.print(", “);
}; Serial.println(” <-remote");
}_
remote_message ++;
itoa(remote_message, UDPSendBuffer, 10);
_ int charsSent = sendUdp.write(UDPSendBuffer);
// delay(debugDelay);
delay(100);
Serial.print(charsSent);
Serial.println(" characters sent");
int UdpSent = sendUdp.endPacket();
if (UdpSent) {
Serial.println(“Loop: Message sent via UDP”);
}
else {
Serial.print(“Loop: Error occurred during write [”);
Serial.print(UdpSent);
Serial.println("]");
}
delay(aWait);
Halt;
}[/quote]
Something went wrong.
Trying to correct listing
of Receive sketch. The
attachment is good.
Until then…_
TII-Interact_commsTest_Send.ino (3.3 KB)
TII-Interact_commsTest_Console.ino (2.61 KB)*