Help with using esp 32 to receive OSC msgs

Hi all, this is my first time posting anything on a forum so please forgive me if I posted this under the wrong topic or if my formatting is erroneous.

I have been trying to get my Node MCU- 32s (ESP 32) to receive osc messages from Processing. It is able to send OSC messages just fine, however I can't for the life of me get it to receive osc messages. If anyone can please help me, I will be eternally grateful.

I have checked the IP address that Processing is sending messages to and it seems accurate, I have checked the port number it is sending too and that is also fine. I have tried to make it such that processing sends osc messages to my computer and it is able to do that fine too, my computer is able to receive the osc messages fine. But for some reason, my esp 32 is unable to receive the osc messages.

Board: Node MCU-32s
Programme: Arduino IDE and Processing
Method of Communication: OSC

//assigning pins to switches and transistors
static const int Transistor1 = 19;
static const int Transistor2 = 18;
static const int Transistor3 = 5;
//static const int MomentarySwitch = 33;

static const int Switch21 = 34; //printed G14 on the board
static const int Switch22 = 35; //printed G14 on the board
static const int Switch23 = 32; //printed G14 on the board
static const int Switch24 = 33; //printed G14 on the board
static const int Switch25 = 25; //printed G14 on the board
static const int Switch26 = 26; //printed G14 on the board
static const int Switch27 = 27; //printed G14 on the board
static const int Switch28 = 14; //printed G14 on the board
static const int Switch29 = 12; //printed G14 on the board
static const int Switch30 = 13; //printed G14 on the board

//WIFI PART
#if defined(ESP8266)
#include <ESP8266WiFi.h>
#else
#include <WiFi.h>
#endif
#include <WiFiManager.h> 
#include <WiFiUdp.h>
#include <OSCMessage.h>
#include <OSCBundle.h>                 // for receiving OSC messages
#include <OSCData.h>

char ssid[] = "Shah";          // your network SSID (name)
char pass[] = "Shaherfi";                    // your network password

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



//variables sent and received by processing
int SwitchPath = 0;
int SwitchNumber = 0;


void setup() {
  // put your setup code here, to run once:

pinMode(Transistor1, OUTPUT);
pinMode(Transistor2, OUTPUT);
pinMode(Transistor3, OUTPUT);
//pinMode(MomentarySwitch, INPUT);
//
digitalWrite(Transistor1, LOW);
digitalWrite(Transistor2, LOW);
digitalWrite(Transistor3, LOW);

pinMode(Switch21, INPUT);// Pinmode for Switches
pinMode(Switch22, INPUT);
pinMode(Switch23, INPUT);
pinMode(Switch24, INPUT);
pinMode(Switch25, INPUT);
pinMode(Switch26, INPUT);
pinMode(Switch27, INPUT);
pinMode(Switch28, INPUT);
pinMode(Switch29, INPUT);
pinMode(Switch30, INPUT);

    // Specify a static IP address for NodeMCU - only needeed for receiving messages)
    // If you erase this line, your ESP8266 will get a dynamic IP address
    //WiFi.config(IPAddress(192,168,0,123),IPAddress(192,168,0,1), IPAddress(255,255,255,0)); 

Serial.begin(115200);



//WIFI Part
  // 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: ");
#ifdef ESP32
  Serial.println(localPort);
#else
  Serial.println(Udp.localPort());
#endif
}

SwitchTransistor2.ino (13.1 KB)

OSCControl.pde (3.36 KB)

