-->
Page 1 of 6

UDP send from esp8266

PostPosted: Sun Apr 03, 2016 1:30 pm
by stefanB11
Hi There,

I´m just looking for an easy way to send data from a sensor via a adafruit huzzah esp8266 microcontroller via UDP to my PC.
Just the simple thing, for example : sending a Temperatur data string via UDP on a defined localport to the PC.

I hope there is a way, please help me!!!!

thx to all!!
S.

Re: UDP send from esp8266

PostPosted: Mon Apr 04, 2016 3:35 am
by bbx10node
In the IDE menu File | Examples | ESP* has examples for UDP.

Re: UDP send from esp8266

PostPosted: Mon Apr 04, 2016 6:01 am
by Robert Angyal
I use this page. https://thearduinoandme.wordpress.com/t ... nary-data/
From Arduino code.
1.Connect Wifi
2.Connect Udp
3.Can receive and send messages.


// connect to UDP – returns true if successful or false if not
boolean connectUDP()
{
boolean state = false;

Serial.println("");
Serial.println("Connecting to UDP");

if (UDP.begin(localPort) == 1){
Serial.println("Connection successful");
state = true;
}
else{
Serial.println("Connection failed");
}
return state;
}

// connect to wifi – returns true if successful or false if not
boolean connectWifi()
{
boolean state = true;
int i = 0;

WiFi.config(ip, gateway, subnet);
WiFi.begin(ssid, password);

// Wait for connection
Serial.print("Connecting");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
if (i > 10){
state = false;
break;
}
i++;
}
if (state){
Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
}
else {
Serial.println("");
Serial.println("Connection failed.");
}
return state;
}

// receive udp messages
void udpReceive( void)
{
if(wifiConnected && udpConnected){
// if there’s data available, read a packet
int packetSize = UDP.parsePacket();
if(packetSize) {
// read the packet into packetBufffer
UDP.read(packetBuffer,UDP_TX_PACKET_MAX_SIZE);
Serial.println("Receive:");
Serial.println(packetBuffer);
}
}
}

unsigned char udpSend( char * msg)
{ UDP.beginPacket("192.168.73.1", 1111);
Serial.println(msg);
UDP.write(msg);
return UDP.endPacket();
}

Re: UDP send from esp8266

PostPosted: Mon Apr 04, 2016 8:26 am
by stefanB11
bbx10node wrote:In the IDE menu File | Examples | ESP* has examples for UDP.



Hi,

thx for the fast answer! The only example for udp i can found, is in the examples/wifi and ethernet menu not in ESP*. In the different ESP* examples i can not find any udp examples. I´m wondering, cause this should be a simple standard. Just read sensor, and send the string via udp. ...

Anyway, thx for help...maybe you know more, the please tell me, I would thank very much!
greetz, s.