OSC message error

Status
Not open for further replies.

harald25

Well-known member
Hello.
I've connected a Huzzah ESP8266 breakout to a Teensy 3.2 through serial.
I'm trying to make the ESP receive OSC messages over UDP, and send them over serial (with SLIP serial) to the Teensy, and then decode the OSC message and activate a function.

At the moment I've programmed the Teensy to take the messages coming from the ESP, and if there are no errors, route them to the appropriate function. The function then outputs something to the serial connection between my PC and Teensy (not the same one as the ESP and Teensy uses), like for example 'LED ON'.
If there is an error no function is activated and "Error in OSC message" is printed to the serial interface my computer is connected to and also "Serial.println(SLIPSerial.read());"

I get a lot of output to the serial monitor. But almost always with errors.
Only 1/10 times (or something) do I get the output from a function, meaning there was no error.

My problem is that I'm unable to find out what is wrong with the OSC messages.
The function checking for errors is: "msgIN.hasError()" where "msgIN" is an object of type 'OSCMessage'. I'm not able to find any information on what the different possible errors are, or how to output the error message.

Help please!?

This is the code on my Teensy:

Code:
//DHCP-based OSC server test code
#include <SPI.h>
#include <SLIPEncodedSerial.h>
#include <OSCMessage.h>

SLIPEncodedSerial SLIPSerial(Serial1);


void setup(){
  Serial.begin(9600);         //Teensy <=> Computer 
  SLIPSerial.begin(115200);   //Teensy <=> ESP
  delay(1000);
  Serial.println("Started");
}

void loop(){
  OSCMsgReceive();
} 



void toggleOnOff(OSCMessage &msg, int addrOffset)
{
  int ledState;
  ledState = (boolean) msg.getFloat(0);
  OSCMessage msgOUT("/OnOff/toggle1");

  //digitalWrite(ledPin, ledState);

  msgOUT.add(ledState);
  if (ledState) {
    Serial.println("LED on");
  }
  else {
    Serial.println("LED off");
  }

  ledState = !ledState;     // toggle the state from HIGH to LOW to HIGH to LOW ...

  //send osc message back to control object in TouchOSC
  //Local feedback is turned off in the TouchOSC interface.
  //The button is turned on in TouchOSC interface whe the conrol receives this message.
  SLIPSerial.beginPacket();
  msgOUT.send(SLIPSerial); // send the bytes
  SLIPSerial.endPacket(); // mark the end of the OSC Packet
  msgOUT.empty(); // free space occupied by message
}

void funcValue(OSCMessage &msg, int addrOffset ){

  int value = msg.getFloat(0);
  OSCMessage msgOUT("/Fader/Value");

  Serial.print("Value = : ");
  Serial.println(value);

  msgOUT.add(value);

  SLIPSerial.beginPacket();
  msgOUT.send(SLIPSerial); // send the bytes
  SLIPSerial.endPacket(); // mark the end of the OSC Packet
  msgOUT.empty(); // free space occupied by message
}

void OSCMsgReceive()
{
  
  OSCMessage msgIN;
  int size;
  
  while(!SLIPSerial.endofPacket())
  {
    
    if(size = SLIPSerial.available() > 0)
    {
      while(size--)
      {
        msgIN.fill(SLIPSerial.read());
      }
      if(!msgIN.hasError())
      {
        msgIN.route("/OnOff/toggle1",toggleOnOff);
        msgIN.route("/Fader/Value",funcValue);
      }
      else
      {
        Serial.println("Error in OSC message");
        Serial.println(msgIN.getError());
      }
    }
  }
}
 
In the OSCData.h file there is a type def OSCErrorCode, composed of an enum (something I had no idea you could do... )
Code:
typedef enum { OSC_OK = 0,
	BUFFER_FULL, INVALID_OSC, ALLOCFAILED, INDEX_OUT_OF_BOUNDS
} OSCErrorCode;

It seems to me that one of the above should be printed, when in your program above, you call ...
Code:
Serial.println("Error in OSC message");
Serial.println(msgIN.getError());

By that I think I mean it will print a "0" for OSC_OK (aka no error, I think), a "1" for a BUFFER_FULL error etc ... so you should be getting something like: "Error in OSC Message 1" for a BUFFER_FULL error.

I had a really brief look at the code ... it is pretty complicated and impressive! That's all i could glean on a quick read. I suspect there is a length / typing issue difference between what the esp sends and what the teensy receives .... just a wild guess.

Do you have anything 'known good' to receive or send osc messages??? could be helpful to debug.
 
I had a thought ... If you had two teensys you could use one to send osc messages to the other using SLIP .... or even you could just route a message out the serial port back in the same serial port on one teensy (OSC is transport independent, right?) ...

that would confirm that you can send and recieve osc ....

I noticed in the oscuino documentation that there were a lot of *ifndefs* related to the ESP which implies that there are differences (particularly in 'int /byte' length?) that could be problematic ....

I also saw that a mismatch between bundle vs msg could create errors, so maybe check what you are sending to the teensy again....
 
Hey Adrian. Thanks for the reply.
I've been a little busy lately so haven't had time to look more at it.
Next week I have more time, so I'll test some more and come back here with a reply then :)
 
Ok.
I'm looking into this as we speak.
I've come to the conclusion that there are not actually errors in the OSC messages.
The reason I thought so is because I was doing 'if(msgIN.hasError())' while the message was being filled. And until the message is successfully filled this function will return true.
 
Ok.
I'm looking into this as we speak.
I've come to the conclusion that there are not actually errors in the OSC messages.
The reason I thought so is because I was doing 'if(msgIN.hasError())' while the message was being filled. And until the message is successfully filled this function will return true.

good point.
 
Status
Not open for further replies.
Back
Top