OSC library - route causing error?

hey all. i know the OSC library is not the most widely used thing but i have been working on this for 4 hours and getting nowhere.

trying to route incoming OSC messages to an i2c lcd, incoming with /lcd, i have the following:

OSCMessage msg;
  int size = Udp.parsePacket();
  if (size > 0) { 
    while (size--) { msg.fill(Udp.read()); }
    if (!msg.hasError())  {   msg.route("/lcd", osclcd);  }  
    if (!msg.hasError())  {   msg.route("/14", oscignore);  }
  }
  else {  
    error = msg.getError();    
    Serial.print("error: ");   
    Serial.println(error);  
 }

and functions:

void osclcd(OSCMessage &msg, int addressOffset){
  char str [20];
  int size;
  if ((size = Udp.parsePacket()) > 0) {
    while (size--)
      msg.fill(Udp.read());
      msg.fill(Udp.read());
      msg.getString(0, str);
      lcd.setCursor(0,1); // clear line first
      lcd.print("                ");
      lcd.setCursor(0,1); // print it
      lcd.print(str);
  }
}

void oscignore(OSCMessage &msg, int addressOffset) { }

which prints “error: 2” relentlessly in the serial monitor, and i can’t find what that means anywhere.

i’ve also tried OSC lib’s “msg.dispatch” with zero result here, which just send the messages to nowhere.

for context, what’s getting sent is:

/lcd,s,CUE: TITLE

which gets parsed correctly to the LCD if i send everything to the lcd, but not if i use route/dispatch.

any help would be appreciated.

You might want to look at this How to get the best out of this forum before you proceed any further.

Also we need to see all your code not just snippets.

I have used OSC but mainly using the Processing language. I have not used it on an Arduino. Where did you get this library from and what sort of Arduino are you using?

the only pertinent things are what’s shown. nothing else in the sketch has anything receiving OSC. i’ve searched a LOT on this, there’s nearly no forum posts and the docs and examples don’t function for me for whatever reason, again the error code that has no description anywhere. people just don’t use this i guess.

and sure, including all the mess of everything i tried to make work that didn’t:

#ifdef ESP8266
#include <ESP8266WiFi.h>
#endif
#include <WiFiUdp.h>
#include <OSCMessage.h>
#include <OSCBundle.h>  
#include <OSCData.h>
#include <LCD_I2C.h>
#include <PCF8575.h>

char ssid[] = "xxxxx";     
char pass[] = "xxxxx";       

IPAddress subnet(255,255,0,0);
IPAddress gateway(10,0,1,1);
IPAddress local_IP(10,0,1,222);

//LCD
LCD_I2C lcd(0x27, 16, 2); 
PCF8575 PCF(0x20);

// A UDP instance to let us send and receive packets over UDP
WiFiUDP Udp;
const IPAddress outIp(10,0,1,121);        // 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;

#ifndef BUILTIN_LED
#ifdef LED_BUILTIN
#define BUILTIN_LED LED_BUILTIN
#else
#define BUILTIN_LED 13
#endif
#endif

int lcdch;  // display updater
int repeatrate = 350;
int value;  // used in spfread
int howlong = 1200;  // delayed button press wait time
byte ptspeed = 2;  // slow med fast
byte exsel = 1; // exec selector 
byte work = 1; // work toggle
byte tc = 1; // timecode toggle
int cleartimer = 0;  
int signaltimer = 0;
byte debounce = 80;
int ptvalue = 1;
unsigned long prevtime = 0;
const long interval= 3000;


// NEW CHARS

byte qtr[] =    { B10000, B10000, B10100, B01001, B10101, B00111, B00001, B00001 };
byte degr[] =   { B01000, B10100, B01000, B00000, B00000, B00000, B00000, B00000 };
byte solo[] =   { B00000, B10101, B01110, B00100, B01110, B10101, B00000, B00000 };
byte wifii[] =  { B00000, B00000, B00000, B00000, B00000, B00000, B00011, B00000 };
byte wifiii[] = { B00000, B00000, B00000, B00000, B00111, B00000, B00011, B00000 };
byte wifiiii[]= { B00000, B00000, B01111, B00000, B00111, B00000, B00011, B00000 };
byte wifiiiii[]={ B11111, B00000, B01111, B00000, B00111, B00000, B00011, B00000 };


