Sending data over UDP
Posted: Sun May 15, 2016 10:14 am
Hi, I am writing an application that will send data from the esp8266 to another device over wifi using a UDP connection, i.e. not through the internet or a router. Below is the part of the code (brought down to its simplest form) that deals with the connection. I am using AT commands on the Arduino UNO. The blue light flashes on the esp8266 and I am able to connect to the other device (iPad) but I can't seem to be able to send my data. I might (most likely) be missing something very basic in the code but before I throw the whole thing through the window, can someone point me in the right direction? Thank you.
[code]
#include "SoftwareSerial.h"
SoftwareSerial esp8266(5,6);
void setup() {
Serial.begin(38400, SERIAL_8N1);
esp8266.begin(38400);
esp8266.println("AT+RST\r\n");
delay(1000);
esp8266.println("AT+CIPCLOSE\r\n");
esp8266.println("AT+CIPMUX=0\r\n");
esp8266.println("AT+CWMODE=3\r\n");
String udpmode = "AT+CIPSTART=";
udpmode+="4,",
udpmode+= "UDP";
udpmode+=",";
udpmode+="196.168.4.1";
udpmode+=",10110,1001,0";
esp8266.println("udpmode\r\n");
esp8266.println("AT+CIPMODE=1\r\n");
}
void loop() {
// Send data;
String mydata = "123456";// Real data is variable. Needed because mydata contains periods and special characters
esp8266.println("AT+CIPSEND=6\r\n");
delay (2000);
esp8266.println("mydata\r\n");
delay(2000);
Serial.println(mydata);// So that I can see the data flowing on the serial monitor
}
// End of code
[code]
#include "SoftwareSerial.h"
SoftwareSerial esp8266(5,6);
void setup() {
Serial.begin(38400, SERIAL_8N1);
esp8266.begin(38400);
esp8266.println("AT+RST\r\n");
delay(1000);
esp8266.println("AT+CIPCLOSE\r\n");
esp8266.println("AT+CIPMUX=0\r\n");
esp8266.println("AT+CWMODE=3\r\n");
String udpmode = "AT+CIPSTART=";
udpmode+="4,",
udpmode+= "UDP";
udpmode+=",";
udpmode+="196.168.4.1";
udpmode+=",10110,1001,0";
esp8266.println("udpmode\r\n");
esp8266.println("AT+CIPMODE=1\r\n");
}
void loop() {
// Send data;
String mydata = "123456";// Real data is variable. Needed because mydata contains periods and special characters
esp8266.println("AT+CIPSEND=6\r\n");
delay (2000);
esp8266.println("mydata\r\n");
delay(2000);
Serial.println(mydata);// So that I can see the data flowing on the serial monitor
}
// End of code