Chat freely about anything...

User avatar
By Widder
#17224 Great start, Antoine! I gave it a try (on Mac, had to build IDE from source rather than use the downloadable version), but OSC packets seem to have significant latency issues at the moment... Have you seen this also? Maybe the networking stack under the hood isn't being serviced often enough to provide good performance for real-time interaction? (I've done a similar thing with Lua - just raw UDP packets - and the latency is much better.)

Here's a bit of code illustrating the latency - the Serial prints "pressed" & "released" come immediately to the console, but the corresponding OSC packets "/play 1" & "/play 0" come much delayed (attach a button on GPIO2, or just carefully short it to the ground pin with a paper clip):

Code: Select all#include <mem.h>
#include <ESP8266WiFi.h>
#include <WiFiUDP.h>
#include <OSCMessage.h>

int buttonPin = 2;

boolean currentState = HIGH;//stroage for current measured button state
boolean lastState = HIGH;//storage for last measured button state
boolean debouncedState = HIGH;//debounced button state

int debounceInterval = 5;//wait 5 ms for button pin to settle
unsigned long timeOfLastButtonEvent = 0;//store the last time the button state changed



// A UDP instance to let us send and receive packets over UDP
WiFiUDP Udp;
const IPAddress outIp(192, 168, 4, 2);
const unsigned int outPort = 8266;

void setup() {
  Serial.begin(115200);
  pinMode(buttonPin, INPUT_PULLUP);
 
  // set up soft Access Point (acts as wireless base station)
  WiFi.mode(WIFI_AP);
  WiFi.softAP("ESPOSC");
  Udp.begin(8266);
 
  delay (1000);
  Serial.println("WiFi Access Point: ESPOSC");
  delay (500);
  Serial.println("WiFi Access Point: ESPOSC");
  Serial.println(WiFi.softAPIP());
}

void loop() {
 
  currentState = digitalRead(buttonPin);
  unsigned long currentTime = millis();
 
  if (currentState != lastState){
    timeOfLastButtonEvent = currentTime;
  }
 
  if (currentTime - timeOfLastButtonEvent > debounceInterval){//if enough time has passed
    if (currentState != debouncedState){//if the current state is still different than our last stored debounced state
      debouncedState = currentState;//update the debounced state
     
      //trigger an event
      if (debouncedState == LOW){
        Serial.println("pressed");
        OSCMessage trig("/play");
        trig.add(1);
        Udp.beginPacket(outIp, outPort);
        trig.send(Udp);
        Udp.endPacket();
        trig.empty();
      } else {
        Serial.println("released");
        OSCMessage trig("/play");
        trig.add(0);
        Udp.beginPacket(outIp, outPort);
        trig.send(Udp);
        Udp.endPacket();
        trig.empty(); 
      }
    }
  }
 
  lastState = currentState;
 
  delay(10);
}
User avatar
By SVWliker
#24623 Hey!

Are there new information?

I want to do the following things:

1) Connect a pulsesensor to my ESP8266
2) Send the data via WiFi to my Computer
3) I need MIDI or OSC Protocol
4) Use the OSC Protocol as external source for my VJ Software and visualize it in realtime


I am not so good, so do you have any good tutorials or tips?


Thanks a lot and best regards!
User avatar
By jemamena
#31246 Awesome, I will try it. I am more interested in receiving osc messages from for example touchosc. Can you do that with your library? if so, can you post an example?

Thanks in advance