From 4aa1b0eeedddc747e2bfcfcae91291132c6583aa Mon Sep 17 00:00:00 2001 From: LautaroGalantini Date: Wed, 3 Aug 2022 10:11:43 -0300 Subject: [PATCH] first commit --- test.cpp | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 test.cpp diff --git a/test.cpp b/test.cpp new file mode 100644 index 0000000..86e9a19 --- /dev/null +++ b/test.cpp @@ -0,0 +1,54 @@ +void loop() { + // Construct a Flux query + // Query will find the worst RSSI for last hour for each connected WiFi network with this device + String query = "from(bucket: \"Prueba_Enviando_Datos\") \ + |> range(start: -1h) \ + |> filter(fn: (r) => r._measurement == \"button_status\" and r._field == \"stauts\") \ + |> last()"; + + // Print composed query + Serial.print("Querying with: "); + Serial.println(query); + + // Print ouput header + Serial.print("=========="); + // Send query to the server and get result + FluxQueryResult result = client.query(query); + + // Iterate over rows. Even there is just one row, next() must be called at least once. + while (result.next()) { + // Get converted value for flux result column 'SSID' + String ssid = result.getValueByName("SSID").getString(); + Serial.print("SSID '"); + Serial.print(ssid); + + Serial.print("' with RSSI "); + // Get converted value for flux result column '_value' where there is RSSI value + long value = result.getValueByName("_value").getLong(); + Serial.print(value); + + // Get converted value for the _time column + FluxDateTime time = result.getValueByName("_time").getDateTime(); + + // Format date-time for printing + // Format string according to http://www.cplusplus.com/reference/ctime/strftime/ + String timeStr = time.format("%F %T"); + + Serial.print(" at "); + Serial.print(timeStr); + + Serial.println(); + } + + // Check if there was an error + if(result.getError() != "") { + Serial.print("Query result error: "); + Serial.println(result.getError()); + } + + // Close the result + result.close(); + + Serial.println("Wait 10s"); + delay(10000); +}