const byte btnnext = 8;
const byte btngo = 1;
const byte btnselect = 2;
const byte btnoff = 3;
const byte btnupdate = 4;
const byte btnwork = 5;
const byte btntc = 6;
const byte btnspeed = 7;

const byte btnprev = 0;
const byte btntilt1 = 9;
const byte btnpan0 = 10;
const byte btnpan1 = 11;
const byte btntilt0 = 12;


//============================================================================================                                   

void setup() {   

  lcd.begin();
  lcd.backlight();
  lcd.createChar(1,degr);
  lcd.createChar(2,solo);

  lcd.createChar(3,wifii);
  lcd.createChar(4,wifiii);
  lcd.createChar(5,wifiiii);
  lcd.createChar(6,wifiiiii);
  lcd.createChar(7,qtr);
  PCF.begin();  // key input

  pinMode(BUILTIN_LED, OUTPUT);
  pinMode(14, INPUT_PULLUP);

  Serial.begin(115200);
  Serial.print("Connecting to ");
  Serial.println(ssid);

  if (WiFi.config(local_IP, gateway, subnet)) {
    Serial.println("Static IP Configured");
  }
  WiFi.begin(ssid, pass);

  while (WiFi.status() != WL_CONNECTED) {  // blink led if not connected
    lcd.setCursor(0, 0);        
    lcd.print("focus tool v0.92");
    lcd.setCursor(0, 1);        
    lcd.print("connecting");
    delay(1000);
  }

  Serial.println("IP address: ");   
  Serial.println(WiFi.localIP());
  Udp.begin(localPort); 
  Serial.print("UDP receive port: ");   
  Serial.println(Udp.localPort());
  digitalWrite(BUILTIN_LED, LOW);  // led off when connected
  
  delay(2000);
  lcd.clear();
  lcd.setCursor(12,0); lcd.print("1"); lcd.write(1);  // degree
}

/*
void osclcd(OSCMessage &msg, int addressOffset){
  char str [20];
  int size;
  if ((size = Udp.parsePacket()) > 0) {
    while (size--)
      msg.fill(Udp.read());
      msg.fill(Udp.read());
      msg.getString(0, str);
      lcd.setCursor(0,1); // clear line first
      lcd.print("                ");
      lcd.setCursor(0,1); // print it
      lcd.print(str);
  }
}

void oscignore(OSCMessage &msg, int addressOffset) { }
*/

