123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- #include <WiFiUdp.h>
- #include <OSCMessage.h>
- WiFiUDP UDP;
- IPAddress ipMulti(239, 0, 0, 56);
- unsigned int portMulti = 12345;
- template <typename TYPE> void sendOSC(const char * adress, TYPE parameter);
- template <typename TYPE> void sendOSC(const char * adress, TYPE parameter) {
- OSCMessage OSCmsg(adress);
- OSCmsg.add(parameter);
- UDP.beginPacketMulticast(ipMulti, portMulti,WiFi.localIP());
- OSCmsg.send(UDP);
- UDP.endPacket();
- OSCmsg.empty();
- }
- void printTest(OSCMessage &msg) {
-
- Serial.print("OSC type : ");
- Serial.println (msg.getType(0));
- sendOSC("/received", (int) msg.getType(0));
-
-
- }
- void updatePotValue(OSCMessage &msg) {
-
- potValueUpdate[msg.getInt(0)] = msg.getInt(1);
- sendOSC("/updated", "pot" );
-
- Serial.println (potValueUpdate[msg.getInt(0)]);
- }
- void setup_OSC(){
-
- ipMulti.fromString(UDP_IP);
-
- String UDP_PORT_string = UDP_PORT;
- portMulti = UDP_PORT_string.toInt();
- Serial.print("connecting udp to ");
- Serial.print(ipMulti);
- Serial.print(":");
- Serial.println(portMulti);
-
- UDP.beginMulticast(WiFi.localIP(), ipMulti, portMulti);
- sendOSC("/connected", 1);
- }
- void handle_OSC() {
- OSCMessage OSCin;
- int size;
- if ( (size = UDP.parsePacket()) > 0) {
- while (size--)
- OSCin.fill(UDP.read());
-
- if (!OSCin.hasError()) {
- OSCin.dispatch("/test", printTest);
- if (OSCin.match(ESP_NAME)){
- Serial.println("matched");
- OSCin.dispatch("/ESP_TENS_*/pot", updatePotValue);
-
-
- }
- }
- }
- }
|