diff --git a/TODO.md b/TODO.md index 330f4676..f24e9888 100644 --- a/TODO.md +++ b/TODO.md @@ -1,6 +1,7 @@ # High priority MVP features required for first public alpha +* make a boot screen explaining this is an early alpha * describe user experience: devices always point to each other and show distance, you can send texts between nodes the channel is encrypted, you can share the the channel key with others by qr code or by sharing a special link @@ -61,6 +62,7 @@ Do this "Signal app compatible" release relatively soon after the alpha release # Medium priority Things for the betaish period. +* Use LocationRequest.setSmallestDisplacement to save battery and decrease net activity * MeshService.reinitFromRadio can take 300 ms, run it in a worker thread instead * show user icons in chat * keep past messages in db, one db per channel diff --git a/app/src/main/java/com/geeksville/mesh/service/MeshService.kt b/app/src/main/java/com/geeksville/mesh/service/MeshService.kt index 9f41104b..d3d8ec0d 100644 --- a/app/src/main/java/com/geeksville/mesh/service/MeshService.kt +++ b/app/src/main/java/com/geeksville/mesh/service/MeshService.kt @@ -106,6 +106,8 @@ class MeshService : Service(), Logging { } private val locationCallback = object : LocationCallback() { + private var lastSendMsec = 0L + override fun onLocationResult(locationResult: LocationResult) { super.onLocationResult(locationResult) var l = locationResult.lastLocation @@ -122,7 +124,17 @@ class MeshService : Service(), Logging { if (l.hasAccuracy() && l.accuracy >= 200) // if more than 200 meters off we won't use it warn("accuracy ${l.accuracy} is too poor to use") else { - sendPosition(l.latitude, l.longitude, l.altitude.toInt()) + val now = System.currentTimeMillis() + + // we limit our sends onto the lora net to a max one once every FIXME + val sendLora = (now - lastSendMsec >= 30 * 1000) + if (sendLora) + lastSendMsec = now + sendPosition( + l.latitude, l.longitude, l.altitude.toInt(), + destNum = if (sendLora) NODENUM_BROADCAST else myNodeNum, + wantResponse = sendLora + ) } } @@ -688,10 +700,14 @@ class MeshService : Service(), Logging { } /// Send a position (typically from our built in GPS) into the mesh - private fun sendPosition(lat: Double, lon: Double, alt: Int) { - debug("Sending our position into mesh lat=$lat, lon=$lon, alt=$alt") - - val destNum = NODENUM_BROADCAST + private fun sendPosition( + lat: Double, + lon: Double, + alt: Int, + destNum: Int = NODENUM_BROADCAST, + wantResponse: Boolean = false + ) { + debug("Sending our position to=$destNum lat=$lat, lon=$lon, alt=$alt") val position = MeshProtos.Position.newBuilder().also { it.latitude = lat @@ -705,6 +721,7 @@ class MeshService : Service(), Logging { packet.payload = MeshProtos.SubPacket.newBuilder().also { it.position = position + it.wantResponse = wantResponse }.build() // Also update our own map for our nodenum, by handling the packet just like packets from other users diff --git a/app/src/main/proto/mesh.proto b/app/src/main/proto/mesh.proto index cc4055d0..19595c2c 100644 --- a/app/src/main/proto/mesh.proto +++ b/app/src/main/proto/mesh.proto @@ -122,6 +122,10 @@ message SubPacket { Data data = 3; User user = 4; } + + /// Not normally used, but for testing a sender can request that recipient responds in kind (i.e. if it received a position, it should unicast back its position). + // Note: that if you set this on a broadcast you will receive many replies. + bool want_response = 5; } // Note: For simplicity reasons (and that we want to keep over the radio packets very small, we now assume that there is only _one_