Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Off-by-one on decoding (esp8266) #113

Open
iMartyn opened this issue Apr 29, 2020 · 1 comment
Open

Off-by-one on decoding (esp8266) #113

iMartyn opened this issue Apr 29, 2020 · 1 comment

Comments

@iMartyn
Copy link

iMartyn commented Apr 29, 2020

I think that there's a loss of a final byte in the library, and in my case it seems to be the most important byte!

I'm still hacking this together on a Wemos, so the code is messy but this code :

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

  Open Sound Control (OSC) library for the ESP8266

  Example for sending messages from the ESP8266 to a remote computer
  The example is sending "hello, osc." to the address "/test".

  This example code is in the public domain.

--------------------------------------------------------------------------------------------- */
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
#include <OSCMessage.h>
#include <OSCBundle.h>
#include <OSCData.h>


char ssid[] = "44v4";          // your network SSID (name)
char pass[] = "REDACTED";                    // your network password

WiFiUDP Udp;                                // A UDP instance to let us send and receive packets over UDP
const IPAddress outIp(192,168,1,236);        // remote IP of your computer
const unsigned int outPort = 10024;          // remote port to receive OSC
const unsigned int localPort = 10024;        // local port to listen for OSC packets (actually not used for sending)

OSCErrorCode error;
unsigned int ledState = LOW;              // LOW means led is *on*

void setup() {
  pinMode(BUILTIN_LED, OUTPUT);
  digitalWrite(BUILTIN_LED, ledState);    // turn *on* led
    Serial.begin(115200);

    // Connect to WiFi network
    Serial.println();
    Serial.println();
    Serial.print("Connecting to ");
    Serial.println(ssid);
    WiFi.begin(ssid, pass);

    while (WiFi.status() != WL_CONNECTED) {
        delay(500);
        Serial.print(".");
    }
    Serial.println("");

    Serial.println("WiFi connected");
    Serial.println("IP address: ");
    Serial.println(WiFi.localIP());

    Serial.println("Starting UDP");
    Udp.begin(localPort);
    Serial.print("Local port: ");
    Serial.println(Udp.localPort());
    
    OSCMessage msg("/xinfo");
    Udp.beginPacket(outIp, outPort);
    msg.send(Udp);
    Udp.endPacket();
    msg.empty();
    
}

void led(OSCMessage &msg) {
  ledState = msg.getInt(0);
  digitalWrite(BUILTIN_LED, ledState);
  Serial.print("/led: ");
  Serial.println(ledState);
}

void xinfo(OSCMessage &msg) {
  char buff[1024];
  msg.getString(0,buff,1024);
  Serial.print("/xinfo: ");
  Serial.println(buff);
}

void catchall(OSCMessage &msg, int addrOffset ) {
  char buff[1024];
  msg.getAddress(buff,0,1024);
  Serial.print(buff);
  Serial.print(":");
  for (int i=0;i<msg.size();i++) {
    Serial.print(" (");
    Serial.print(i);
    Serial.print(" - ");
    Serial.print(msg.getType(i));
    Serial.print(") ");
    if (msg.isBlob(i)) {
      Serial.print("[blob]");
    }
    if (msg.isChar(i) || msg.isString(i)) {
      msg.getString(i,buff,1024);
      Serial.print("`");
      Serial.print(buff);
      Serial.print("`");
    }
    if (msg.isInt(i)) {
      int intVal = 0;
      msg.getInt(intVal);
      Serial.print(intVal);
    }
    if (msg.isFloat(i) || msg.isDouble(i)) {
      double floatVal = 0;
      msg.getInt(floatVal);
      Serial.print(floatVal);
    }
  }
}

unsigned long last_send = 0;
unsigned long uptime_millis;
unsigned long bundle_count = 0;

void loop() {
  OSCBundle bundle;
  // every 10 seconds ~= every 9 seconds...
  uptime_millis = millis();
  if (last_send > uptime_millis || (uptime_millis - last_send) > (9 * 1000)) {
    last_send = uptime_millis;
    //Telling mixer we still want updates
    OSCMessage msg("/xremote");
    Udp.beginPacket(outIp, outPort);
    msg.send(Udp);
    Udp.endPacket();
    msg.empty();
  }
  
  int size = Udp.parsePacket();

  if (size > 0) {
    Serial.println("Buffer :");
    while (size--) {
      char b = Udp.read();
      bundle.fill(b);
      Serial.print(b, HEX);
    }
    Serial.println("");
    Serial.println("---");
    if (!bundle.hasError()) {
      Serial.println("Recieved a BUNDLE!!!!!");
      bundle_count = bundle.size();
      Serial.print("Bundle has ");
      Serial.print(bundle_count);
      Serial.println(" messages.");
      bundle.route("/*", catchall);
    } else {
      error = bundle.getError();
      Serial.print("error: ");
      Serial.println(error);
    }
  }
}

Creates this output :

Connecting to 44v4
.......
WiFi connected
IP address: 
192.168.1.137
Starting UDP
Local port: 10024
Buffer :
2F78696E666F002C737373730003139322E3136382E312E323336000585231382D33352D35332D3243000585231380000312E31360000
---
Recieved a BUNDLE!!!!!
Bundle has 1 messages.
/xinfo: (0 - s) `192.168.1.236` (1 - s) `XR18-35-53-2C` (2 - s) `XR18` (3 - s) `1.16`Buffer :
2F63682F30352F6D69782F6F6E0002C69000000
---
Recieved a BUNDLE!!!!!
Bundle has 1 messages.
/ch/05/mix/on: (0 - i) 0Buffer :
2F63682F30352F6D69782F6F6E0002C69000001
---
Recieved a BUNDLE!!!!!
Bundle has 1 messages.
/ch/05/mix/on: (0 - i) 0Buffer :
2F63682F30352F6D69782F6F6E0002C69000000
---
Recieved a BUNDLE!!!!!
Bundle has 1 messages.
/ch/05/mix/on: (0 - i) 0

Note that the two almost identical messages are decoded as having 0 as the attached integer data, but looking at the hex values, you can see one ends in 1, the other in 0.

These messages are from my OSC-capable XR18 mixer, muting and unmuting a channel. (Note it's wierd implementation requires the send port and recv port are the same)

@robtech21
Copy link

Has this issue ever been considered or fixed? I'm having the same issue and this is like a dead end for me...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants