Receive & Send OSC data to ESP 32

Hi,
Thank you very much.
I have not tried yet to send data from WIFI and the serial monitor (for example) because I would like to send directly OSC datas with the ESP32
And later receive OSC datas into ESP32.
I mixed my program with your but I have an error like that

  /Users/oslive/Documents/Arduino/hardware/WiFi_Kit_series/oscTestQuBits/oscTestQuBits.ino: In function 'void setup()':
  /Users/oslive/Documents/Arduino/hardware/WiFi_Kit_series/oscTestQuBits/oscTestQuBits.ino:77:22: error: 'class WiFiUDP' has no member named 'localPort'
   exit status 1
   Compilation error: 'class WiFiUDP' has no member named 'localPort'
   //__

Can you try if you see something please ?

// ESP32 UDP client sending datagrams to a UDP server

//  from https://github.com/evothings/evothings-examples/blob/master/examples/arduino-led-onoff-tcp/arduinowifi/arduinowifi/arduinowifi.ino

#include <WiFi.h>
#include <WiFiUdp.h>
#include <OSCMessage.h>

WiFiUDP Udp; 

const unsigned int outPort = 8000;          // remote port to receive OSC
const unsigned int localPort = 8001;        // local port to listen for OSC packets (actually not used for sending)




// network SSID (network name). and network password.
//char ssid[] = "****";
//char pass[] = "****";


char ssid[] = "SFR-d078"; // your network SSID (name)
char pass[] = "DEDW3VPARYGZ";  // your network password



// network key Index number (needed only for WEP).
int keyIndex = 0;

// UDP information
//local broadcast address..
IPAddress udpServer(192, 168, 0, 255);
IPAddress outIp(127, 0, 0, 1); //127.0.0.1
#define UDP_PORT 8002
WiFiUDP udp;

// UDP Datagram
struct __attribute__((packed)) UDPDatagram {
  uint16_t seq;                          // sequence number
  int16_t sdata;                         // 16 bit integer data
  int32_t idata;                         // 32 bit integer data
  float fdata;                           // float data
  uint16_t crc;                          // crc check
} udpDatagram = { 0, 10, 10, 3.14, 0 };  // initial values

void setup() {
  Serial.begin(115200);
  // Wait for serial port to connect. Needed for Leonardo only
  while (!Serial)
    ;
  delay(1000);
  Serial.println();
  Serial.println("ESP32 WiFi UDP client - send UDP datagrams to server");
  WiFi.mode(WIFI_STA);  // Connect to Wifi network.
  WiFi.begin(ssid, pass);
  Serial.println("");
  // Wait for connection
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.print("\nserver IP address: ");
  Serial.println(udpServer);
  udp.begin(UDP_PORT);
  Serial.print("server udp port ");
  Serial.println(UDP_PORT);


  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(localPort)); // bug
 

}

void loop() {
  // generate crc check - in this case a simple checksum
  udpDatagram.crc = 0;
  Serial.print("Datagram data ");
  for (int i = 0; i < sizeof(udpDatagram) - 2; i++) {
    Serial.print((uint8_t)((uint8_t *)&udpDatagram)[i], HEX);
    Serial.print(' ');
    udpDatagram.crc += ((uint8_t *)&udpDatagram)[i];
  }

    OSCMessage msg("/pongo");
  msg.add(65);
 // msg.add("hello");
 // msg.add(fnum);
  Udp.beginPacket(outIp, outPort);
  msg.send(Udp);
  Udp.endPacket();
  msg.empty();

  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(localPort);   

  // Send Packet to UDP server
  udp.beginPacket(udpServer.toString().c_str(), UDP_PORT);
  int len = udp.write((const uint8_t *)&udpDatagram, sizeof(udpDatagram));
  udp.endPacket();
  Serial.print("\nudp datagram transmitted length ");
  Serial.print(len);
  Serial.print(" seq ");
  Serial.print(udpDatagram.seq++);
  Serial.print(" sdata ");
  Serial.print(udpDatagram.sdata);
  Serial.print(" idata ");
  Serial.print(udpDatagram.idata);
  Serial.print(" fdata ");
  Serial.print(udpDatagram.fdata);
  Serial.print(" crc = ");
  Serial.println(udpDatagram.crc);
  udpDatagram.crc = 0;  // update data values for tests
  udpDatagram.sdata += 10;
  udpDatagram.idata += 25;
  udpDatagram.fdata += 5.0f;
  delay(10000);
}

I moved your topic to an appropriate forum category @bvking.

In the future, please take some time to pick the forum category that best suits the subject of your topic. There is an "About the _____ category" topic at the top of each category that explains its purpose.

This is an important part of responsible forum usage, as explained in the "How to get the best out of this forum" guide. The guide contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.

