Skip to content

RF Sentinel (RFSentinel): free, open-source police detector app for Android. Spots police body cams, Flock ALPR cameras, AirTag trackers, Remote ID drones, smart glasses and fake cell towers from Bluetooth LE and WiFi. No root.

Meshtastic: choose the node's channel slot (never the primary), hops setting (default 1) so a city mesh isn't flooded, status shows the channel in use

CIS-C0e4256f344f89
diff --git a/app/src/main/java/com/rfsentinel/app/link/LinkStore.kt b/app/src/main/java/com/rfsentinel/app/link/LinkStore.kt
index d930171..87274da 100644
--- a/app/src/main/java/com/rfsentinel/app/link/LinkStore.kt
+++ b/app/src/main/java/com/rfsentinel/app/link/LinkStore.kt
@@ -109,6 +109,17 @@ object LinkStore {
const val MESH_INTERVAL_MIN = 15
const val MESH_INTERVAL_MAX = 300
+ /** The node's channel slot for RF Sentinel's channel: 0 picks the first empty one of 1-7. Never 0, the primary. */
+ fun meshSlot(c: Context) = sp(c).getInt("mesh_slot", 0).coerceIn(0, 7)
+ fun setMeshSlot(c: Context, slot: Int) = sp(c).edit { putInt("mesh_slot", slot) }
+
+ /** How many times other nodes pass a packet on (at most the node's own hop limit). 1: only nodes in range of
+ * yours relay it, so a city mesh isn't flooded with it. */
+ fun meshHops(c: Context) = sp(c).getInt("mesh_hops", 1).coerceIn(MESH_HOPS_MIN, MESH_HOPS_MAX)
+ fun setMeshHops(c: Context, hops: Int) = sp(c).edit { putInt("mesh_hops", hops) }
+ const val MESH_HOPS_MIN = 1
+ const val MESH_HOPS_MAX = 7
+
private var meshNext = -1L
private var meshReserved = 0L
diff --git a/app/src/main/java/com/rfsentinel/app/link/MeshNode.kt b/app/src/main/java/com/rfsentinel/app/link/MeshNode.kt
index 88539b8..801efbd 100644
--- a/app/src/main/java/com/rfsentinel/app/link/MeshNode.kt
+++ b/app/src/main/java/com/rfsentinel/app/link/MeshNode.kt
@@ -86,7 +86,8 @@ object MeshNode {
private var region = -1
private var txEnabled = true
private val channels = HashMap<Int, MeshProto.From.ChannelInfo>()
- private var channelIndex = -1
+ /** The node's slot RF Sentinel sends on (1-7), -1 until set up. */
+ @Volatile var channelIndex = -1; private set
private var channelTries = 0
/** Why the node can't be used as it is (no region, no free channel): kept on screen while it retries. */
private var setupProblem: String? = null
@@ -121,6 +122,16 @@ object MeshNode {
connect()
}
+ /** The chosen channel slot changed: set the channel up again where it now belongs. */
+ fun slotChanged() = h.post {
+ if (!running || !ioReady) return@post
+ ready = false
+ channelIndex = -1
+ channelTries = 0
+ setupProblem = null
+ askConfig()
+ }
+
fun stop() = h.post {
if (!running) return@post
running = false
@@ -135,8 +146,9 @@ object MeshNode {
h.post {
if (!ready || channelIndex < 0 || !txEnabled) return@post
if (ops.count { it is Op.Write } >= MAX_QUEUED) return@post
+ val hops = minOf(ctx?.let { LinkStore.meshHops(it) } ?: LinkStore.MESH_HOPS_MIN, hopLimit)
enqueue(Op.Write(MeshProto.packet(MeshProto.BROADCAST, channelIndex, MeshProto.PORT_PRIVATE_APP, payload,
- packetId(), hopLimit, if (urgent) MeshProto.PRIORITY_RELIABLE else MeshProto.PRIORITY_BACKGROUND)))
+ packetId(), hops, if (urgent) MeshProto.PRIORITY_RELIABLE else MeshProto.PRIORITY_BACKGROUND)))
lastSent = System.currentTimeMillis()
changed()
}
@@ -418,21 +430,31 @@ object MeshNode {
private fun configDone() {
val psk = channelPsk ?: return
if (region == 0) { stuck("set its LoRa region in the Meshtastic app first"); return }
- val ours = channels.values.firstOrNull { it.role != MeshProto.ROLE_DISABLED && it.name == MeshCodec.CHANNEL_NAME && it.psk.contentEquals(psk) }
+ // Never the primary (0): it's often a whole city's public channel.
+ val wanted = ctx?.let { LinkStore.meshSlot(it) } ?: 0
+ val ours = channels.values.filter {
+ it.index in 1..7 && it.role != MeshProto.ROLE_DISABLED && it.name == MeshCodec.CHANNEL_NAME && it.psk.contentEquals(psk)
+ }.let { l -> if (wanted > 0) l.firstOrNull { it.index == wanted } else l.minByOrNull { it.index } }
if (ours != null) {
channelIndex = ours.index
ready = true
retryMs = RETRY_MIN_MS
- setStatus(if (!txEnabled) "Meshtastic node: its LoRa transmit is off" else "Meshtastic node · connected")
+ setStatus(if (!txEnabled) "Meshtastic node: its LoRa transmit is off" else "Meshtastic node · channel ${ours.index}, encrypted")
return
}
if (channelTries >= 2 || myNode == 0L) {
stuck("couldn't add the ${MeshCodec.CHANNEL_NAME} channel")
return
}
- val slot = channels.values.firstOrNull { it.index in 1..7 && it.name == MeshCodec.CHANNEL_NAME }?.index
- ?: channels.values.filter { it.index in 1..7 && it.role == MeshProto.ROLE_DISABLED }.minOfOrNull { it.index }
- if (slot == null) { stuck("no free channel - free one in the Meshtastic app"); return }
+ // Only an empty slot or our own channel (another group's key): never a channel someone set up.
+ fun free(i: Int) = channels[i]?.let { it.role == MeshProto.ROLE_DISABLED || it.name == MeshCodec.CHANNEL_NAME } == true
+ val slot = if (wanted > 0) wanted.takeIf { free(it) }
+ else channels.values.firstOrNull { it.index in 1..7 && it.name == MeshCodec.CHANNEL_NAME }?.index
+ ?: (1..7).firstOrNull { channels[it]?.role == MeshProto.ROLE_DISABLED }
+ if (slot == null) {
+ stuck(if (wanted > 0) "channel $wanted is in use - pick another slot" else "no free channel - free one in the Meshtastic app")
+ return
+ }
channelTries++
setStatus("Meshtastic node: adding the ${MeshCodec.CHANNEL_NAME} channel…")
// Admin message to the node itself (from this phone: no admin key needed); channels change without a restart.
diff --git a/app/src/main/java/com/rfsentinel/app/ui/SentinelLinkActivity.kt b/app/src/main/java/com/rfsentinel/app/ui/SentinelLinkActivity.kt
index 2e1b511..fef0bcf 100644
--- a/app/src/main/java/com/rfsentinel/app/ui/SentinelLinkActivity.kt
+++ b/app/src/main/java/com/rfsentinel/app/ui/SentinelLinkActivity.kt
@@ -149,7 +149,9 @@ class SentinelLinkActivity : AppCompatActivity() {
setLineSpacing(0f, 1.2f)
text = "Reach Sentinels kilometres away through a Meshtastic node: a LoRa board with the official firmware, " +
"paired with this phone over Bluetooth. RF Sentinel adds a private channel named ${com.rfsentinel.app.link.MeshCodec.CHANNEL_NAME} " +
- "to the node, made from the group's key, so only your group reads it. LoRa is slow: watchlist matches go " +
+ "to the node, made from the group's key, so only your group reads it. It goes in an empty slot (1 to 7) and " +
+ "RF Sentinel only sends on it: never on the primary channel 0 or a channel you set up, and never to MQTT. " +
+ "Others only see encrypted packets. LoRa is slow: watchlist matches go " +
"first, then flagged devices, then every other device, a few per packet. While RF Sentinel uses the node, " +
"the Meshtastic app on this phone can't."
}
@@ -182,10 +184,42 @@ class SentinelLinkActivity : AppCompatActivity() {
}
}
showInterval(interval.value.toInt())
+ fun slotLabel(s: Int) = if (s == 0) "Channel slot: automatic" else "Channel slot: $s"
+ lateinit var slotButton: MaterialButton
+ slotButton = button(slotLabel(LinkStore.meshSlot(this))) {
+ val names = arrayOf("Automatic - first empty slot") + (1..7).map { "Slot $it" }
+ MaterialAlertDialogBuilder(this)
+ .setTitle("Channel slot on the node")
+ .setMessage("Slot 0 is the primary channel and is never used. A slot that already holds another channel isn't changed.")
+ .setSingleChoiceItems(names, LinkStore.meshSlot(this)) { d, which ->
+ LinkStore.setMeshSlot(this, which)
+ slotButton.text = slotLabel(which)
+ MeshNode.slotChanged()
+ d.dismiss()
+ }
+ .setNegativeButton("Cancel", null)
+ .show()
+ }
+ val hopsLabel = TextView(this).apply { textSize = 14f; setPadding(0, pad(12), 0, 0) }
+ fun showHops(n: Int) {
+ hopsLabel.text = if (n == 1) "Hops: 1 - only nodes in range of yours pass it on"
+ else "Hops: $n - relayed up to $n times (at most your node's own hop limit)"
+ }
+ val hops = Slider(this).apply {
+ valueFrom = LinkStore.MESH_HOPS_MIN.toFloat()
+ valueTo = LinkStore.MESH_HOPS_MAX.toFloat()
+ stepSize = 1f
+ value = LinkStore.meshHops(this@SentinelLinkActivity).toFloat()
+ addOnChangeListener { _, v, fromUser ->
+ showHops(v.toInt())
+ if (fromUser) LinkStore.setMeshHops(this@SentinelLinkActivity, v.toInt())
+ }
+ }
+ showHops(hops.value.toInt())
return LinearLayout(this).apply {
orientation = LinearLayout.VERTICAL
addView(header); addView(about); addView(meshSwitch); addView(meshNodeText); addView(meshStatus)
- addView(choose); addView(intervalLabel); addView(interval)
+ addView(choose); addView(slotButton); addView(intervalLabel); addView(interval); addView(hopsLabel); addView(hops)
setPadding(0, 0, 0, pad(12))
}
}