Chat freely about anything...

User avatar
By Gleekzorp
#55858 Hi All,

I really hope someone can give me a hand with this, it's driving me crazy...

What I'm trying to do is having a esp-12 in AP mode listening to UDP data (in fact, OSC messages) that several other esp-12s in STA mode are sending, for now restricted to one esp-12 sending a LED-toggle message.

The AP server is OK (I think...) and can be accessed from e.g. Processing (see below) or Packet Sender (Mac), but I just can't get the 2nd esp-12 to connect to the AP server. No errors are shown.
All IP addresses are static and I'm using the Adruino IDE (1.6.11)

After having read a lot on this topic and tried even more, my last hope is the wisdom of crowds... so, any help is hugely appreciated!


AP Server
Code: Select all
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
#include <OSCMessage.h>
#include <OSCData.h>
#include <DNSServer.h>

#define BUILTIN_LED 12
#define PACKET_LED 5

const byte   DNS_PORT  =   53;

WiFiUDP Udp;
DNSServer dnsServer;

const IPAddress local(11, 11, 11, 11);
const IPAddress dns(11, 11, 11, 11);
const IPAddress gateway(11, 11, 11, 1); /* not used */
const IPAddress netmask(255, 255, 255, 0);

const unsigned int localPort = 8888;

OSCErrorCode error;

unsigned int ledState = LOW;

void setup()
{

  Serial.begin(115200);
   
  pinMode(BUILTIN_LED, OUTPUT);
  pinMode(PACKET_LED, OUTPUT);
  digitalWrite(BUILTIN_LED, ledState);
  digitalWrite(BUILTIN_LED, HIGH);

  dnsServer.start(DNS_PORT, "*", local);

  WiFi.mode(WIFI_AP);
  WiFi.softAPConfig(local, dns, netmask);
  WiFi.softAP("UDP-RECEIVER");
  WiFi.begin();

  Udp.begin(localPort);

}

void led(OSCMessage &msg)
{
  ledState = msg.getInt(0);
  digitalWrite(BUILTIN_LED, ledState);
  Serial.print("/led: ");
  Serial.println(ledState);
}

void loop()
{
  dnsServer.processNextRequest();
  delay(0);
 
  OSCMessage oscMsg;
  int size = Udp.parsePacket();

  if (size > 0)
  {
    Serial.print((String)"Request from " + Udp.remoteIP().toString() + ", port " + Udp.remotePort());

    // short blink to show some data was received
    digitalWrite(BUILTIN_LED, LOW);
    delay(50);
    digitalWrite(BUILTIN_LED, HIGH);
   
    while (size--)
    {
      oscMsg.fill(Udp.read());
    }
    if (!oscMsg.hasError())
    {
      oscMsg.dispatch("/led", led);
    }
    else
    {
      error = oscMsg.getError();
      Serial.print("error: ");
      Serial.println(error);
    }
  }
}


STA client
Code: Select all#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
#include <OSCMessage.h>

WiFiUDP Udp;

int led = 1;

unsigned int localPort = 8888;

const IPAddress local(11, 11, 11, 30);
const IPAddress server(11, 11, 11, 11);
const IPAddress dns(11, 11, 11, 11);
const IPAddress netmask(255, 255, 255, 0);

void setup()
{
  Serial.begin(115200);
  pinMode(5, OUTPUT);
  digitalWrite(5, HIGH);

  WiFi.mode(WIFI_STA);
  WiFi.config(local, dns, netmask);
  WiFi.softAP("udpsender1");

  //WiFi.config(local, dns, netmask);
  WiFi.begin();

  Udp.begin(localPort);
}

void loop()
{
  OSCMessage msg("/led");
  msg.add(led);
  led = !led;

  digitalWrite(5, LOW);
  delay(50);
  digitalWrite(5, HIGH);
 
  Udp.beginPacket(server, 8888);
  msg.send(Udp);
  Udp.endPacket();
  msg.empty();
 
  delay(1000);
}


Processing:
Code: Select allimport oscP5.*;
import netP5.*;

OscP5 osc;
NetAddress esp8266;
boolean pressed = true;

void setup()
{
  osc = new OscP5(this, 12000);
  esp8266 = new NetAddress("11.11.11.11", 8888);
 
  size(100, 100); // click in this square to send an OCS message

}

void draw()
{
  if (mousePressed)
  {
      OscMessage msg = new OscMessage("/led").add((pressed)?1:0);
      osc.send(msg, esp8266);
      pressed = !pressed;
      delay(250);
  }
}
User avatar
By Gleekzorp
#57324 Yeah, solved it by changing the client setup() into:

Code: Select all  Serial.begin(115200);
  WiFi.begin("SERVERNAME"); // NAME of the server!

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println((String)"\nConnected to " + WiFi.localIP().toString());
  Udp.begin(9999);    // any port will do, we're not listening


Don't know why, but connecting based on server name worked for me...

Have fun!