void loop() {
// RECEIVE ---------------------------------------------------------------------------
  OSCMessage msg("/lcd");
  char str [20];
  int size;
  if ((size = Udp.parsePacket()) > 0) {
    while (size--)
      msg.fill(Udp.read());
      msg.fill(Udp.read());
      msg.getString(0, str);
      lcd.setCursor(0,1); // clear line first
      lcd.print("                ");
      lcd.setCursor(0,1); // print it
      lcd.print(str);
  }

/*

  OSCMessage msg("/lcd");
  int size = Udp.parsePacket();
  if (size > 0) { 
    while (size--) { msg.fill(Udp.read()); }
    if (!msg.hasError())  {   msg.route("/lcd", osclcd);  }  
//   if (!msg.hasError())  {   msg.route("/14", oscignore);  }
    

  }
  else {  
    error = msg.getError();    
    Serial.print("error: ");   
    Serial.println(error);  
 }


OSCMessage msg;
  int size = Udp.parsePacket();
  if (size > 0) {  // OSC MIDI DISPLAY NIGHTMARE shitting hell
    while (size--) { msg.fill(Udp.read()); }
    if (!msg.hasError())  {   msg.dispatch("/focustool/lcd", routeAddress);  }  // row 0 (first 5 chars)
    else {  error = msg.getError();    Serial.print("error: ");   Serial.println(error);   }
  }
*/




//  OSCMessage msg;


//      char oscin = str;
//      char topline[4] = output.substring(0,3);
//      char bottomline[15] = output.substring(4);
//      lcd.setCursor(0,0);
//      lcd.print(topline);
//      lcd.setCursor(0,1);

  

// WIFI SIGNAL METER --------------------------------------------------------------------------------------------------------------

  unsigned long nowtime = millis();
  if (nowtime - prevtime >= interval) { 
    long siglevel = WiFi.RSSI();
    siglevel = -siglevel;
//    Serial.println(siglevel); // debug
    lcd.setCursor(15,0);
    if ((siglevel >=1) && (siglevel<= 39)) { lcd.write(6); }
    if ((siglevel >=40) && (siglevel<= 49)) { lcd.write(5); }
    if ((siglevel >=50) && (siglevel<= 59)) { lcd.write(4); }
    if ((siglevel >=60) && (siglevel<= 70)) { lcd.write(3); }
    prevtime = nowtime;

  }



// PT SPEED ---------------------------------------------------------------  
  while(readspf(btnspeed) == 0) { 
    if(ptspeed == 3) 
      { ptspeed = 1; delay(debounce); }
    else 
      {ptspeed = ptspeed + 1; delay(debounce);}
    lcd.setCursor(12, 0);
      if(ptspeed==1) { lcd.write(7); ptvalue = 1;}  // .25 deg
      if(ptspeed==2) { lcd.print("1"); ptvalue = 2;}  // 1 deg      
      if(ptspeed==3) { lcd.print("5"); ptvalue = 5;}  // 5 deg
    while(readspf(btnspeed) == 0) { 
      delay(10);
      } // do nothing until button release
    delay(debounce);

  }
  
// D PAD ----------------------------------------------------------
  while(readspf(btnpan0) == 0) {
      OSCMessage msg("/cmd");
      if(ptspeed == 1) { msg.add("attribute pan at - .25"); }
      if(ptspeed == 2) { msg.add("attribute pan at - 1"); }
      if(ptspeed == 3) { msg.add("attribute pan at - 5"); }
      Udp.beginPacket(outIp, outPort);  msg.send(Udp);  Udp.endPacket();   msg.empty();
      retrig(btnpan0);
  } 

  while(readspf(btnpan1) == 0) {
      OSCMessage msg("/cmd");
      if(ptspeed == 1) { msg.add("attribute pan at + .25"); }
      if(ptspeed == 2) { msg.add("attribute pan at + 1"); }
      if(ptspeed == 3) { msg.add("attribute pan at + 5"); }
      Udp.beginPacket(outIp, outPort);  msg.send(Udp);  Udp.endPacket();   msg.empty();
      retrig(btnpan1); 
  } 

  while(readspf(btntilt0) == 0) {
      OSCMessage msg("/cmd");
      if(ptspeed == 1) { msg.add("attribute tilt at - .25"); }
      if(ptspeed == 2) { msg.add("attribute tilt at - 1"); }
      if(ptspeed == 3) { msg.add("attribute tilt at - 5"); }
      Udp.beginPacket(outIp, outPort);  msg.send(Udp);  Udp.endPacket();   msg.empty();
      retrig(btntilt0); 
  } 

  while(readspf(btntilt1) == 0) {
      OSCMessage msg("/cmd");
      if(ptspeed == 1) { msg.add("attribute tilt at + .25"); }
      if(ptspeed == 2) { msg.add("attribute tilt at + 1"); }
      if(ptspeed == 3) { msg.add("attribute tilt at + 5"); }
      Udp.beginPacket(outIp, outPort);  msg.send(Udp);  Udp.endPacket();   msg.empty();
      retrig(btntilt1);
  } 

  // PREV / NEXT  ----------------------------------------------------------
  while(readspf(btnnext) == 0) {
      OSCMessage msg("/cmd");
      msg.add("next");
      Udp.beginPacket(outIp, outPort);  msg.send(Udp);  Udp.endPacket();   msg.empty();
      while(readspf(btnnext) == 0) { delay(1); }
      delay(debounce);
  }

  while(readspf(btnprev) == 0) {
      OSCMessage msg("/cmd");
      msg.add("prev");
      Udp.beginPacket(outIp, outPort);  msg.send(Udp);  Udp.endPacket();   msg.empty();
      while(readspf(btnprev) == 0) { }  
      delay(debounce);
  }



// UPDATE -------------------------------------------------------

  int waittosend = 0;
  while(readspf(btnupdate) == 0) {
      if(waittosend <= 2000) {
          delay(50);
          waittosend = waittosend + 101;
          if(readspf(btnupdate) == 1) {  // button up before timer up? send off message
            OSCMessage msg("/cmd");
            msg.add("macro lcdresend");
            
            Udp.beginPacket(outIp, outPort);  msg.send(Udp);  Udp.endPacket();   msg.empty();  
            delay(debounce); 
            }  //if button up before timer ends
         if(waittosend > 2000) {  // if timer is over send clear all
            OSCMessage msg("/cmd");
            msg.add("macro updatepreset");  
            Udp.beginPacket(outIp, outPort);  msg.send(Udp);  Udp.endPacket();   msg.empty(); //osc
            while(readspf(btnupdate) == 0) { delay(1); } // wait for button release
            delay(debounce); 
          } // if the timer runs out
      } // if timer up
  } // while 


//    OSCMessage msg("/cmd");
//    msg.add("macro lcdresend");
//    Udp.beginPacket(outIp, outPort);  msg.send(Udp);  Udp.endPacket();   msg.empty(); 




// GO ------------------------------------------------------------
  while(readspf(btngo) == 0) {
      OSCMessage msg("/cmd");  
      msg.add("go+");
      Udp.beginPacket(outIp, outPort);  msg.send(Udp);  Udp.endPacket();   msg.empty();
      while(readspf(btngo) == 0) { } // wait for release
    } 




// SEL ---------------------------------------------------------------  
  while(readspf(btnselect) == 0) { 
    if(exsel == 3) 
      {
        exsel = 1; // reset to 1?
        while(readspf(btnselect) == 0) { delay(1);} // wait for button up
        delay(debounce); 
      }
    else 
      {
        exsel = exsel + 1; // increment
        while(readspf(btnselect) == 0) { delay(1);} 
        delay(debounce);
      }
    OSCMessage msg("/cmd");
    if(exsel==1) { msg.add("macro STGFOCUS"); lcd.setCursor(0, 0); lcd.print("stage   "); }
    if(exsel==2) { msg.add("macro AIRFOCUS"); lcd.setCursor(0, 0); lcd.print("air     "); }  
    if(exsel==3) { msg.add("macro DEFFOCUS"); lcd.setCursor(0, 0); lcd.print("default "); }  
    Udp.beginPacket(outIp, outPort);  msg.send(Udp);  Udp.endPacket();   msg.empty();
  }




// OFF
  cleartimer = 0;
  while(readspf(btnoff) == 0) {
      if(cleartimer <= 2000) {
          delay(50);
          cleartimer = cleartimer + 101;
          if(readspf(btnoff) == 1) {  // button up before timer up? send off message
            OSCMessage msg("/cmd");
            msg.add("off");
            
            Udp.beginPacket(outIp, outPort);  msg.send(Udp);  Udp.endPacket();   msg.empty();  
            delay(debounce); 
            }  //if button up before timer ends
         if(cleartimer > 2000) {  // if timer is over send clear all
            OSCMessage msg("/cmd");
            msg.add("clearall");  
            Udp.beginPacket(outIp, outPort);  msg.send(Udp);  Udp.endPacket();   msg.empty(); //osc
            while(readspf(btnoff) == 0) { delay(1); } // wait for button release
            delay(debounce); 
          } // if the timer runs out
      } // if timer up
  } // while 
     

   
// WORK = SET, or PT RESET if held
  signaltimer = 0;
  while(readspf(btnwork) == 0) { 
      if(signaltimer <= 2000) {
          delay(50);
          signaltimer = signaltimer + 101;
          if(readspf(btnwork) == 1) {  // button up before timer up? send off message
            OSCMessage msg("/cmd");
            msg.add("Set Selection Property Active");
            Udp.beginPacket(outIp, outPort);  msg.send(Udp);  Udp.endPacket();   msg.empty();  
            delay(debounce); 
            }  //if button up before timer ends

         if(signaltimer > 2000) {  // if timer is over send clear all
            OSCMessage msg("/cmd");
            msg.add("macro pantiltreset");  
            Udp.beginPacket(outIp, outPort);  msg.send(Udp);  Udp.endPacket();   msg.empty(); //osc
            while(readspf(btnwork) == 0) { delay(1); } // wait for button release
            delay(debounce); 
          } // if the timer runs out
      } // if timer up
  } // while 

// TC SOLO  ---------------------------------------------------------------  
  while(readspf(btntc) == 0) { 
    if(tc == 2) 
      { 
        tc = 1; 
        while(readspf(btntc) == 0) { delay(1);}
        delay(debounce); 
        OSCMessage msg("/cmd");
        msg.add("solo off");
        Udp.beginPacket(outIp, outPort);  msg.send(Udp);  Udp.endPacket();   msg.empty();
      }
    else 
      {
        tc = tc + 1; 
        while(readspf(btntc) == 0) { delay(1);}
        delay(debounce);
        OSCMessage msg("/cmd");
        msg.add("solo on");
        Udp.beginPacket(outIp, outPort);  msg.send(Udp);  Udp.endPacket();   msg.empty();
      }
    byte tcsend = tc - 1;
    lcd.setCursor(14,1);
    if(tcsend == 1) { lcd.write(2); } else { lcd.print(" ");}  // solo indicator
  }


}  // LOOP

