ESP8266sendMessage.ino 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*---------------------------------------------------------------------------------------------
  2. Open Sound Control (OSC) library for the ESP8266/ESP32
  3. Example for sending messages from the ESP8266/ESP32 to a remote computer
  4. The example is sending "hello, osc." to the address "/test".
  5. This example code is in the public domain.
  6. --------------------------------------------------------------------------------------------- */
  7. #if defined(ESP8266)
  8. #include <ESP8266WiFi.h>
  9. #else
  10. #include <WiFi.h>
  11. #endif
  12. #include <WiFiUdp.h>
  13. #include <OSCMessage.h>
  14. char ssid[] = "*****************"; // your network SSID (name)
  15. char pass[] = "*******"; // your network password
  16. WiFiUDP Udp; // A UDP instance to let us send and receive packets over UDP
  17. const IPAddress outIp(10,40,10,105); // remote IP of your computer
  18. const unsigned int outPort = 9999; // remote port to receive OSC
  19. const unsigned int localPort = 8888; // local port to listen for OSC packets (actually not used for sending)
  20. void setup() {
  21. Serial.begin(115200);
  22. // Connect to WiFi network
  23. Serial.println();
  24. Serial.println();
  25. Serial.print("Connecting to ");
  26. Serial.println(ssid);
  27. WiFi.begin(ssid, pass);
  28. while (WiFi.status() != WL_CONNECTED) {
  29. delay(500);
  30. Serial.print(".");
  31. }
  32. Serial.println("");
  33. Serial.println("WiFi connected");
  34. Serial.println("IP address: ");
  35. Serial.println(WiFi.localIP());
  36. Serial.println("Starting UDP");
  37. Udp.begin(localPort);
  38. Serial.print("Local port: ");
  39. #ifdef ESP32
  40. Serial.println(localPort);
  41. #else
  42. Serial.println(Udp.localPort());
  43. #endif
  44. }
  45. void loop() {
  46. OSCMessage msg("/test");
  47. msg.add("hello, osc.");
  48. Udp.beginPacket(outIp, outPort);
  49. msg.send(Udp);
  50. Udp.endPacket();
  51. msg.empty();
  52. delay(500);
  53. }