1

I am using the OSCbundle.h library to receive OSC messages on a Teensy 3.x(Arduino) from TouchOSC.

Once the OSC message ahas been recieved, there is (often) a return message that sends feedback back to the TouchOSC interface, that is typically called like:

OSCMessage msgOUT("/2/toggle1");

where "/2/off1" is the destination "address" of the message.

I am trying to replace the literal "/2/toggle1", with a variable. Currently I am using a String variable type name 'title' to contain the destination address, however I am unable to use:

OSCMessage msgOUT(title);

The above results in the following error: "no matching function for call to 'OSCMessage::OSCMessage(String&)'"

If I try using other variable formats, such as uint8_t, I get:

"call of overloaded 'OSCMessage(uint8_t&)' is ambiguous"

I have tried converting the String to various other variable types, but so far I have not figured out a type or format that works to replace the literal.

Any ideas?

Here is the full code of the function:

void transmit(byte cmd,  byte mtr, byte spd, byte otr, int value, String title){

Serial.print("title:");
Serial.println(title);

Wire.beginTransmission(0x44); // transmit to device #8
Wire.write( cmd );              // sends one byte
Wire.write( mtr ); 
Wire.write( spd );       
Wire.write( otr );  
Wire.endTransmission();    // stop transmitting
print_i2c_status();  // print I2C final status

OSCMessage msgOUT("/2/off1");
msgOUT.add(value);
Udp.beginPacket(Udp.remoteIP(), destPort);
msgOUT.send(Udp); // send the bytes
Udp.endPacket(); // mark the end of the OSC Packet
msgOUT.empty(); // free space occupied by message

}
rdel
  • 155
  • 1
  • 1
  • 10
  • 1
    Ok. So after a bunch of blind trial and error, it seems using const char* instead of String actually works. Not exactly sure I understand why, but going with it for now! – rdel Jan 08 '17 at 22:13

1 Answers1

1

OSCMessage takes const char * as an argument which you can see here: https://github.com/CNMAT/OSC/blob/master/OSCMessage.h#L112

While this is related to a string, it isn't the same thing. In the Arduino language there is a String class that provides the same kinds of conveniences that you might expect from other high level or object oriented languages.

This class overrides the + operator so that you can do string concatenation. This class also has a .c_str() method that will return a const char *.

https://www.arduino.cc/en/Reference/CStr

If you put this together you can take your strings and concatenate them and then return the character array pointer.

String addr_prefix = "/some/osc/address/";
String addr_suffix = "destination";
String completeaddress = addr_prefix + addr_suffix;
const char * addr = completeaddress.c_str();
Adam Tindale
  • 1,239
  • 10
  • 26