Skip to content

Commit 517f2f1

Browse files
authored
Merge pull request #1961 from weebl2000/dutycycle-command
Add get/set dutycycle command
2 parents 15b2469 + 37d1a75 commit 517f2f1

3 files changed

Lines changed: 49 additions & 5 deletions

File tree

docs/cli_commands.md

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,29 @@ This document provides an overview of CLI commands that can be sent to MeshCore
500500

501501
---
502502

503+
#### View or change the duty cycle limit
504+
**Usage:**
505+
- `get dutycycle`
506+
- `set dutycycle <value>`
507+
508+
**Parameters:**
509+
- `value`: Duty cycle percentage (1-100)
510+
511+
**Default:** `50%` (equivalent to airtime factor 1.0)
512+
513+
**Examples:**
514+
- `set dutycycle 100` — no duty cycle limit
515+
- `set dutycycle 50` — 50% duty cycle (default)
516+
- `set dutycycle 10` — 10% duty cycle
517+
- `set dutycycle 1` — 1% duty cycle (strictest EU requirement)
518+
519+
> **Note:** Added in firmware v1.15.0
520+
521+
---
522+
503523
#### View or change the airtime factor (duty cycle limit)
524+
> **Deprecated** as of firmware v1.15.0. Use [`get/set dutycycle`](#view-or-change-the-duty-cycle-limit) instead.
525+
504526
**Usage:**
505527
- `get af`
506528
- `set af <value>`
@@ -510,8 +532,8 @@ This document provides an overview of CLI commands that can be sent to MeshCore
510532
- `af = 1`~50% duty
511533
- `af = 2`~33% duty
512534
- `af = 3`~25% duty
513-
- `af = 9`~10% duty
514-
Yyou are responsible for choosing a value that is appropriate for your jurisdiction and channel plan (for example EU 868 Mhz 10% duty cycle regulation).
535+
- `af = 9`~10% duty
536+
You are responsible for choosing a value that is appropriate for your jurisdiction and channel plan (for example EU 868 Mhz 10% duty cycle regulation).
515537

516538
**Default:** `1.0`
517539

docs/terminal_chat_cli.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,15 @@ set lon {longitude}
2727
```
2828
Sets your advertisement map longitude. (decimal degrees)
2929

30+
```
31+
set dutycycle {percent}
32+
```
33+
Sets the transmit duty cycle limit (1-100%). Example: `set dutycycle 10` for 10%.
34+
3035
```
3136
set af {air-time-factor}
3237
```
33-
Sets the transmit air-time-factor.
38+
Sets the transmit air-time-factor. Deprecated — use `set dutycycle` instead.
3439

3540

3641
```

src/helpers/CommonCLI.cpp

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,12 @@ void CommonCLI::handleCommand(uint32_t sender_timestamp, const char* command, ch
294294
*/
295295
} else if (memcmp(command, "get ", 4) == 0) {
296296
const char* config = &command[4];
297-
if (memcmp(config, "af", 2) == 0) {
297+
if (memcmp(config, "dutycycle", 9) == 0) {
298+
float dc = 100.0f / (_prefs->airtime_factor + 1.0f);
299+
int dc_int = (int)dc;
300+
int dc_frac = (int)((dc - dc_int) * 10.0f + 0.5f);
301+
sprintf(reply, "> %d.%d%%", dc_int, dc_frac);
302+
} else if (memcmp(config, "af", 2) == 0) {
298303
sprintf(reply, "> %s", StrHelper::ftoa(_prefs->airtime_factor));
299304
} else if (memcmp(config, "int.thresh", 10) == 0) {
300305
sprintf(reply, "> %d", (uint32_t) _prefs->interference_threshold);
@@ -451,7 +456,19 @@ void CommonCLI::handleCommand(uint32_t sender_timestamp, const char* command, ch
451456
*/
452457
} else if (memcmp(command, "set ", 4) == 0) {
453458
const char* config = &command[4];
454-
if (memcmp(config, "af ", 3) == 0) {
459+
if (memcmp(config, "dutycycle ", 10) == 0) {
460+
float dc = atof(&config[10]);
461+
if (dc < 1 || dc > 100) {
462+
strcpy(reply, "ERROR: dutycycle must be 1-100");
463+
} else {
464+
_prefs->airtime_factor = (100.0f / dc) - 1.0f;
465+
savePrefs();
466+
float actual = 100.0f / (_prefs->airtime_factor + 1.0f);
467+
int a_int = (int)actual;
468+
int a_frac = (int)((actual - a_int) * 10.0f + 0.5f);
469+
sprintf(reply, "OK - %d.%d%%", a_int, a_frac);
470+
}
471+
} else if (memcmp(config, "af ", 3) == 0) {
455472
_prefs->airtime_factor = atof(&config[3]);
456473
savePrefs();
457474
strcpy(reply, "OK");

0 commit comments

Comments
 (0)