Skip to content

Commit 2484267

Browse files
committed
LED commands
1 parent 68209df commit 2484267

2 files changed

Lines changed: 97 additions & 0 deletions

File tree

README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,42 @@ This feature only really works in interactive mode.
204204

205205
Note: There is also an `auto_update_contacts` setting that has nothing to do with adding contacts, it permits to automatically sync contact lists between device and meshcore-cli (when there is an update in name, location or path).
206206

207+
### LED Control
208+
209+
The BLE and status LEDs on companion devices can be controlled using the `set` and `get` commands.
210+
211+
#### BLE LED (`led_ble_mode`)
212+
213+
Controls the BLE connection indicator LED.
214+
215+
| Value | Behavior |
216+
|-------|----------|
217+
| 0 | Normal: blinks when disconnected, solid when connected |
218+
| 1 | Blinks only when disconnected from BLE |
219+
| 2 | Solid only when connected to BLE |
220+
| 3 | Disabled |
221+
222+
```
223+
set led_ble_mode 1
224+
get led_ble_mode
225+
```
226+
227+
#### Status LED (`led_status_mode`)
228+
229+
Controls the status LED blinking.
230+
231+
| Value | Behavior |
232+
|-------|----------|
233+
| 0 | Enabled (normal blinking) |
234+
| 1 | Disabled |
235+
236+
```
237+
set led_status_mode 1
238+
get led_status_mode
239+
```
240+
241+
Note: LED settings are persisted to the device and require a reboot to take effect.
242+
207243
### Issuing batch commands to contacts with apply to
208244

209245
`apply_to <f> <cmd>` : applies cmd to contacts matching filter `<f>` it can be used to apply the same command to a pool of repeaters, or remove some contacts matching a condition.

src/meshcore_cli/meshcore_cli.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,8 @@ def make_completion_dict(contacts, pending={}, to=None, channels=None):
579579
"max_flood_attempts" : None,
580580
"flood_after" : None,
581581
"path_hash_mode": None,
582+
"led_ble_mode": None,
583+
"led_status_mode": None,
582584
},
583585
"get" : {"name":None,
584586
"bat":None,
@@ -620,6 +622,8 @@ def make_completion_dict(contacts, pending={}, to=None, channels=None):
620622
"stats_packets":None,
621623
"allowed_repeat_freq":None,
622624
"path_hash_mode":None,
625+
"led_ble_mode":None,
626+
"led_status_mode":None,
623627
},
624628
"?get":None,
625629
"?set":None,
@@ -2055,6 +2059,30 @@ async def next_cmd(mc, cmds, json_output=False):
20552059
print(json.dumps(res.payload, indent=4))
20562060
else:
20572061
print("ok")
2062+
case "led_ble_mode":
2063+
mode = int(cmds[2])
2064+
if mode < 0 or mode > 3:
2065+
logger.error("led_ble_mode must be 0-3 (0=enabled, 1=disconn_only, 2=conn_only, 3=disabled)")
2066+
else:
2067+
res = await mc.commands.set_led_ble_mode(mode)
2068+
if res.type == EventType.ERROR:
2069+
print(f"Error: {res}")
2070+
elif json_output:
2071+
print(json.dumps(res.payload, indent=4))
2072+
else:
2073+
print("ok")
2074+
case "led_status_mode":
2075+
mode = int(cmds[2])
2076+
if mode < 0 or mode > 1:
2077+
logger.error("led_status_mode must be 0-1 (0=enabled, 1=disabled)")
2078+
else:
2079+
res = await mc.commands.set_led_status_mode(mode)
2080+
if res.type == EventType.ERROR:
2081+
print(f"Error: {res}")
2082+
elif json_output:
2083+
print(json.dumps(res.payload, indent=4))
2084+
else:
2085+
print("ok")
20582086
case "name":
20592087
res = await mc.commands.set_name(cmds[2])
20602088
logger.debug(res)
@@ -2380,6 +2408,30 @@ async def next_cmd(mc, cmds, json_output=False):
23802408
print(f"{res.payload['path_hash_mode']}")
23812409
else:
23822410
print("Not available")
2411+
case "led_ble_mode":
2412+
res = await mc.commands.send_device_query()
2413+
logger.debug(res)
2414+
if res.type == EventType.ERROR :
2415+
print(f"ERROR: {res}")
2416+
elif json_output :
2417+
print(json.dumps(res.payload, indent=4))
2418+
else :
2419+
if "led_ble_mode" in res.payload :
2420+
print(f"{res.payload['led_ble_mode']}")
2421+
else:
2422+
print("Not available")
2423+
case "led_status_mode":
2424+
res = await mc.commands.send_device_query()
2425+
logger.debug(res)
2426+
if res.type == EventType.ERROR :
2427+
print(f"ERROR: {res}")
2428+
elif json_output :
2429+
print(json.dumps(res.payload, indent=4))
2430+
else :
2431+
if "led_status_mode" in res.payload :
2432+
print(f"{res.payload['led_status_mode']}")
2433+
else:
2434+
print("Not available")
23832435
case "bat" :
23842436
res = await mc.commands.get_bat()
23852437
logger.debug(res)
@@ -3728,6 +3780,8 @@ def get_help_for (cmdname, context="line") :
37283780
stats_packets : packets stats (recv/sent/flood/direct)
37293781
allowed_repeat_freq: possible frequency ranges for repeater mode
37303782
path_hash_mode
3783+
led_ble_mode : BLE LED mode (0-3)
3784+
led_status_mode : status LED mode (0-1)
37313785
""")
37323786

37333787
elif cmdname == "set" :
@@ -3753,6 +3807,10 @@ def get_help_for (cmdname, context="line") :
37533807
(pending contacts list is built by meshcli from adverts while connected)
37543808
autoadd_config : set autoadd_config flags (see ?autoadd)
37553809
path_hash_mode <value>
3810+
led_ble_mode <0-3> : BLE LED behavior
3811+
0=normal, 1=disconn blink only, 2=conn solid only, 3=disabled
3812+
led_status_mode <0-1> : status LED behavior
3813+
0=enabled (blinking), 1=disabled
37563814
display:
37573815
print_timestamp <on/off/fmt>: toggle printing of timestamp, can be strftime format
37583816
print_snr <on/off> : toggle snr display in messages
@@ -3882,6 +3940,7 @@ def get_help_for (cmdname, context="line") :
38823940
"bridge.channel": None, "bridge.secret": None, "bridge.type": None,
38833941
"adc.multiplier": None, "acl": None,
38843942
"owner.info": None,
3943+
"led.ble": None, "led.status": None,
38853944
},
38863945
"set": {
38873946
"name": None, "radio": None, "tx": None, "freq": None,
@@ -3897,6 +3956,8 @@ def get_help_for (cmdname, context="line") :
38973956
"bridge.baud": None, "bridge.channel": None, "bridge.secret": None,
38983957
"adc.multiplier": None,
38993958
"owner.info": None,
3959+
"led.ble": None,
3960+
"led.status": None,
39003961
},
39013962
"powersaving": {"on":None, "off":None,},
39023963
"password": None,

0 commit comments

Comments
 (0)