-->
Page 1 of 1

Adafruit Feather Huzzah UDP connection to multiple clients

PostPosted: Tue Jul 05, 2016 7:13 pm
by dominator99
Managed to get AP & STA connected using slightly modified IDE sketches below:

Server

#include <ESP8266WiFi.h>
#include <WiFiUdp.h>

WiFiUDP port;

char packetBuffer[255];
unsigned int localPort = 9999;

const char *ssid = "ESP8266AP";
const char *password = "yourPassword";

void setup()
{
Serial.begin(115200);

Serial.println("\n\nMyAdafruitHeatherAP_5-7-16_2"); //prints filename

WiFi.softAP(ssid, password);
WiFi.mode(WIFI_AP); // to force connection as only AP
port.begin(localPort);

Serial.print("[Connecting] ");
Serial.println(WiFi.localIP()); //0.0.0.0
Serial.println(WiFi.softAPIP()); //192.168.4.1
}

void loop()
{
int packetSize = port.parsePacket();
Serial.print("Received (IP/Size/Data): ");
Serial.print(port.remoteIP());Serial.print(" / ");
Serial.print(packetSize);Serial.print(" / ");

if (packetSize)
{
int len = port.read(packetBuffer, 255);
if (len > 0) packetBuffer[len-1] = 0;
Serial.print(packetBuffer);
port.beginPacket(port.remoteIP(),port.remotePort());
port.write("Your UDP packet was received OK\r\n");
port.endPacket();
}

Serial.println("");
delay(1000);

Serial.print("[Connected] ");
Serial.println (WiFi.localIP());
Serial.println(WiFi.softAPIP());
Serial.println("");

}

........................................................................................................................................................................

client

#include <ESP8266WiFi.h>
#include <WiFiUdp.h>

WiFiUDP port;

char packetBuffer[255];
unsigned int localPort = 9999;


void setup() {
Serial.begin(115200);

Serial.println("MyAdafruitHeatherSTA_5-7-16_2"); //prints filename

WiFi.begin("ESP8266AP", "yourPassword");
port.begin(localPort);

Serial.print("[Connecting]: ");
Serial.println(WiFi.localIP());
}

void loop()
{
//Received
int packetSize = port.parsePacket();
Serial.print("Received(Size/data): ");
Serial.print(packetSize);Serial.print(" / ");

if (packetSize)
{
int len = port.read(packetBuffer, 255);
if (len > 0) packetBuffer[len-1] = 0;
Serial.print(packetBuffer);
}

Serial.println("");

//Send
port.beginPacket("192.168.4.1",9999);
port.write("Send millis: ");
char buf[20];
unsigned long testID = millis();
sprintf(buf, "%lu", testID);
Serial.print("Sending: ");Serial.println(buf);

port.write(buf);
port.write("\r\n");
port.endPacket();

delay(500);

Serial.print("[Connected] ");
Serial.println(WiFi.localIP());
Serial.println("");
}

I now want to add 3 more clients to send their temperature data to the server but don't know how to begin; any suggestions?

ps
I don't need a web connection just connect to local WLAN

Re: Adafruit Feather Huzzah UDP connection to multiple clien

PostPosted: Thu Jul 07, 2016 9:59 am
by mrburnette
I now want to add 3 more clients to send their temperature data to the server but don't know how to begin; any suggestions?


The Op here is running 2 clients to one AP in a ping-pong loop-back way...
http://www.esp8266.com/viewtopic.php?f=29&t=10698

I'm doing the reverse, one AP using UDP to broadcast NMEA to multiple clients:
http://www.hackster.io/rayburne/tardis-time-esp8266-ap-webserver-gps

Ray