hdsv3.ino 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. //Inject zeroconf attr into the MDNS respond (For scanning by ArozOS)
  2. void MDNSDynamicServiceTxtCallback(const MDNSResponder::hMDNSService p_hService) {
  3. //Define the domain of the HDSv2 devices
  4. MDNS.addDynamicServiceTxt(p_hService, "domain", "hds.imuslab.com");
  5. MDNS.addDynamicServiceTxt(p_hService, "protocol", "hdsv3");
  6. //Define the OEM written values
  7. MDNS.addDynamicServiceTxt(p_hService, "uuid", deviceUUID.c_str());
  8. MDNS.addDynamicServiceTxt(p_hService, "name", (String(DEVICE_NAME) + "_" + deviceUUID).c_str());
  9. MDNS.addDynamicServiceTxt(p_hService, "model", "hds_4xRelay");
  10. MDNS.addDynamicServiceTxt(p_hService, "vendor", "imuslab");
  11. MDNS.addDynamicServiceTxt(p_hService, "version", "1.00");
  12. }
  13. void hostProbeResult(String p_pcDomainName, bool p_bProbeResult) {
  14. MDNS.setDynamicServiceTxtCallback(MDNSDynamicServiceTxtCallback);
  15. }
  16. //Start all HDSv3 required services
  17. void initHds3Services() {
  18. // Connect to Wi-Fi
  19. Serial.println("Starting WiFi Manager");
  20. wifiManager.setClass("invert");
  21. wifiManager.autoConnect("HDS-4xRelay");
  22. Serial.print("Connected to ");
  23. Serial.println(WiFi.SSID());
  24. Serial.print("IP address:\t");
  25. Serial.println(WiFi.localIP());
  26. //Startup MDNS Responder
  27. MDNS.setHostProbeResultCallback(hostProbeResult);
  28. if (!MDNS.begin((String(DEVICE_NAME) + "_" + deviceUUID).c_str())) {
  29. Serial.println("Error setting up MDNS responder!");
  30. }
  31. //Advertise the port that you are using
  32. MDNS.addService("http", "tcp", LISTENING_PORT);
  33. Serial.println("mDNS responder started");
  34. //Restful API (required)
  35. server.on("/", handle_index);
  36. server.on("/status", handle_status);
  37. server.on("/info", handle_deviceInfo);
  38. server.on("/uuid", handle_uuid);
  39. //Restful API (device dependents)
  40. server.on("/toggle", handle_toggle);
  41. server.on("/on", handle_on);
  42. server.on("/off", handle_off);
  43. delay(100);
  44. server.begin();
  45. Serial.println("Restful API server started");
  46. Serial.print("Listening on port: ");
  47. Serial.println(LISTENING_PORT);
  48. }