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.

101 lines
1.8 KiB

3 years ago
  1. /// READ OSC MESSAGES ///
  2. #include <WiFiUdp.h>
  3. #include <OSCMessage.h>
  4. bool light = false;
  5. bool fog = false;
  6. int humidityctrl = 80;
  7. bool fogstate = false;
  8. bool prevfogstate = false;
  9. WiFiUDP Udp; // A UDP instance to let us send and receive packets over UDP
  10. // const IPAddress dest(192, 168, 8, 255);
  11. const unsigned int rxport = 54321; // remote port to receive OSC
  12. const unsigned int txport = 12345; // local port to listen for OSC packets (actually not used for sending)
  13. void on_light(OSCMessage &msg, int addrOffset) {
  14. int lighton;
  15. if(msg.isFloat(0)){
  16. lighton = msg.getFloat(0);
  17. }
  18. if (lighton){
  19. light = true ;
  20. }else{
  21. light = false;
  22. }
  23. }
  24. ////////////////////////////////
  25. ///////////////////////////////
  26. void on_fog(OSCMessage &msg, int addrOffset) {
  27. int fogon;
  28. if(msg.isFloat(0)){
  29. fogon = msg.getFloat(0);
  30. }
  31. if (fogon){
  32. fog = true ;
  33. }else{
  34. fog = false ;
  35. }
  36. }
  37. void on_humidity(OSCMessage &msg, int addrOffset) {
  38. int humidityon;
  39. if(msg.isFloat(0)){
  40. humidityon = msg.getFloat(0);
  41. }
  42. humidityctrl = int(humidityon);
  43. }
  44. ////////////////////////////////
  45. ///////////////////////////////
  46. void osc_message_pump() {
  47. OSCMessage in;
  48. int size;
  49. if( (size = Udp.parsePacket()) > 0)
  50. {
  51. Serial.println("processing OSC package");
  52. // parse incoming OSC message
  53. while(size--) {
  54. in.fill( Udp.read() );
  55. }
  56. if(!in.hasError()) {
  57. in.route("/light", on_light);
  58. in.route("/fog", on_fog);
  59. in.route("/humidity", on_humidity);
  60. }
  61. Serial.println("OSC MESSAGE RECEIVED");
  62. // Serial.println (light);
  63. // Serial.println (fog);
  64. }
  65. }
  66. ///////////////////////////////