void loop() {

  //Serial.println (SwitchNumber);
  // put your main code here, to run repeatedly:
//int MomentarySwitch_State_1 = digitalRead(MomentarySwitch);
//
//if (MomentarySwitch_State_1 == HIGH) {
//
//Serial.println("ON");
//  
//}

//  delay (1500);
//
//  Serial.println ("High");
//
//  digitalWrite(Transistor1, HIGH);
//
//  delay (3500);
//
//  Serial.println ("Low");
//
//  digitalWrite(Transistor1, LOW);
//
//  delay (1500);
//
//  Serial.println ("High2");
//
//  digitalWrite(Transistor2, HIGH);
//
//  delay (3500);
//
//  Serial.println ("Low2");
//
//  digitalWrite(Transistor2, LOW);
//
//    delay (1500);
//
//  Serial.println ("High3");
//
//  digitalWrite(Transistor3, HIGH);
//
//  delay (3500);
//
//  Serial.println ("Low3");
//
//  digitalWrite(Transistor3, LOW);

int Switch_State_21 = digitalRead(Switch21);
int Switch_State_22 = digitalRead(Switch22);
int Switch_State_23 = digitalRead(Switch23);
int Switch_State_24 = digitalRead(Switch24);
int Switch_State_25 = digitalRead(Switch25);
int Switch_State_26 = digitalRead(Switch26);
int Switch_State_27 = digitalRead(Switch27);
int Switch_State_28 = digitalRead(Switch28);
int Switch_State_29 = digitalRead(Switch29);
int Switch_State_30 = digitalRead(Switch30);


if ( Switch_State_21 == LOW )
  {
    //Serial.println ("On21");
    digitalWrite(Transistor1, LOW);
  }else

if ( Switch_State_21 == HIGH )
  {
    Serial.println ("On21");
    digitalWrite(Transistor1, HIGH);
  }
  

if ( Switch_State_22 == LOW )
  {
    //Serial.println ("On22");
    digitalWrite(Transistor2, LOW);
  }else

if ( Switch_State_22 == HIGH )
  {
    Serial.println ("On22");
    digitalWrite(Transistor2, HIGH);
  }
  

if ( Switch_State_23 == LOW )
  {
    //Serial.println ("On23");
    digitalWrite(Transistor3, LOW);
  }else

if ( Switch_State_23 == HIGH )
  {
    Serial.println ("On23");
    digitalWrite(Transistor3, HIGH);

if (Switch_State_21 == HIGH && Switch_State_22 == LOW && Switch_State_23 == LOW && Switch_State_24 == LOW && Switch_State_25 == LOW && Switch_State_26 == LOW && Switch_State_27 == LOW && Switch_State_28 == LOW && Switch_State_29 == LOW && Switch_State_30 == LOW){
    
    SwitchNumber =21;
   }

SwitchTransistor2.ino (13.1 KB)

OSCControl.pde (3.36 KB)

if (Switch_State_21 == LOW && Switch_State_22 == HIGH && Switch_State_23 == LOW && Switch_State_24 == LOW && Switch_State_25 == LOW && Switch_State_26 == LOW && Switch_State_27 == LOW && Switch_State_28 == LOW && Switch_State_29 == LOW && Switch_State_30 == LOW){
    
    SwitchNumber =22;
   }

if (Switch_State_21 == LOW && Switch_State_22 == LOW && Switch_State_23 == HIGH && Switch_State_24 == LOW && Switch_State_25 == LOW && Switch_State_26 == LOW && Switch_State_27 == LOW && Switch_State_28 == LOW && Switch_State_29 == LOW && Switch_State_30 == LOW){
    
    SwitchNumber =23;
   }

if (Switch_State_21 == LOW && Switch_State_22 == LOW && Switch_State_23 == LOW && Switch_State_24 == HIGH && Switch_State_25 == LOW && Switch_State_26 == LOW && Switch_State_27 == LOW && Switch_State_28 == LOW && Switch_State_29 == LOW && Switch_State_30 == LOW){
    
    SwitchNumber =24;
   }

if (Switch_State_21 == LOW && Switch_State_22 == LOW && Switch_State_23 == LOW && Switch_State_24 == LOW && Switch_State_25 == HIGH && Switch_State_26 == LOW && Switch_State_27 == LOW && Switch_State_28 == LOW && Switch_State_29 == LOW && Switch_State_30 == LOW){
    
    SwitchNumber =25;
   }

if (Switch_State_21 == LOW && Switch_State_22 == LOW && Switch_State_23 == LOW && Switch_State_24 == LOW && Switch_State_25 == LOW && Switch_State_26 == HIGH && Switch_State_27 == LOW && Switch_State_28 == LOW && Switch_State_29 == LOW && Switch_State_30 == LOW){
    
    SwitchNumber =26;
   }

if (Switch_State_21 == LOW && Switch_State_22 == LOW && Switch_State_23 == LOW && Switch_State_24 == LOW && Switch_State_25 == LOW && Switch_State_26 == LOW && Switch_State_27 == HIGH && Switch_State_28 == LOW && Switch_State_29 == LOW && Switch_State_30 == LOW){
    
    SwitchNumber =27;
   }

if (Switch_State_21 == LOW && Switch_State_22 == LOW && Switch_State_23 == LOW && Switch_State_24 == LOW && Switch_State_25 == LOW && Switch_State_26 == LOW && Switch_State_27 == LOW && Switch_State_28 == HIGH && Switch_State_29 == LOW && Switch_State_30 == LOW){
    
    SwitchNumber =28;
   }

if (Switch_State_21 == LOW && Switch_State_22 == LOW && Switch_State_23 == LOW && Switch_State_24 == LOW && Switch_State_25 == LOW && Switch_State_26 == LOW && Switch_State_27 == LOW && Switch_State_28 == LOW && Switch_State_29 == HIGH && Switch_State_30 == LOW){
    
    SwitchNumber =29;
   }

if (Switch_State_21 == LOW && Switch_State_22 == LOW && Switch_State_23 == LOW && Switch_State_24 == LOW && Switch_State_25 == LOW && Switch_State_26 == LOW && Switch_State_27 == LOW && Switch_State_28 == LOW && Switch_State_29 == LOW && Switch_State_30 == HIGH){
    
    SwitchNumber =30;
   }

if (Switch_State_21 == LOW && Switch_State_22 == LOW && Switch_State_23 == LOW && Switch_State_24 == LOW && Switch_State_25 == LOW && Switch_State_26 == LOW && Switch_State_27 == LOW && Switch_State_28 == LOW && Switch_State_29 == LOW && Switch_State_30 == LOW){
    
    SwitchNumber =0;
   }



//SwitchPath Controller

if (Switch_State_21 == HIGH && Switch_State_22 == LOW && Switch_State_23 == LOW && Switch_State_24 == LOW && Switch_State_25 == LOW && Switch_State_26 == LOW && Switch_State_27 == LOW && Switch_State_28 == LOW && Switch_State_29 == LOW && Switch_State_30 == LOW){
    
    SwitchPath = 21;
    
    Serial.println (SwitchPath);
   }

if (Switch_State_21 == HIGH && Switch_State_22 == LOW && Switch_State_23 == LOW && Switch_State_24 == HIGH && Switch_State_25 == LOW && Switch_State_26 == LOW && Switch_State_27 == LOW && Switch_State_28 == LOW && Switch_State_29 == LOW && Switch_State_30 == LOW){
    
    SwitchPath = 22;
    
    Serial.println (SwitchPath);
   }

if (Switch_State_21 == HIGH && Switch_State_22 == LOW && Switch_State_23 == HIGH && Switch_State_24 == LOW && Switch_State_25 == LOW && Switch_State_26 == LOW && Switch_State_27 == LOW && Switch_State_28 == LOW && Switch_State_29 == LOW && Switch_State_30 == LOW){
    
    SwitchPath = 23;
    
    Serial.println (SwitchPath);
   }

if (Switch_State_21 == HIGH && Switch_State_22 == HIGH && Switch_State_23 == LOW && Switch_State_24 == LOW && Switch_State_25 == LOW && Switch_State_26 == LOW && Switch_State_27 == LOW && Switch_State_28 == LOW && Switch_State_29 == LOW && Switch_State_30 == LOW){
    
    SwitchPath = 24;
    
    Serial.println (SwitchPath);
   }       


if (Switch_State_21 == HIGH && Switch_State_22 == LOW && Switch_State_23 == LOW && Switch_State_24 == HIGH && Switch_State_25 == HIGH && Switch_State_26 == LOW && Switch_State_27 == LOW && Switch_State_28 == LOW && Switch_State_29 == LOW && Switch_State_30 == LOW){
    
    SwitchPath = 25;
    
    Serial.println (SwitchPath);
   } 


if (Switch_State_21 == HIGH && Switch_State_22 == LOW && Switch_State_23 == LOW && Switch_State_24 == HIGH && Switch_State_25 == LOW && Switch_State_26 == HIGH && Switch_State_27 == LOW && Switch_State_28 == LOW && Switch_State_29 == LOW && Switch_State_30 == LOW){
    
    SwitchPath = 26;
    
    Serial.println (SwitchPath);
   } 

if (Switch_State_21 == HIGH && Switch_State_22 == LOW && Switch_State_23 == HIGH && Switch_State_24 == LOW && Switch_State_25 == LOW && Switch_State_26 == LOW && Switch_State_27 == HIGH && Switch_State_28 == LOW && Switch_State_29 == LOW && Switch_State_30 == LOW){
    
    SwitchPath = 27;
    
    Serial.println (SwitchPath);
   }

if (Switch_State_21 == HIGH && Switch_State_22 == LOW && Switch_State_23 == HIGH && Switch_State_24 == LOW && Switch_State_25 == LOW && Switch_State_26 == LOW && Switch_State_27 == LOW && Switch_State_28 == HIGH && Switch_State_29 == LOW && Switch_State_30 == LOW){
    
    SwitchPath = 28;
    
    Serial.println (SwitchPath);
   }

if (Switch_State_21 == HIGH && Switch_State_22 == HIGH && Switch_State_23 == LOW && Switch_State_24 == LOW && Switch_State_25 == LOW && Switch_State_26 == LOW && Switch_State_27 == LOW && Switch_State_28 == LOW && Switch_State_29 == HIGH && Switch_State_30 == LOW){
    
    SwitchPath = 29;
    
    Serial.println (SwitchPath);
   }

if (Switch_State_21 == HIGH && Switch_State_22 == HIGH && Switch_State_23 == LOW && Switch_State_24 == LOW && Switch_State_25 == LOW && Switch_State_26 == LOW && Switch_State_27 == LOW && Switch_State_28 == LOW && Switch_State_29 == LOW && Switch_State_30 == HIGH){
    
    SwitchPath = 30;
    
    Serial.println (SwitchPath);
   }

if (Switch_State_21 == LOW && Switch_State_22 == LOW && Switch_State_23 == LOW && Switch_State_24 == LOW && Switch_State_25 == LOW && Switch_State_26 == LOW && Switch_State_27 == LOW && Switch_State_28 == LOW && Switch_State_29 == LOW && Switch_State_30 == LOW){
    
    SwitchPath = 0;
    
   }
// and of switches part.


 OSCMessage msg("/SwitchController2");
  msg.add(SwitchPath);
  msg.add(SwitchNumber);
  Udp.beginPacket(outIp, outPort);
  msg.send(Udp);
  Udp.endPacket();
  msg.empty();

  OSCMsgReceive();
      
}



// function meant to receive osc messages but doesnt seem to be working
void OSCMsgReceive(){
  OSCBundle msgIN;
  int size;
  if((size = Udp.parsePacket())>0){
    while(size--)
      msgIN.fill(Udp.read());
      msgIN.route("/UnitySwitchBoard",RecieveMsgTest);
    if(!msgIN.hasError()){
      msgIN.route("/UnitySwitchBoard",RecieveMsgTest);
    }
  }
}

// function called in OSCMsgReceive, but doesnt seem to be working, nothing is being Serial.println
void RecieveMsgTest(OSCMessage &msg, int addrOffset){
  SwitchPath = msg.getInt(0);
  Serial.println("Recieving :" + SwitchPath);
}

Are all nodes in the same IP range? That is, they all must have the same first three numbers in their IP addresses (when the subnetmask is 255.255.255.0).

10.27.243.230 will never communicate with 192.168.0.124 !

code on processing

import netP5.*;
import oscP5.*;

OscP5 oscP5;
NetAddress myRemoteLocation;
NetAddress myRemoteLocation2;
NetAddress testmyRemoteLocation3;

void setup () {
size(600,600);
background(0);

oscP5 = new OscP5(this,8888);  //  <<<<<<<<<<<<Port number

/* you must find your UUID and match it below */
//oscP5.plug(this, "Controller1AccelGyro", "/Controller1AccelGyro");
oscP5.plug(this, "Controller1Btn", "/Controller1Btn");
oscP5.plug(this, "ControllerJoystickandAccelerometer", "/Controller1AccelGyroJoyStick");
oscP5.plug(this, "ControllerJoystick", "/Controller1Joystick");
oscP5.plug(this, "WekiJoystickRotateRight", "/wekiJoystickRotate-1_1");
oscP5.plug(this, "WekiJoystickRotateLeft", "/wekiJoystickRotate-1_2");
oscP5.plug(this, "SwitchBoard", "/SwitchController");
oscP5.plug(this, "SwitchBoard2", "/SwitchController2");

//Wekinator Port is 7777
//Unity Port is 9999
//This Port is 8888
myRemoteLocation = new NetAddress("192,168,236,159",9999);
myRemoteLocation2 = new NetAddress("192,168,236,159",7777);
testmyRemoteLocation3 = new NetAddress("192,168,236,118",5555);

}

void draw() {
}

// accepts controller button values and sends them to unity
void Controller1Btn (int x) {
  OscMessage myMessage = new OscMessage("/UnityController1Btn");
  
  int ButtonPressed = x;
  //println(ButtonPressed);
  myMessage.add(ButtonPressed);
  oscP5.send(myMessage, myRemoteLocation);
}

//accepts joystick and Accelrometer values and sends them to wekinator
void ControllerJoystickandAccelerometer (float gForceX, float gForceY, float gForceZ, float rotX, float rotY, float rotZ, int Jx, int Jy, int Js) {
  OscMessage myMessage3 = new OscMessage("/WekiControllerJoyStick");
  
  float wekiJx  = map(Jx, 0, 4095, 0, 1);
  float wekiJy  = map(Jy, 0, 4095, 0, 1);
  float wekiJs  = map(Js, 0, 4095, 0, 1);
  myMessage3.add(wekiJx);
  myMessage3.add(wekiJy);
  myMessage3.add(wekiJs);
  //println(wekiJx);
  oscP5.send(myMessage3, myRemoteLocation2);
}

void ControllerJoystick (int x) {
  OscMessage myMessage4 = new OscMessage("/WekiControllerJoyStick2");
  
  float wekiJDirection  = map(x, 0, 9, 0, 1);
  myMessage4.add(wekiJDirection);
  oscP5.send(myMessage4, myRemoteLocation2);
  //println(wekiJDirection);
}

void WekiJoystickRotateRight () {
  OscMessage myMessage5 = new OscMessage("/unity/PanRotateRight");
  
  float x = 1.0f;
  myMessage5.add(x);
  oscP5.send(myMessage5, myRemoteLocation);
  println("RotateRight");
}

void WekiJoystickRotateLeft () {
  OscMessage myMessage5 = new OscMessage("/unity/PanRotateLeft");
  
  float x = 2.0f;
  myMessage5.add(x);
  oscP5.send(myMessage5, myRemoteLocation);
  println("RotateLeft");
}

// accepts switchboard values and sends them over to unity
void SwitchBoard (int x, int y) {
  OscMessage myMessage2 = new OscMessage("/UnitySwitchBoard");
  
  int SwitchPath = x;
  int SwitchNumber = y;
  println("SwitchPath" + SwitchPath);
  myMessage2.add(SwitchPath);
  myMessage2.add(SwitchNumber);
  oscP5.send(myMessage2, myRemoteLocation);
}


// this is the function meant to send the osc messages back to the esp 32
void SwitchBoard2 (int x, int y) {
  OscMessage myMessage2 = new OscMessage("/UnitySwitchBoard");
  
  int SwitchPath = x;
  int SwitchNumber = y;
  println("SwitchPath" + SwitchPath);
  myMessage2.add(SwitchPath);
  myMessage2.add(SwitchNumber);
  //oscP5.send(myMessage2, myRemoteLocation);
  oscP5.send(myMessage2, testmyRemoteLocation3);
}

Erik_Baas:
Are all nodes in the same IP range? That is, they all must have the same first three numbers in their IP addresses (when the subnetmask is 255.255.255.0).

10.27.243.230 will never communicate with 192.168.0.124 !

I have tried changing it an it still doesnt work. I have changes it such that my computer and esp 32 is connected to my mobile hotspot instead, and that has changed my computer ip address to 192.168.236.159 , but it still doesnt work :CCCCCC

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.