OscEthernet.ino 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #include <ArduinoOSC.h>
  2. // Ethernet stuff
  3. const IPAddress ip(192, 168, 1, 201);
  4. uint8_t mac[] = {0xAB, 0xCD, 0xEF, 0x01, 0x23, 0x45};
  5. // for ArduinoOSC
  6. OscEthernet osc;
  7. const char* host = "192.168.1.200";
  8. const int recv_port = 10000;
  9. const int send_port = 12000;
  10. void onOscReceived(OscMessage& m)
  11. {
  12. Serial.print("callback : ");
  13. Serial.print(m.ip()); Serial.print(" ");
  14. Serial.print(m.port()); Serial.print(" ");
  15. Serial.print(m.size()); Serial.print(" ");
  16. Serial.print(m.address()); Serial.print(" ");
  17. Serial.print(m.arg<int>(0)); Serial.print(" ");
  18. Serial.print(m.arg<float>(1)); Serial.print(" ");
  19. Serial.print(m.arg<String>(2)); Serial.println();
  20. }
  21. void setup()
  22. {
  23. Serial.begin(115200);
  24. // Ethernet stuff
  25. Ethernet.begin(mac, ip);
  26. // ArduinoOSC
  27. osc.begin(recv_port);
  28. // TODO: TBD
  29. // osc.subscribe("/int32", i);
  30. // osc.subscribe("/float", f);
  31. // osc.subscribe("/string", s);
  32. // osc.subscribe("/blob", b);
  33. osc.subscribe("/callback", onOscReceived); // old style (v0.1.x)
  34. osc.subscribe("/lambda", [](OscMessage& m)
  35. {
  36. Serial.print("lambda : ");
  37. Serial.print(m.ip()); Serial.print(" ");
  38. Serial.print(m.port()); Serial.print(" ");
  39. Serial.print(m.size()); Serial.print(" ");
  40. Serial.print(m.address()); Serial.print(" ");
  41. Serial.print(m.arg<int>(0)); Serial.print(" ");
  42. Serial.print(m.arg<float>(1)); Serial.print(" ");
  43. Serial.print(m.arg<String>(2)); Serial.println();
  44. });
  45. osc.subscribe("/wildcard/*/test", [](OscMessage& m)
  46. {
  47. Serial.print("wildcard : ");
  48. Serial.print(m.ip()); Serial.print(" ");
  49. Serial.print(m.port()); Serial.print(" ");
  50. Serial.print(m.size()); Serial.print(" ");
  51. Serial.print(m.address()); Serial.print(" ");
  52. Serial.print(m.arg<int>(0)); Serial.println();
  53. });
  54. osc.subscribe("/need/reply", [](OscMessage& m)
  55. {
  56. Serial.println("/need/reply");
  57. int i = 12;
  58. float f = 34.56F;
  59. double d = 78.987;
  60. String s = "hello";
  61. bool b = true;
  62. osc.send(host, send_port, "/send", i, f, d, s, b);
  63. });
  64. // TODO: TBD
  65. // osc.publish(host, send_port, "/value", value);
  66. // osc.publish(host, send_port, "/millis", &millis);
  67. }
  68. void loop()
  69. {
  70. osc.parse(); // should be called
  71. }