i cant receive udp but can't send with esp8266
Posted: Thu Aug 06, 2015 6:58 am
Hello,
i try to send data with my esp8266 with UDP protocol.
it say send ok but i receive no data on maxmsp on my other computer.
but i can send data with maxmsp and it work fine.
can anyone help please.
here is my code
i try to send data with my esp8266 with UDP protocol.
it say send ok but i receive no data on maxmsp on my other computer.
but i can send data with maxmsp and it work fine.
can anyone help please.
here is my code
Code: Select all
#include <SoftwareSerial.h>
SoftwareSerial ESP8266(10, 11);
String NomduReseauWifi = "myssid";
String MotDePasse = "mypassword";
/****************************************************************/
/* INIT */
/****************************************************************/
void setup()
{
Serial.begin(9600);
ESP8266.begin(9600);
initESP8266();
envoiTcp();
}
/****************************************************************/
/* BOUCLE INFINIE */
/****************************************************************/
void loop()
{
while(ESP8266.available())
{
Serial.println(ESP8266.readString());
}
}
/****************************************************************/
/* Fonction qui initialise l'ESP8266 */
/****************************************************************/
void initESP8266()
{
Serial.println("**********************************************************");
Serial.println("**************** DEBUT DE L'INITIALISATION ***************");
Serial.println("**********************************************************");
envoieAuESP8266("AT+RST");
recoitDuESP8266(2000);
Serial.println("**********************************************************");
envoieAuESP8266("AT+CWMODE=3");
recoitDuESP8266(5000);
Serial.println("**********************************************************");
envoieAuESP8266("AT+CWJAP=\""+ NomduReseauWifi + "\",\"" + MotDePasse +"\"");
recoitDuESP8266(10000);
Serial.println("**********************************************************");
envoieAuESP8266("AT+CIFSR");
recoitDuESP8266(1000);
Serial.println("**********************************************************");
envoieAuESP8266("AT+CIPMUX=1");
recoitDuESP8266(1000);
Serial.println("**********************************************************");
envoieAuESP8266("AT+CIPSERVER=1,80");
recoitDuESP8266(1000);
Serial.println("**********************************************************");
Serial.println("***************** INITIALISATION TERMINEE ****************");
Serial.println("**********************************************************");
Serial.println("");
}
void envoiTcp(){
envoieAuESP8266("AT+CIPSTART=4,\"UDP\",\"192.168.0.13\",8000");
recoitDuESP8266(1000);
envoieAuESP8266("AT+CIPSEND=4,18");
recoitDuESP8266(1000);
envoieAuESP8266("GET /THEAP/1.0");
recoitDuESP8266(1000);
envoieAuESP8266("");
recoitDuESP8266(1000);
}
/****************************************************************/
/* Fonction qui envoie une commande à l'ESP8266 */
/****************************************************************/
void envoieAuESP8266(String commande)
{
ESP8266.println(commande);
//Serial.println(commande.length());
}
/****************************************************************/
/*Fonction qui lit et affiche les messages envoyés par l'ESP8266*/
/****************************************************************/
void recoitDuESP8266(const int timeout)
{
String reponse = "";
long int time = millis();
while( (time+timeout) > millis())
{
while(ESP8266.available())
{
char c = ESP8266.read();
reponse+=c;
}
}
Serial.print(reponse);
}