Aypac / Arduino-TR-064-SOAP-Library

Arduino library for the TR-064 protocol, most commonly used by the Fritz!Box router API
Other
63 stars 21 forks source link

tr064_connection.init(); tr064_connection.action( ... ) very slow compared to the past #61

Closed GvDatGithub closed 1 year ago

GvDatGithub commented 1 year ago

Hello,

In the new version the first query of a Fritz! - Value ( power socket ) 20 seconds!

Previously ret was a string with all contents of the query String ret = tr064_connection.action(tr064_service, "GetSpecificDeviceInfos", params, 1, req, 1);

Questions:

  1. why is the query so slow now ( 20s for the first query )?
  2. is it possible to query all values of a device at once?

Example: Start powerqueries: 9316 End power queries: 29414 Socket 1: WATT 1: 467.5 Start switch status query: 29415 End of switch status query: 39489 Switch status: ON

Start power interrogation 2: 39490 End power interrogation: 49567 Socket 1: WATT 1: 128.1 Start switch status query: 49568 End switch status query: 59667 SwitchStatus2: ON

Translated with www.DeepL.com/Translator (free version)

click to show code ``` // 26.07.2022 #include #include "MyFunctions.h" // for ota ********************* #include #include // END for ota ***************** #include TR064 tr064_connection(FRITZBOX_PORT, FRITZBOX_IP, F_USER, F_PASSWORD); void setup() { Serial.begin(115200); delay(10); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(200); Serial.println(millis()); } IPAddress ipLocalAdress; Serial.println(""); Serial.print("localIP: "); ipLocalAdress = WiFi.localIP(); Serial.println(ipLocalAdress); tr064_connection.debug_level = tr064_connection.DEBUG_WARNING; tr064_connection.init(); LeistungAbfragen(); LeistungAbfragen2(); } void loop() { } void LeistungAbfragen() { // tr064_connection.init(); float fWatt = 0.00; int iTmp = 0; const char *FbApiAIN01 = "08761 0340889"; // Aktor Identifikationsnummer (AIN) String tr064_service = "urn:dslforum-org:service:X_AVM-DE_Homeauto:1"; Serial.printf("Start LeistungAbfragen: "); Serial.println(millis()); // Leistung abfragen Steckdose n // ****************************** // Serial.println("-"); String req[][2] = {{"NewMultimeterPower", ""}}; String params[][2] = {{"NewAIN", FbApiAIN01}}; // Energiequelle tr064_connection.action(tr064_service, "GetSpecificDeviceInfos", params, 1, req, 1); Serial.printf("Ende LeistungAbfragen: "); Serial.println(millis()); Serial.print("Steckdose 1:"); // Serial.println(ret); // Zeigt alle für diese Frage möglichen Parameter ( xml ) Serial.print(" WATT 1: "); // Serial.println(req[0][1]); cAktuelleWattErzeuger = req[0][1]; // Serial.println(cAktuelleWattErzeuger); iTmp = cAktuelleWattErzeuger.toInt(); // String2Int Str2Int fWatt = iTmp / 100.00; cAktuelleWattErzeuger = String(fWatt, 1); Serial.println(cAktuelleWattErzeuger); // Schalterstatus abfragen Steckdose 1 // *********************************** Serial.printf("Start Schalterstatus abfragen: "); Serial.println(millis()); String state_req[][2] = {{"NewSwitchState", ""}}; tr064_connection.action(tr064_service, "GetSpecificDeviceInfos", params, 1, state_req, 1); Serial.printf("Ende Schalterstatus abfragen: "); Serial.println(millis()); Serial.print("SchalterStatus: "); Serial.println(state_req[0][1]); } void LeistungAbfragen2() { // tr064_connection.init(); float fWatt = 0.00; int iTmp = 0; const char *FbApiAIN01 = "08761 0456994"; // FRITZ_Springer Aktor Identifikationsnummer (AIN) String tr064_service = "urn:dslforum-org:service:X_AVM-DE_Homeauto:1"; Serial.printf("Start LeistungAbfragen 2: "); Serial.println(millis()); // Leistung abfragen Steckdose n // ****************************** // Serial.println("-"); String req[][2] = {{"NewMultimeterPower", ""}}; String params[][2] = {{"NewAIN", FbApiAIN01}}; // Energiequelle tr064_connection.action(tr064_service, "GetSpecificDeviceInfos", params, 1, req, 1); Serial.printf("Ende LeistungAbfragen: "); Serial.println(millis()); Serial.print("Steckdose 1:"); // Serial.println(ret); // Zeigt alle für diese Frage möglichen Parameter ( xml ) Serial.print(" WATT 1: "); // Serial.println(req[0][1]); cAktuelleWattErzeuger = req[0][1]; // Serial.println(cAktuelleWattErzeuger); iTmp = cAktuelleWattErzeuger.toInt(); // String2Int Str2Int fWatt = iTmp / 100.00; cAktuelleWattErzeuger = String(fWatt, 1); Serial.println(cAktuelleWattErzeuger); // Schalterstatus abfragen Steckdose 1 // *********************************** Serial.printf("Start Schalterstatus abfragen: "); Serial.println(millis()); String state_req[][2] = {{"NewSwitchState", ""}}; tr064_connection.action(tr064_service, "GetSpecificDeviceInfos", params, 1, state_req, 1); Serial.printf("Ende Schalterstatus abfragen: "); Serial.println(millis()); Serial.print("SchalterStatus2: "); Serial.println(state_req[0][1]); } ```
GvDatGithub commented 1 year ago

Sorry - the solution "set Stream Timeout at readStringUntil() function to 40 milliseconds #58" worked for me!

Aypac commented 1 year ago

Hey :) That's good to hear. All the more reason for me to finally merge that PR. So it solved both the latency and the "fetching several things at once" issue?

Aypac commented 1 year ago

You should be able to request several things at once like this:

String state_req[][2] = {{"NewSwitchState", ""}, {"NewMultimeterPower", ""}};
cAktuelleWattErzeuger = req[1][1];

Serial.print("SchalterStatus2: ");
Serial.println(state_req[0][1]);
GvDatGithub commented 1 year ago

Hey :) That's good to hear. All the more reason for me to finally merge that PR. So it solved both the latency and the "fetching several things at once" issue?

yes - it's all fine!

GvDatGithub commented 1 year ago

yes - i found: String paramsV[][2] = {{"NewAIN", FbApiAIN02}}; // Energieverbraucher String reqV[][2] = {{"NewMultimeterPower", ""}, {"NewSwitchState", ""}, {"NewMultimeterEnergy", ""}, {"NewTemperatureCelsius", ""}, {"NewDeviceName", ""}}; tr064_connection.action(tr064_service, "GetSpecificDeviceInfos", paramsV, 1, reqV, 5);

Serial.printf("Ende LeistungAbfragen2: "); Serial.println(millis());

Serial.println("--------- reqV ---------------"); Serial.print("reqV[0][1]: "); Serial.println(reqV[0][1]); Serial.print("reqV[1][1]: "); Serial.println(reqV[1][1]); Serial.print("reqV[2][1]: "); Serial.println(reqV[2][1]); Serial.print("reqV[3][1]: "); Serial.println(reqV[3][1]); Serial.print("reqV[4][1]: "); Serial.println(reqV[4][1]);

:)