PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

88 lines
2.2KB

  1. /*---------------------------------------------------------------------------------------------
  2. Open Sound Control (OSC) library for the ESP8266
  3. Example for receiving open sound control (OSC) bundles on the ESP8266
  4. Send integers '0' or '1' to the address "/led" to turn on/off the built-in LED of the esp8266.
  5. This example code is in the public domain.
  6. --------------------------------------------------------------------------------------------- */
  7. #include <ESP8266WiFi.h>
  8. #include <WiFiUdp.h>
  9. #include <OSCMessage.h>
  10. #include <OSCBundle.h>
  11. #include <OSCData.h>
  12. char ssid[] = "*****************"; // your network SSID (name)
  13. char pass[] = "*******"; // your network password
  14. // A UDP instance to let us send and receive packets over UDP
  15. WiFiUDP Udp;
  16. const IPAddress outIp(10,40,10,105); // remote IP (not needed for receive)
  17. const unsigned int outPort = 9999; // remote port (not needed for receive)
  18. const unsigned int localPort = 8888; // local port to listen for UDP packets (here's where we send the packets)
  19. OSCErrorCode error;
  20. unsigned int ledState = LOW; // LOW means led is *on*
  21. void setup() {
  22. pinMode(BUILTIN_LED, OUTPUT);
  23. digitalWrite(BUILTIN_LED, ledState); // turn *on* led
  24. Serial.begin(115200);
  25. // Connect to WiFi network
  26. Serial.println();
  27. Serial.println();
  28. Serial.print("Connecting to ");
  29. Serial.println(ssid);
  30. WiFi.begin(ssid, pass);
  31. while (WiFi.status() != WL_CONNECTED) {
  32. delay(500);
  33. Serial.print(".");
  34. }
  35. Serial.println("");
  36. Serial.println("WiFi connected");
  37. Serial.println("IP address: ");
  38. Serial.println(WiFi.localIP());
  39. Serial.println("Starting UDP");
  40. Udp.begin(localPort);
  41. Serial.print("Local port: ");
  42. Serial.println(Udp.localPort());
  43. }
  44. void led(OSCMessage &msg) {
  45. ledState = msg.getInt(0);
  46. digitalWrite(BUILTIN_LED, ledState);
  47. Serial.print("/led: ");
  48. Serial.println(ledState);
  49. }
  50. void loop() {
  51. OSCBundle bundle;
  52. int size = Udp.parsePacket();
  53. if (size > 0) {
  54. while (size--) {
  55. bundle.fill(Udp.read());
  56. }
  57. if (!bundle.hasError()) {
  58. bundle.dispatch("/led", led);
  59. } else {
  60. error = bundle.getError();
  61. Serial.print("error: ");
  62. Serial.println(error);
  63. }
  64. }
  65. }