Show the fixed radio pins as read-only in the web UI

On the integrated-radio board the firmware replaces any radio pins a client
saves with the board's wiring, yet the web UI let the user edit them and
reported success. The radio settings now carry fixedPins (wire key fx),
sent only where the radio is wired to the board. The web UI disables the six
pin selects, shows "Radio wiring is fixed on this board." and skips the pin
duplicate and boot-pin checks for them. Generic builds do not send the
field, so their behaviour is unchanged, and applyBoardPins() stays as the
safety net for old configs and imports.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
R. Sid Shaytay 2026-11-14 18:41:27 -08:00
parent 31eda550b9
commit 2b3d556729
No known key found for this signature in database
13 changed files with 109 additions and 15 deletions

View file

@ -933,6 +933,7 @@
<label for="selTransRXPin">RX</label> <label for="selTransRXPin">RX</label>
</div> </div>
</div> </div>
<div id="divRadioPinsFixed" style="display:none;font-size:12px;margin:-14px 0 14px 0;white-space:normal;">Radio wiring is fixed on this board.</div>
<div id="divRadioBootPins" style="display:none;color:#e65100;font-size:12px;margin:-14px 0 14px 0;white-space:normal;"></div> <div id="divRadioBootPins" style="display:none;color:#e65100;font-size:12px;margin:-14px 0 14px 0;white-space:normal;"></div>
<div class="field-group" style="display:inline-block;width:auto;min-width:247px;margin-top:-20px;vertical-align:top;"> <div class="field-group" style="display:inline-block;width:auto;min-width:247px;margin-top:-20px;vertical-align:top;">
<div class="field-group"> <div class="field-group">

View file

