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:
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());
}
}
}
}