// ========================================================================================================


void retrig(int button) {
  int waittime = 0;
  while(readspf(button) == 0) {
  if(waittime <= repeatrate && readspf(button) == 0) { 
    delay(10); 
    waittime = waittime + 10;
    }
    if(readspf(button) == 1) { break; }
    if(waittime == repeatrate) { break; }
  }
}  

bool readspf(int pin) {
  int x = PCF.read16();
  value = bitRead(x,pin);  // needs inverting
  return value;
}

Thanks, you didn't tell me what sort of Arduino you have but from the code I am assuming you used an ESP8266. Sorry but I don't know anything about this type of knock off clone, I only deal with official Arduino boards.

So sorry you will have to wait until someone who does comes along.

See post 2. Remember we can't see what you see.

if we had a dollar for everytime we heard that.

the whole code is in the second post, but at this point i’ll have to figure out another way. i’m bad at explaining anything and bad at asking for help apparently, tried to be as clear as possible and failed at that as well

Just follow the instructions at post 2.
I am in a good mood today so I will tell you the first two things you need to do

  1. Hand draw the wiring and components, label any non obvious parts. Now post a picture of the drawing.
  2. Post ALL the code in code tags

I forgot, what OS, what IDE and ver, what board was selected and did you use the Tools menu to change any of the boards settings.

Not saying that will get you a solution but it is the starting info. I know nothing of the subject matter but with the basics someone who does can start asking questions.
Good luck.

you know nothing of the subject matter and your solution is “hand draw wiring and components”?

so… what do i draw for trying to get a UDP based wifi message into the serial monitor with no hardware attached to a board? a square that says “esp8266”?

It's standard procedure and you were asked in post 2, 4, 5, and 7. You could have told us what board and that it had no connections other than USB as a reply to post 2.
The other thing you haven't done, and maybe the hints were not strong enough for you, is to simplify. For starters, get rid of the LCD and use a few serials. prints to trace progress and output. These suggestions are generic and have always proved to be useful. The less code there is to look at, the better the chance someone can spot the error.

I just had a look at the OSC library and see it comes with a LOT of examples. This is where I start when coding something new. You may benefit from these as well.