The code is supposed to take what it receives over Serial and send it to another ESP8266 via UDP. I get successful packet sends, but only ONCE. It ignores any further serial data.
int code, i, x;
char* codeChar;
#include <SPI.h> // needed for Arduino versions later than 0018
#include <Ethernet.h>
#include <EthernetUdp.h> // UDP library from: bjoern@cs.stanford.edu 12/30/2008
//#include <WiFi.h>
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
IPAddress ip(192, 168, 1, 139);
const char* ssid = "JMR";
const char* password = "crystal2965";
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
unsigned int localPort = 8888; // local port to listen on
// buffers for receiving and sending data
char packetBuffer[UDP_TX_PACKET_MAX_SIZE]; //buffer to hold incoming packet,
// An EthernetUDP instance to let us send and receive packets over UDP
EthernetUDP Udp;
void setup() {
// start the Ethernet and UDP:
Serial.begin(115200);
WiFi.mode(WIFI_STA);
WiFi.config(192, 168, 1, 137);
WiFi.begin(ssid, password);
Serial.println("");
// Wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("Node7b: Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
Udp.begin(localPort);
}
void loop() {
codeChar = "";
i = 0;
while (Serial.available()) {
codeChar[i] = Serial.read() ;
i++;
}
// send a reply, to the IP address and port that sent us the packet we received
x = Udp.beginPacket(ip, 8888);
if (x == 1) {
Serial.print("beginPacket status: Success ");
}
else {
Serial.print("beginPacket status: FAILURE ");
}
Serial.print("Sent: "); Serial.println(code);
Udp.write(codeChar);
x = Udp.endPacket();
if (x == 1) {
Serial.print("Packet Send status: Success ");
}
else {
Serial.print("Packet Send status: FAILURE ");
}
delay(100);
}
Here is the current code. I utizlized the Example 2 and pasted it making necessary changes. I may have a few issues but nothing that should stop the code cold.
It stops on x = Udp.endPacket();
Any reason why this would halt? The destination, btw, isn't there, but UDP unlike TCP doesn't wait for an acknowledgement. The thing although not continuing executing the code still replies to ICMP ECHO requests.