Go Down

Topic: ESP8266 and OSC- dispatching messages troubles (Read 118 times) previous topic - next topic

CloudSky

Hello everyone !

My lack of coding skills has brought me here...
I am hoping one of you could give me a little push in the right direction.

What I am trying to do is send messages from ableton live to my ESP8266 (lolin nodemcu v3).
It works if I am only sending one message.
When I try to dispatch 3 messages, somehow it dispatches the first message/address but the other two
are stuck at -255.

Tried searching for solutions but I am most sure that my lack of knowledge/experience is making me not see one.

Anyone with a suggestion?

 CODE :

/*---------------------------------------------------------------------------------------------

#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
#include <OSCMessage.h>
#include <OSCBundle.h>
#include <OSCData.h>

char ssid[] = "osc";          // your network SSID (name)
char pass[] = "oscoscosc"; // your network password

// A UDP instance to let us send and receive packets over UDP
WiFiUDP Udp;
//const IPAddress outIp(192,168,0,233);        // remote IP (not needed for receive)
//const unsigned int outPort = 9999;          // remote port (not needed for receive)
const unsigned int localPort = 8888;        // local port to listen for UDP packets (here's where we send the packets)


OSCErrorCode error;
float ledStatelow = 1.0; 
float ledStatemid = 1.0; 
float ledStatehi = 1.0;   
         
void setup() {
  pinMode(16, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(4, OUTPUT);
  analogWrite(16, ledStatelow);   
  analogWrite(5, ledStatemid);
  analogWrite(4, ledStatehi);

  Serial.begin(9600);

  // Connect to WiFi network
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);
  WiFi.softAP(ssid, pass);
        //while (WiFi.status() != WL_CONNECTED) {
    delay(5000);
        // Serial.print(".");
        // }
  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.softAPIP());

  Serial.println("Starting UDP");
  Udp.begin(localPort);
  Serial.print("Local port: ");
  Serial.println(Udp.localPort());

}

void hi(OSCMessage &msg) {
  ledStatehi = (msg.getFloat(0)*255.0f);
  analogWrite(16, ledStatehi);
  Serial.print("/hi: ");
  Serial.println(ledStatehi);
}

void mid(OSCMessage &msg) {
  ledStatemid = (msg.getFloat(0)*255.0f);
  analogWrite(5, ledStatemid);
  Serial.print("/mid: ");
  Serial.println(ledStatemid);
}

void low(OSCMessage &msg) {
  ledStatelow = (msg.getFloat(0)*255.0f);
  analogWrite(4, ledStatelow);
  Serial.print("/low: ");
  Serial.println(ledStatelow);
}

void loop() {
  OSCMessage msg;
  int size = Udp.parsePacket();
  if (size > 0) {
    while (size--) {
      msg.fill(Udp.read());
    }
    if (!msg.hasError()) {
      msg.dispatch("/followlow", low, 0);
      msg.empty();
      msg.dispatch("/followmid", mid, 0);
      msg.empty();
      msg.dispatch("/followhi", hi, 0);
      msg.empty();
    }
   
    else {
      error = msg.getError();
      Serial.print("error: ");
      Serial.println(error);
    }
  }
}

CloudSky

Ok, fixed it. msg.empty(); was needed only one time ! Moving on (:

PaulS

Code: [Select]
float ledStatelow = 1.0;
float ledStatemid = 1.0;
float ledStatehi = 1.0;   

A state is off or on. An analog pin VALUE can be any integral value from 0 to 255. Using float is wrong. Using State in the name is wrong.
The art of getting good answers lies in asking good questions.

Go Up