thomasfredericks / MicroOsc

MicroOsc is a minimal Open Sound Control (OSC) library for Arduino
MIT License
16 stars 2 forks source link

Issue sending OCS messages ESP32 to Chataigne #4

Closed UseruserOmar closed 10 months ago

UseruserOmar commented 10 months ago

Hello Thomas,

I have run into an issue with sending OSC messages from an ESP32 connected with ethernet to my laptop running Chataigne. And I would like to know if you can help me out to find if the issue is coming from the MicroOSC library that I am using.

The following things that I have tried seem to work properly:

I also checked if the port in Chataigne matched with the port on the ESP32, which it did. But i couldn’t make it to send OCS messages from the ESP32 to Chataigne, not via ethernet neither via WiFi. I don’t know yet if the issue is coming from the ESP32 itself or the MicroOSC library.

I will attach the code to this issue file so you can have a look at what's happening. The code contains the ethernet setup and makes the EPS32 send a OCS message every 1000ms and enables it to receive a OSC message.

I hope I gave you all the necessary information and I look forward to your reply. If you any questions, please let me know!

Greetings, Omar

// Libraries
#include <ETH.h>
#include <WiFiUDP.h>
#include <MicroOscUdp.h>

// Global Variable declaration
static bool eth_connected = false;
unsigned long myChronoStart = 0;

// network settings
WiFiUDP ESPUdp;
IPAddress ComputerIP(0, 0, 0, 0);  
IPAddress localIP(0, 0, 0, 0);     
IPAddress Gateway(0, 0, 0, 0);
IPAddress Subnet(0, 0, 0, 0);
unsigned int myReceivePort = 0000;  
unsigned int mySendPort = 0000;     

WiFiClient ethclient;

// OSC settings
MicroOscUdp<1024> myMicroOsc(&ESPUdp, localIP, mySendPort);

void setup() 
{
  // Serial Monitor delay
  Serial.begin(115200);
  delay(2000);

  // start ethernet connection
  WiFi.onEvent(WiFiEvent);
  ETH.begin();
  ETH.config(localIP, Gateway, Subnet);
  if (eth_connected) {
    Serial.println("Ethernet Connected");
  }

  Serial.println(ETH.localIP());
  ESPUdp.begin(myReceivePort);
}

void loop() 
{
  myMicroOsc.onOscMessageReceived(myOnOscMessageReceived);

  if (millis() - myChronoStart >= 1000) //SEND OCS MESSAGE
  {  
    myChronoStart = millis();           

    myMicroOsc.sendInt("/send", 123);
  }
}

void myOnOscMessageReceived(MicroOscMessage& oscMessage) // RECEIVE OSC MESSAGE
{
  if (oscMessage.checkOscAddress("/receive")) 
  {
    int message = oscMessage.nextAsInt();
    Serial.println(message);
  }
}

// ethernet 
void WiFiEvent(WiFiEvent_t event) 
{
  switch (event) {
    case ARDUINO_EVENT_ETH_START:
      Serial.println("ETH Started");
      // set eth hostname here
      ETH.setHostname("esp32-ethernet");
      break;
    case ARDUINO_EVENT_ETH_CONNECTED:
      Serial.println("ETH Connected");
      break;
    case ARDUINO_EVENT_ETH_GOT_IP:
      Serial.print("ETH MAC: ");
      Serial.print(ETH.macAddress());
      Serial.print(", IPv4: ");
      Serial.print(ETH.localIP());
      if (ETH.fullDuplex()) {
        Serial.print(", FULL_DUPLEX");
      }
      Serial.print(", ");
      Serial.print(ETH.linkSpeed());
      Serial.println("Mbps");
      eth_connected = true;
      break;
    case ARDUINO_EVENT_ETH_DISCONNECTED:
      Serial.println("ETH Disconnected");
      eth_connected = false;
      break;
    case ARDUINO_EVENT_ETH_STOP:
      Serial.println("ETH Stopped");
      eth_connected = false;
      break;
    default:
      break;
  }
}
thomasfredericks commented 10 months ago

Hi, can you share an example Châtaigne projet to test?

UseruserOmar commented 10 months ago

Hi, thanks for you reply.

You can send a test message to the ESP32 via the command tester under the OCS module. Messages from the ESP32 to Chataigne should auto-add and be visible in the logger when something is received. You only have to fill in the Local Port, Remote Host and Remote Port in Chataigne. And fill in the following values in the code: IPAddress ComputerIP(0, 0, 0, 0); IPAddress localIP(0, 0, 0, 0); unsigned int myReceivePort = 0000; unsigned int mySendPort = 0000;

Chataigne_Github_Test.noisette.zip

thomasfredericks commented 10 months ago

Hi, again,

I noticed the 0.0.0.0 adresses in your code, but that is not a valid address. I believe certain libraries even consider it a null non-determined address.

Also, you are settings the computer and the ESP32 to the same address. If you are relying on Zeroconf, you have to code it in Arduino and set the proper IP adresses when they are determined.

UseruserOmar commented 10 months ago

Hi,

Yes that's correct I put them all on 0000 in this example code. But I will share the code and chataigne file again where I configured everything. I hope this makes it more clear.

Greetings!

Github.zip

thomasfredericks commented 10 months ago

In the following lines of code

// OSC settings
MicroOscUdp<1024> myMicroOsc(&ESPUdp, localIP, mySendPort);

should it not be ComputerIP instead of localIP?

It is confusing as your naming in not standard:

IPAddress ComputerIP(0, 0, 0, 0);  
IPAddress localIP(0, 0, 0, 0);     
unsigned int myReceivePort = 0000;  
unsigned int mySendPort = 0000; 

You would reduce confusion with the following naming convention:

IPAddress sendIP(0, 0, 0, 0);  
unsigned int sendPort = 0000; 
IPAddress myIP(0, 0, 0, 0);     
unsigned int myPort = 0000;  
UseruserOmar commented 10 months ago

Well look at this, everything works! I think I just completely missed that wrong setting. Thanks a lot for your time and tips! :)

Greetings, Omar