Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By stefanB11
#44739 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.
User avatar
By Robert Angyal
#44779 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();
}
Last edited by Robert Angyal on Mon Apr 04, 2016 1:53 pm, edited 1 time in total.
User avatar
By stefanB11
#44792
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.