influxdb-client-dart
influxdb-client-dart copied to clipboard
Connect to two diferrent IPs
Hi. I a developing an APP with flutter, in this case I want to check if the connection to the first IP has been made correctly, make the query correctly; otherwise try to make the connection to the second IP. Next I leave you the code that I have implemented and it works correctly with the first IP, however when I select the second IP it does not give any error, but the query is not done, because it returns the empty variables.
import '../Cuidador/screen_Paciente.dart';
class InfluxDBService {
late InfluxDBClient client;
// var url = 'http://192.168.72.11:8086'; // PC POM
var url = 'http://212.256.20.330:8086'; // PC POM
var token =
'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
var org = 'XXXXXXXXXXXXXXXXXX';
var bucket = 'XXXXXXXXXXXXXXXX';
InfluxDBService() {
//PC POM
client = InfluxDBClient(
url: url, // PC POM
token: token,
org: org,
bucket: bucket,
followRedirects: true,
maxRedirects: 5,
debug: true,
);
}
Future GetSteps(COD_PACIENTE_WEARABLE, startDateString, endDateString) async {
var startDate = DateTime.parse(startDateString);
var endDate = DateTime.parse(endDateString);
var queryService = client.getQueryService();
var StepsQuery = '''
from(bucket: "${bucket}")
|> range(start: ${startDate.toIso8601String()}, stop: ${endDate.toIso8601String()})
|> filter(fn: (r) => r["_measurement"] == "${COD_PACIENTE_WEARABLE}")
|> filter(fn: (r) => r["Data_type"] == "MISC")
|> filter(fn: (r) => r["Sensor_type"] == "Movement")
|> filter(fn: (r) => r["_field"] == "Steps")
''';
var StepsResponse = await queryService.query(StepsQuery);
// Convertir el Stream en una lista
var StepsRecords = await StepsResponse.toList();
client.close();
// Procesa los resultados y devuelve el nivel de la batería
// Procesar los resultados
var StepList = <StepData>[];
for (var record in StepsRecords) {
var Step = record["_value"];
var timestampString = record["_time"];
var timestamp = DateTime.parse(timestampString).toLocal();
StepList.add(StepData(Step, timestamp));
}
StepList.sort((a, b) => b.timestamp.compareTo(a.timestamp));
return StepList;
}
}