thank you

You can add some serial prints during setup to see what ip your esp was assigned..
Would like this..


void setup() {
  Serial.begin(115200);
  pinMode(LED_BUILTIN, OUTPUT);
  pinMode(led, OUTPUT);
  /* setup wifi */
  WiFi.begin(ssid, pass);
  Serial.println("Wfifi connecting");
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print(".");
    delay(500);
  }

  Serial.println("");
  Serial.print("Connected to ");
  Serial.println(ssid);
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());

  Udp.begin(localPort);
}

use the serial monitor, make sure baud rate is set correctly and you should see it connect and report its ip..

that's a strange ip you're sending too??
never used OSCMessage before, looks like udp..

did some udp examples..
UDP Send
there's a receiver in the git too..

have fun..~q

I am not clear about your objectives -- what do you want to achieve?

You want to turn ON and turn OFF the LED (connected at GPIO-26) --
1. from your Smart Phone via your Home Router?

or

2. from the InputBox of the Serial Monitor of Arduino IDE?

or

3. What?

IPAddress local_IP(192, 168, 1, 2);
// Maybe you can set local ip then you can continue
void setup() {
  Serial.begin(115200);
  pinMode(LED_BUILTIN, OUTPUT);
  pinMode(led, OUTPUT);
  /* setup wifi */
  WiFi.begin(ssid, pass);
  Serial.println("Wfifi connecting");
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print(".");
    delay(500);
  }

  Serial.println("");
  Serial.print("Connected to ");
  Serial.println(ssid);
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP()); // 192.168.1.2 

  Udp.begin(localPort);
}

or if you want to learn mac adresse:

  #include <WiFi.h>

void setup(){
  Serial.begin(115200);
  Serial.println();
  Serial.print("ESP Board MAC Address:  ");
  Serial.println(WiFi.macAddress());
}
 
void loop(){

}

Hi,

Yes it's exactly I would like to do!

Hello.
I tryed to run the supercollider program (that I have just discover) from your link with the Arduino program but I have this messager error.
Can you tell me what to please?

-> an EventStreamPlayer
ERROR: Message 'sendMsg' not understood.
RECEIVER:
   nil
ARGS:
Instance of String {    (0x1404a7788, gc=A8, fmt=07, flg=10, set=02)
  indexed slots [4]
      0 : /
      1 : l
      2 : e
      3 : d
}
   Integer 1

PROTECTED CALL STACK:
	Meta_MethodError:new	0x128347480
		arg this = DoesNotUnderstandError
		arg what = nil
		arg receiver = nil
	Meta_DoesNotUnderstandError:new	0x1283497c0
		arg this = DoesNotUnderstandError
		arg receiver = nil
		arg selector = sendMsg
		arg args = [ /led, 1 ]
	Object:doesNotUnderstand	0x140093580
		arg this = nil
		arg selector = sendMsg
		arg args = nil
	a FunctionDef	0x1584e9800
		sourceCode = "<an open Function>"
	Function:prTry	0x128625200
		arg this = a Function
		var result = nil
		var thread = a Routine
		var next = nil
		var wasInProtectedFunc = true
	
CALL STACK:
	DoesNotUnderstandError:reportError
		arg this = <instance of DoesNotUnderstandError>
	Nil:handleError
		arg this = nil
		arg error = <instance of DoesNotUnderstandError>
	Thread:handleError
		arg this = <instance of Thread>
		arg error = <instance of DoesNotUnderstandError>
	Thread:handleError
		arg this = <instance of Routine>
		arg error = <instance of DoesNotUnderstandError>
	Object:throw
		arg this = <instance of DoesNotUnderstandError>
	Function:protect
		arg this = <instance of Function>
		arg handler = <instance of Function>
		var result = <instance of DoesNotUnderstandError>
	Routine:prStart
		arg this = <instance of Routine>
		arg inval = 12961.82271025
^^ ERROR: Message 'sendMsg' not understood.
RECEIVER: nil

my link?? supercollider, cool, but not mine, sorry..
looks like python code??
probably won't be of much help there either, haven't learned it as of yet..

good luck.. ~q

sorry, I was wrong . Your program works very well to send data over wifi. Now I'm looking to receive data in OSC. Do you perhaps have a link to guide me?

Never heard of this before, sounds like a disorder they have pills for, sorry..
You didn't find any of the libs examples of any use..
OSC Examples

If you're stuck on something specific then let us know..

good luck.. ~q

it's ok. I use the second example of osc library and it works.
Now I hope to send to 10 esp32 between 1 to 10 and ten orc message to control 1 to 10 led strip, I hope ESP 32 will have enough RAM to do that.

Good, glad you got something kicking..
and esp32 has boat loads of ram should be ok..

~q