@ -1973,13 +1973,16 @@ class Somfy {
let config = ProtoViews.radio(proto.schema, radio); let config = ProtoViews.radio(proto.schema, radio);
ui.toElement(document.getElementById('divTransceiverSettings'), { transceiver: { config: config } }); ui.toElement(document.getElementById('divTransceiverSettings'), { transceiver: { config: config } });
document.getElementById('divRadioError').style.display = config.radioInit ? 'none' : ''; document.getElementById('divRadioError').style.display = config.radioInit ? 'none' : '';
this.radioPinsFixed = !!config.fixedPins;
ProtoViews.showRadioPins(document, this.radioPinsFixed);
this.checkBootPins(); this.checkBootPins();
}); });
} }
// Warns of radio pins that can stop the board booting (issue #34). // Warns of radio pins that can stop the board booting (issue #34).
checkBootPins() { checkBootPins() {
let trans = ui.fromElement(document.getElementById('divTransceiverSettings')).transceiver; let trans = ui.fromElement(document.getElementById('divTransceiverSettings')).transceiver;
let warnings = BootPins.radioWarnings(chipModel(), trans.config); // The board's wiring is not the user's to move, so there is nothing to warn of.
let warnings = this.radioPinsFixed ? [] : BootPins.radioWarnings(chipModel(), trans.config);
let div = document.getElementById('divRadioBootPins'); let div = document.getElementById('divRadioBootPins');
div.innerText = warnings.join('\n'); div.innerText = warnings.join('\n');
div.style.display = warnings.length > 0 ? '' : 'none'; div.style.display = warnings.length > 0 ? '' : 'none';
@ -1993,7 +1996,7 @@ class Somfy {
ui.errorMessage('You must select a radio type.'); ui.errorMessage('You must select a radio type.');
valid = false; valid = false;
} }
// Check to make sure no pins were duplicated and defined // Check to make sure no pins were duplicated and defined. The board's own wiring is not checked.
if (valid) { if (valid) {
let fnValDup = (o, name) => { let fnValDup = (o, name) => {
let val = o[name]; let val = o[name];
@ -2022,12 +2025,12 @@ class Somfy {
} }
return true; return true;
}; };
if (valid) valid = fnValDup(trans.config, 'SCKPin'); if (valid && !this.radioPinsFixed) valid = fnValDup(trans.config, 'SCKPin');
if (valid) valid = fnValDup(trans.config, 'CSNPin'); if (valid && !this.radioPinsFixed) valid = fnValDup(trans.config, 'CSNPin');
if (valid) valid = fnValDup(trans.config, 'MOSIPin'); if (valid && !this.radioPinsFixed) valid = fnValDup(trans.config, 'MOSIPin');
if (valid) valid = fnValDup(trans.config, 'MISOPin'); if (valid && !this.radioPinsFixed) valid = fnValDup(trans.config, 'MISOPin');
if (valid) valid = fnValDup(trans.config, 'TXPin'); if (valid && !this.radioPinsFixed) valid = fnValDup(trans.config, 'TXPin');
if (valid) valid = fnValDup(trans.config, 'RXPin'); if (valid && !this.radioPinsFixed) valid = fnValDup(trans.config, 'RXPin');
if (valid) { if (valid) {
sendOp('saveSettings', ProtoViews.radioSave(trans.config), (err) => { sendOp('saveSettings', ProtoViews.radioSave(trans.config), (err) => {
if (err) ui.serviceError(err); if (err) ui.serviceError(err);

View file

@ -51,10 +51,20 @@ class ProtoViews {
static radioSave(config) { static radioSave(config) {
const fields = { section: 'radio', bitLength: config.type }; const fields = { section: 'radio', bitLength: config.type };
for (const name of ProtoViews.SETTINGS.radio) { for (const name of ProtoViews.SETTINGS.radio) {
if (name !== 'bitLength' && name !== 'radioInit') fields[name] = config[name]; if (name !== 'bitLength' && !ProtoViews.RADIO_SHOWN.includes(name)) fields[name] = config[name];
} }
return fields; return fields;
} }
// Where the radio is wired to the board (config.fixedPins) its six pins
// can't be changed: the pin selects are disabled and the note shown.
static showRadioPins(doc, fixed) {
for (const id of ProtoViews.RADIO_PIN_SELECTS) {
const el = doc.getElementById(id);
if (el) el.disabled = !!fixed;
}
const note = doc.getElementById(ProtoViews.RADIO_PINS_NOTE);
if (note) note.style.display = fixed ? '' : 'none';
}
// An op's refusal as the UI's error box shows it. A shade whose settings // An op's refusal as the UI's error box shows it. A shade whose settings
// don't add up carries the reason's number, which the errors table // don't add up carries the reason's number, which the errors table
// describes. // describes.
@ -66,6 +76,10 @@ class ProtoViews {
} }
ProtoViews.WIFI = ['ssid', 'hasPassphrase', 'roaming', 'hidden']; ProtoViews.WIFI = ['ssid', 'hasPassphrase', 'roaming', 'hidden'];
ProtoViews.ETHERNET = ['boardType', 'phyType', 'CLKMode', 'phyAddress', 'PWRPin', 'MDCPin', 'MDIOPin']; ProtoViews.ETHERNET = ['boardType', 'phyType', 'CLKMode', 'phyAddress', 'PWRPin', 'MDCPin', 'MDIOPin'];
// The radio fields the device only sends.
ProtoViews.RADIO_SHOWN = ['radioInit', 'fixedPins'];
ProtoViews.RADIO_PIN_SELECTS = ['selTransSCKPin', 'selTransCSNPin', 'selTransMOSIPin', 'selTransMISOPin', 'selTransTXPin', 'selTransRXPin'];
ProtoViews.RADIO_PINS_NOTE = 'divRadioPinsFixed';
ProtoViews.IP = ['dhcp', 'ip', 'gateway', 'subnet', 'dns1', 'dns2']; ProtoViews.IP = ['dhcp', 'ip', 'gateway', 'subnet', 'dns1', 'dns2'];
// The fields of each settings section, as getSettings sends them // The fields of each settings section, as getSettings sends them
// (src/DeviceOps.cpp). // (src/DeviceOps.cpp).
@ -75,6 +89,6 @@ ProtoViews.SETTINGS = {
mqtt: ['enabled', 'pubDisco', 'protocol', 'hostname', 'port', 'username', 'hasPassword', 'rootTopic', 'discoTopic'], mqtt: ['enabled', 'pubDisco', 'protocol', 'hostname', 'port', 'username', 'hasPassword', 'rootTopic', 'discoTopic'],
security: ['securityType', 'username', 'hasPassword', 'hasPin'], security: ['securityType', 'username', 'hasPassword', 'hasPin'],
radio: ['bitLength', 'proto', 'enabled', 'TXPin', 'RXPin', 'SCKPin', 'MOSIPin', 'MISOPin', 'CSNPin', 'frequency', 'rxBandwidth', radio: ['bitLength', 'proto', 'enabled', 'TXPin', 'RXPin', 'SCKPin', 'MOSIPin', 'MISOPin', 'CSNPin', 'frequency', 'rxBandwidth',
'deviation', 'txPower', 'noiseDetection', 'radioInit'] 'deviation', 'txPower', 'noiseDetection', 'radioInit', 'fixedPins']
}; };
if (typeof module !== 'undefined' && module.exports) module.exports = { ProtoViews }; if (typeof module !== 'undefined' && module.exports) module.exports = { ProtoViews };

View file

@ -139,7 +139,7 @@ The settings are in five sections. `getSettings` and `saveSettings` name one in
| `security` | `securityType`, `username`, `password`, `pin` | `/getSecurity`, `/saveSecurity` | | `security` | `securityType`, `username`, `password`, `pin` | `/getSecurity`, `/saveSecurity` |
| `radio` | `bitLength`, `proto`, `enabled`, `TXPin`, `RXPin`, `SCKPin`, `MOSIPin`, `MISOPin`, `CSNPin`, `frequency`, `rxBandwidth`, `deviation`, `txPower`, `noiseDetection` | `/getRadio`, `/saveRadio` | | `radio` | `bitLength`, `proto`, `enabled`, `TXPin`, `RXPin`, `SCKPin`, `MOSIPin`, `MISOPin`, `CSNPin`, `frequency`, `rxBandwidth`, `deviation`, `txPower`, `noiseDetection` | `/getRadio`, `/saveRadio` |
- **Reading.** `getSettings` replies with the section's fields. A secret is never sent: `hasPassphrase`, `hasPassword` and `hasPin` say whether one is set. `network` also has `hasEthernet`, and has the Ethernet fields only on a device with Ethernet. `radio` also has `radioInit`. - **Reading.** `getSettings` replies with the section's fields. A secret is never sent: `hasPassphrase`, `hasPassword` and `hasPin` say whether one is set. `network` also has `hasEthernet`, and has the Ethernet fields only on a device with Ethernet. `radio` also has `radioInit`, and `fixedPins` where the radio is wired to the board (the LILYGO T-Embed CC1101), left out on every other build. `fixedPins` means the six pins in the section are the board's and a client should show them as read-only: a save of other pins is applied with the board's pins and still replies as saved. Older clients and Home Assistant ignore the field.
- `connMode` is the connection the settings ask for: 1 WiFi, 2 Ethernet, 3 Ethernet with WiFi as the fallback. The header's `connType` is the connection in use. - `connMode` is the connection the settings ask for: 1 WiFi, 2 Ethernet, 3 Ethernet with WiFi as the fallback. The header's `connType` is the connection in use.
- **Saving.** `saveSettings` takes the section and the fields to change. As with every op, a field left out stays as it is. A secret sent empty keeps the stored one, except alongside a new `ssid` or MQTT `username`, as on the routes. - **Saving.** `saveSettings` takes the section and the fields to change. As with every op, a field left out stays as it is. A secret sent empty keeps the stored one, except alongside a new `ssid` or MQTT `username`, as on the routes.
- Every field is checked before anything is saved: - Every field is checked before anything is saved:
@ -148,7 +148,7 @@ The settings are in five sections. `getSettings` and `saveSettings` name one in
- a string's length, which is what the setting holds: `hostname` 31, `pin` 4, and so on; - a string's length, which is what the setting holds: `hostname` 31, `pin` 4, and so on;
- an address: four numbers 0–255, or `""` for none. - an address: four numbers 0–255, or `""` for none.
A bad request also comes for a field the section doesn't save (a `has*` field, `radioInit`, a field of another section, Ethernet on a device without it), and for a save with no fields. A bad request also comes for a field the section doesn't save (a `has*` field, `radioInit`, `fixedPins`, a field of another section, Ethernet on a device without it), and for a save with no fields.
- One save runs at a time, whichever client sent it: while one is waiting, another gets busy. - One save runs at a time, whichever client sent it: while one is waiting, another gets busy.
- The reply comes once the settings are saved and applied, as their route applies them. A saved time zone takes effect at once, where the route waited for a reboot. - The reply comes once the settings are saved and applied, as their route applies them. A saved time zone takes effect at once, where the route waited for a reboot.
- `rebooting` 1 means the device restarts a second later for them. That happens for a new `connMode`, for a new SSID or passphrase while on WiFi with nobody on the soft AP, and for Ethernet settings while on Ethernet. - `rebooting` 1 means the device restarts a second later for them. That happens for a new `connMode`, for a new SSID or passphrase while on WiFi with nobody on the soft AP, and for Ethernet settings while on Ethernet.

View file

@ -109,6 +109,7 @@ static void writeSettings(ProtoWriter &w, settings_section_t section) {
w.add(proto_field_t::txPower, cfg.txPower); w.add(proto_field_t::txPower, cfg.txPower);
w.add(proto_field_t::noiseDetection, cfg.noiseDetection); w.add(proto_field_t::noiseDetection, cfg.noiseDetection);
w.add(proto_field_t::radioInit, cfg.radioInit); w.add(proto_field_t::radioInit, cfg.radioInit);
writeRadioBoardFields(w, BoardProfile::integratedRadio);
break; break;
} }
} }

View file

@ -251,6 +251,7 @@
FIELD(txPower, "tp", 'i', 0) \ FIELD(txPower, "tp", 'i', 0) \
FIELD(noiseDetection, "nd", 'b', 0) \ FIELD(noiseDetection, "nd", 'b', 0) \
FIELD(radioInit, "ri", 'b', 0) \ FIELD(radioInit, "ri", 'b', 0) \
FIELD(fixedPins, "fx", 'b', 0) \
/* wifiNetworks: each network has ssid, channel and strength as above */ \ /* wifiNetworks: each network has ssid, channel and strength as above */ \
FIELD(networks, "nw", 'l', 0) \ FIELD(networks, "nw", 'l', 0) \
FIELD(macAddress, "ma", 's', 0) FIELD(macAddress, "ma", 's', 0)

View file

@ -25,7 +25,7 @@ static settings_section_t sectionOf(settings_part_t part) {
// What a save may set. lo..hi is a whole number's range, a number's in // What a save may set. lo..hi is a whole number's range, a number's in
// hundredths, and hi a string's longest length: what the setting holds, so the // hundredths, and hi a string's longest length: what the setting holds, so the
// route's fromJSON neither cuts it short nor wraps it. The has* fields and // route's fromJSON neither cuts it short nor wraps it. The has* fields and
// radioInit are only ever sent. // radioInit and fixedPins are only ever sent.
struct settings_field_t { struct settings_field_t {
settings_part_t part; settings_part_t part;
proto_field_t field; proto_field_t field;
@ -97,6 +97,10 @@ static const settings_field_t *saved(settings_section_t section, proto_field_t f
return nullptr; return nullptr;
} }
void writeRadioBoardFields(ProtoWriter &w, bool pinsFixed) {
w.add(proto_field_t::fixedPins, pinsFixed);
}
const char *parseSettingsSection(JsonObjectConst d, settings_section_t &section) { const char *parseSettingsSection(JsonObjectConst d, settings_section_t &section) {
const char *name = protoString(d, proto_field_t::section); const char *name = protoString(d, proto_field_t::section);
if(!name) return "section is missing"; if(!name) return "section is missing";

View file

@ -32,6 +32,11 @@ enum class settings_part_t : uint8_t {
radio // transceiver_config_t radio // transceiver_config_t
}; };
const char *settingsSectionName(settings_section_t section); const char *settingsSectionName(settings_section_t section);
// What the radio section says about the board rather than the config:
// fixedPins is set where the radio is wired to the board, so the six pins in
// the section are the board's and a save can't change them. Left out
// otherwise, so a client that doesn't know it never sees it.
void writeRadioBoardFields(ProtoWriter &w, bool pinsFixed);
// The section that payload d names in section. nullptr when it is good; // The section that payload d names in section. nullptr when it is good;
// otherwise what is wrong with it, for a bad request reply. // otherwise what is wrong with it, for a bad request reply.
const char *parseSettingsSection(JsonObjectConst d, settings_section_t &section); const char *parseSettingsSection(JsonObjectConst d, settings_section_t &section);

View file

@ -3,6 +3,6 @@
"t": 1, "t": 1,
"d": { "d": {
"fw": "v3.0.14", "fw": "v3.0.14",
"sh": "16fdffc7" "sh": "422f9a6e"
} }
} }

View file

@ -1,5 +1,5 @@
{ {
"hash": "16fdffc7", "hash": "422f9a6e",
"types": { "types": {
"1": "hello", "1": "hello",
"2": "reply", "2": "reply",
@ -294,6 +294,11 @@
"kind": "s", "kind": "s",
"default": 0 "default": 0
}, },
"fx": {
"name": "fixedPins",
"kind": "b",
"default": 0
},
"g": { "g": {
"name": "groupId", "name": "groupId",
"kind": "i", "kind": "i",

View file

@ -1148,6 +1148,12 @@
"b", "b",
0 0
], ],
[
"fx",
"fixedPins",
"b",
0
],
[ [
"nw", "nw",
"networks", "networks",

View file

@ -71,9 +71,40 @@ test('the radio section as the panel binds it, and back', () => {
assert.equal(save.frequency, 433.42); assert.equal(save.frequency, 433.42);
// Only shown, never saved. // Only shown, never saved.
assert.equal('radioInit' in save, false); assert.equal('radioInit' in save, false);
assert.equal('fixedPins' in save, false);
assert.equal('type' in save, false); assert.equal('type' in save, false);
}); });
function fakeDocument() {
const els = {};
for (const id of ProtoViews.RADIO_PIN_SELECTS) els[id] = { disabled: false };
els[ProtoViews.RADIO_PINS_NOTE] = { style: { display: 'none' } };
return { els, getElementById: (id) => els[id] || null };
}
test('the radio pins are fixed only where the device says so', () => {
assert.equal(ProtoViews.radio(schema, { bitLength: 80 }).fixedPins, false);
assert.equal(ProtoViews.radio(schema, { bitLength: 80, fixedPins: true }).fixedPins, true);
const fixed = fakeDocument();
ProtoViews.showRadioPins(fixed, ProtoViews.radio(schema, { fixedPins: true }).fixedPins);
assert.equal(ProtoViews.RADIO_PIN_SELECTS.length, 6);
for (const id of ProtoViews.RADIO_PIN_SELECTS) assert.equal(fixed.els[id].disabled, true, id);
assert.equal(fixed.els[ProtoViews.RADIO_PINS_NOTE].style.display, '');
// Without the flag they are editable, and a page that was fixed becomes editable again.
const free = fakeDocument();
ProtoViews.showRadioPins(free, true);
ProtoViews.showRadioPins(free, ProtoViews.radio(schema, {}).fixedPins);
for (const id of ProtoViews.RADIO_PIN_SELECTS) assert.equal(free.els[id].disabled, false, id);
assert.equal(free.els[ProtoViews.RADIO_PINS_NOTE].style.display, 'none');
});
test('every pin select and the note are in the page', () => {
const html = require('node:fs').readFileSync(require('node:path').join(__dirname, '../../data-src/index.html'), 'utf8');
for (const id of ProtoViews.RADIO_PIN_SELECTS.concat(ProtoViews.RADIO_PINS_NOTE)) assert.ok(html.includes(`id="${id}"`), id);
});
test('an op refusal for the error box, with a shade validation code', () => { test('an op refusal for the error box, with a shade validation code', () => {
assert.deepEqual(ProtoViews.opError('saveShade', { code: 'badRequest', desc: 'Pin in use', data: { validation: -10 } }), assert.deepEqual(ProtoViews.opError('saveShade', { code: 'badRequest', desc: 'Pin in use', data: { validation: -10 } }),
{ htmlError: 'badRequest', service: 'saveShade', desc: 'Pin in use', code: -10 }); { htmlError: 'badRequest', service: 'saveShade', desc: 'Pin in use', code: -10 });

View file

@ -2,6 +2,7 @@
#include <string> #include <string>
#include <ArduinoJson.h> #include <ArduinoJson.h>
#include "ProtoSettings.h" #include "ProtoSettings.h"
#include "JsonFormatter.h"
// Socket protocol 2's settings ops: the sections, and the settings route's // Socket protocol 2's settings ops: the sections, and the settings route's
// request that a save's payload becomes (docs/PROTOCOL.md). // request that a save's payload becomes (docs/PROTOCOL.md).
@ -161,6 +162,7 @@ static void test_what_is_only_sent_is_refused() {
TEST_ASSERT_EQUAL_STRING("hasPassphrase can't be saved in network", expand(R"({"se":"network","hq":1})")); TEST_ASSERT_EQUAL_STRING("hasPassphrase can't be saved in network", expand(R"({"se":"network","hq":1})"));
TEST_ASSERT_EQUAL_STRING("hasEthernet can't be saved in network", expand(R"({"se":"network","he":1})")); TEST_ASSERT_EQUAL_STRING("hasEthernet can't be saved in network", expand(R"({"se":"network","he":1})"));
TEST_ASSERT_EQUAL_STRING("radioInit can't be saved in radio", expand(R"({"se":"radio","ri":1})")); TEST_ASSERT_EQUAL_STRING("radioInit can't be saved in radio", expand(R"({"se":"radio","ri":1})"));
TEST_ASSERT_EQUAL_STRING("fixedPins can't be saved in radio", expand(R"({"se":"radio","fx":1})"));
} }
static void test_a_field_of_another_section_is_refused() { static void test_a_field_of_another_section_is_refused() {
TEST_ASSERT_EQUAL_STRING("ssid can't be saved in general", expand(R"({"se":"general","sd":"home"})")); TEST_ASSERT_EQUAL_STRING("ssid can't be saved in general", expand(R"({"se":"general","sd":"home"})"));
@ -202,6 +204,26 @@ static void test_a_route_name_belongs_to_its_section() {
TEST_ASSERT_EQUAL_UINT16(bit(settings_part_t::security), parts()); TEST_ASSERT_EQUAL_UINT16(bit(settings_part_t::security), parts());
} }
/*********************************************************************
* What the radio section says about the board
********************************************************************/
static std::string boardFields(bool pinsFixed) {
static BufferedJsonFormatter fmt;
static char buff[64];
fmt.setBuffer(buff, sizeof(buff));
ProtoWriter w(fmt);
fmt.beginObject();
writeRadioBoardFields(w, pinsFixed);
fmt.endObject();
return buff;
}
static void test_the_radio_pins_are_fixed_only_where_the_board_wires_them() {
TEST_ASSERT_EQUAL_STRING("{\"fx\":1}", boardFields(true).c_str());
// A generic board leaves it out, which is false to a client that knows it.
TEST_ASSERT_EQUAL_STRING("{}", boardFields(false).c_str());
TEST_ASSERT_EQUAL_STRING("fixedPins", protoFieldByKey("fx")->name);
}
int main(int argc, char **argv) { int main(int argc, char **argv) {
UNITY_BEGIN(); UNITY_BEGIN();
RUN_TEST(test_every_section_by_its_name); RUN_TEST(test_every_section_by_its_name);
@ -226,5 +248,6 @@ int main(int argc, char **argv) {
RUN_TEST(test_ethernet_needs_a_chip_with_it); RUN_TEST(test_ethernet_needs_a_chip_with_it);
RUN_TEST(test_a_save_sets_the_parts_it_has_fields_of); RUN_TEST(test_a_save_sets_the_parts_it_has_fields_of);
RUN_TEST(test_a_route_name_belongs_to_its_section); RUN_TEST(test_a_route_name_belongs_to_its_section);
RUN_TEST(test_the_radio_pins_are_fixed_only_where_the_board_wires_them);
return UNITY_END(); return UNITY_END();
} }