ESP_UKI.ino 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. ESP_UKI
  3. TODO : better function organizing
  4. add firmware number in webserver
  5. send ADC to default IP via udp, allow configuration
  6. build onDemand config mode
  7. load/save parameters (fixed ip, uki_name, udp_port udp_ip
  8. */
  9. #include "includes.h" //headers and variables declaration
  10. /* UDP CONFIGURATION */
  11. int UKI_UDP_In_Port = 9000; //udp port input for ESP
  12. String UKI_UDP_IP_test = "192.168.1.1";
  13. IPAddress UKI_UDP_Master_IP(192, 168, 10, 100); //default udp address to send to. Will automatically change to the ip sending something to udp in
  14. Ticker tkUKI; // periodic send ADC to UDP
  15. int GSR_sensor;
  16. void setup ( void ) {
  17. Serial.begin(115200);
  18. Serial.println("Starting ESP8266");
  19. setupLeds();
  20. setupWifi();
  21. //setupOTA();
  22. delay(200);
  23. Serial.println("Ready");
  24. Serial.print("IP address: ");
  25. Serial.println(WiFi.localIP());
  26. //UKI sensor setup
  27. UKI_UDP.begin(UKI_UDP_In_Port);
  28. // delay(1000);
  29. // digitalWrite(Red_Led, HIGH); //red led off
  30. // digitalWrite(Blue_Led, HIGH);
  31. // delay(1000);
  32. // ledBlink(Red_Led, 3, 100); //3 quick blink on red led as we start
  33. // delay (1000);
  34. blueLedState(-1, 500);
  35. }
  36. void loop ( void ) {
  37. //Serial.println(WiFi.status());
  38. StartConfigAP();
  39. /* UKI part */
  40. GSR_sensor = analogRead(A0);
  41. //UKI_UDP.beginPacketMulticast((224, 1, 2, 3), 8000, WiFi.localIP());//
  42. UKI_UDP.beginPacket(UKI_UDP_IP_test, 8000);
  43. UKI_UDP.print("UKI");
  44. UKI_UDP.print(" ");
  45. UKI_UDP.print(GSR_sensor);
  46. UKI_UDP.endPacket();
  47. yield();
  48. delay(50);
  49. //Check udp in
  50. int packetSize = UKI_UDP.parsePacket();
  51. if(packetSize) {
  52. UKI_UDP_Master_IP = UKI_UDP.remoteIP();
  53. UKI_UDP.beginPacket(UKI_UDP_Master_IP, 8000);
  54. UKI_UDP.print("new master ip");
  55. UKI_UDP.endPacket();
  56. }
  57. }