12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- //Inject zeroconf attr into the MDNS respond (For scanning by ArozOS)
- void MDNSDynamicServiceTxtCallback(const MDNSResponder::hMDNSService p_hService) {
- //Define the domain of the HDSv2 devices
- MDNS.addDynamicServiceTxt(p_hService, "domain", "hds.imuslab.com");
- MDNS.addDynamicServiceTxt(p_hService, "protocol", "hdsv3");
- //Define the OEM written values
- MDNS.addDynamicServiceTxt(p_hService, "uuid", deviceUUID.c_str());
- MDNS.addDynamicServiceTxt(p_hService, "name", (String(DEVICE_NAME) + "_" + deviceUUID).c_str());
- MDNS.addDynamicServiceTxt(p_hService, "model", "hds_4xRelay");
- MDNS.addDynamicServiceTxt(p_hService, "vendor", "imuslab");
- MDNS.addDynamicServiceTxt(p_hService, "version", "1.00");
- }
- void hostProbeResult(String p_pcDomainName, bool p_bProbeResult) {
- MDNS.setDynamicServiceTxtCallback(MDNSDynamicServiceTxtCallback);
- }
- //Start all HDSv3 required services
- void initHds3Services() {
- // Connect to Wi-Fi
- Serial.println("Starting WiFi Manager");
- wifiManager.setClass("invert");
- wifiManager.autoConnect("HDS-4xRelay");
- Serial.print("Connected to ");
- Serial.println(WiFi.SSID());
- Serial.print("IP address:\t");
- Serial.println(WiFi.localIP());
- //Startup MDNS Responder
- MDNS.setHostProbeResultCallback(hostProbeResult);
- if (!MDNS.begin((String(DEVICE_NAME) + "_" + deviceUUID).c_str())) {
- Serial.println("Error setting up MDNS responder!");
- }
- //Advertise the port that you are using
- MDNS.addService("http", "tcp", LISTENING_PORT);
- Serial.println("mDNS responder started");
- //Restful API (required)
- server.on("/", handle_index);
- server.on("/status", handle_status);
- server.on("/info", handle_deviceInfo);
- server.on("/uuid", handle_uuid);
- //Restful API (device dependents)
- server.on("/toggle", handle_toggle);
- server.on("/on", handle_on);
- server.on("/off", handle_off);
-
- delay(100);
- server.begin();
- Serial.println("Restful API server started");
- Serial.print("Listening on port: ");
- Serial.println(LISTENING_PORT);
-
- }
|