device infos
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -10,11 +10,10 @@ import 'package:miler/views/helpers/constants/apiconstants.dart';
|
||||
import 'package:miler/providers/Riderlog/riderlog_provider.dart';
|
||||
import 'package:miler/background/backgroundservice.dart';
|
||||
import 'package:geolocator/geolocator.dart';
|
||||
import 'package:miler/data/device_telemetry.dart';
|
||||
import 'package:miler/utils/kalman_filter.dart';
|
||||
import 'package:miler/utils/mqtt_service.dart';
|
||||
import 'package:miler/views/helpers/constants/mqtt_constants.dart';
|
||||
import 'package:battery_plus/battery_plus.dart';
|
||||
import 'package:connectivity_plus/connectivity_plus.dart';
|
||||
|
||||
class _BackgroundRiderLog {
|
||||
static MilerKalmanFilter? _kf;
|
||||
@@ -165,6 +164,24 @@ class _BackgroundRiderLog {
|
||||
final int? logid = prefs.getInt('logId') ?? prefs.getInt('logid');
|
||||
final String orderId = prefs.getString('current_riding_order_id') ?? '';
|
||||
|
||||
// ── The handset's own state goes IN the heartbeat ──
|
||||
//
|
||||
// It used to be gathered further down, after this post had already gone,
|
||||
// and published to MQTT alone — so the console reading `/miler/logs` had
|
||||
// a position and nothing else, and drew an em dash against Battery,
|
||||
// Connection, GPS Accuracy and Location Service on a rider whose phone
|
||||
// was reporting all four.
|
||||
//
|
||||
// Read here, once, and spread into the payload below. The MQTT publish
|
||||
// further down reuses the same values rather than asking again, so the
|
||||
// two lanes cannot disagree about the same second. See [DeviceTelemetry].
|
||||
final telemetry = await DeviceTelemetry.read(
|
||||
// The fix lookup already resolved this to get a position at all;
|
||||
// asking a second time can disagree with itself if the rider toggles
|
||||
// the setting in between.
|
||||
locationService: loc['status'],
|
||||
);
|
||||
|
||||
final payload = {
|
||||
"logid": logid ?? 0,
|
||||
"userid": userid,
|
||||
@@ -189,6 +206,15 @@ class _BackgroundRiderLog {
|
||||
"userfcmtoken": userfcmtoken ?? '',
|
||||
"username": (username ?? '').trim(),
|
||||
"orderid": orderId,
|
||||
// What the dispatcher needs when a rider goes quiet: the battery, the
|
||||
// signal, whether location is even on, and how good the last fix was.
|
||||
...telemetry.toPayload(),
|
||||
// Only a measured one — a `0` reads on the console as a perfect fix.
|
||||
if ((loc['accuracy'] ?? '0') != '0') "accuracy": loc['accuracy'],
|
||||
// This heartbeat is the *background* one — it is what keeps reporting
|
||||
// while the app is not on screen, which is exactly the state the
|
||||
// console's App State column exists to show.
|
||||
"is_background": true,
|
||||
};
|
||||
|
||||
final firstName = prefs.getString('firstname') ?? '';
|
||||
@@ -223,18 +249,13 @@ class _BackgroundRiderLog {
|
||||
}
|
||||
|
||||
if (mqttService.isConnected) {
|
||||
// Gather Telemetry
|
||||
final battery = Battery();
|
||||
final int batteryLevel = await battery.batteryLevel;
|
||||
final BatteryState batteryState = await battery.batteryState;
|
||||
final isCharging =
|
||||
batteryState == BatteryState.charging ||
|
||||
batteryState == BatteryState.full;
|
||||
|
||||
final connectivity = await Connectivity().checkConnectivity();
|
||||
final String connType = connectivity.isNotEmpty
|
||||
? connectivity.first.toString().split('.').last
|
||||
: 'none';
|
||||
// The same reading the heartbeat above carried — not a second one.
|
||||
// Two reads a second apart can report two batteries, and the console
|
||||
// then shows one number on the live tile and a different one in the
|
||||
// trail it is drawn from.
|
||||
final int batteryLevel = telemetry.battery ?? 0;
|
||||
final bool isCharging = telemetry.isCharging ?? false;
|
||||
final String connType = telemetry.connection ?? 'none';
|
||||
|
||||
// 1. Direct Telemetry (Feeding the /full API)
|
||||
mqttService.publish('battery', '$batteryLevel%');
|
||||
|
||||
Reference in New Issue
Block a user