ESP_UKI.ino 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. ESP_UKI
  3. TODO : clean webserver
  4. add uki configuration/information page (player number, ADC value, IP of main computer)
  5. send ADC to default IP via udp, allow configuration
  6. ajout numéro de firmware sur webserver
  7. */
  8. #include "includes.h" //headers and variables declaration
  9. /* UKI udp configuration */
  10. int UKI_UDP_In_Port = 9000; //udp port input for ESP
  11. IPAddress UKI_UDP_Master_IP(192, 168, 0, 41); //default udp address to send to. Will automatically change to the ip sending something to udp in
  12. void setup ( void ) {
  13. startESP();
  14. setupWifi();
  15. setupWebserver();
  16. setupOTA();
  17. delay(200);
  18. Serial.println("Ready");
  19. Serial.print("IP address: ");
  20. Serial.println(WiFi.localIP());
  21. //UKI sensor setup
  22. UKI_UDP.begin(UKI_UDP_In_Port);
  23. delay(1000);
  24. digitalWrite(Red_Led, HIGH); //red led off
  25. digitalWrite(Blue_Led, HIGH);
  26. delay(1000);
  27. ledBlink(Red_Led, 3, 100); //3 quick blink on red led as we start
  28. delay (1000);
  29. }
  30. void loop ( void ) {
  31. loopWebserver();
  32. loopHandles();
  33. /* UKI part */
  34. GSR_sensor = analogRead(A0);
  35. //UKI_UDP.beginPacketMulticast((224, 1, 2, 3), 8000, WiFi.localIP());//
  36. UKI_UDP.beginPacket(UKI_UDP_Master_IP, 8000);
  37. UKI_UDP.print(config.DeviceName);
  38. UKI_UDP.print(" ");
  39. UKI_UDP.print(GSR_sensor);
  40. UKI_UDP.endPacket();
  41. //yield();
  42. //Red_Led_State = !Red_Led_State;
  43. //analogWrite(Red_Led, GSR_sensor);
  44. delay(20);
  45. //Check udp in
  46. int packetSize = UKI_UDP.parsePacket();
  47. if(packetSize) {
  48. UKI_UDP_Master_IP = UKI_UDP.remoteIP();
  49. UKI_UDP.beginPacket(UKI_UDP_Master_IP, 8000);
  50. UKI_UDP.print("new master ip");
  51. UKI_UDP.endPacket();
  52. }
  53. }