Skip to content

Commit 1bdabf2

Browse files
author
Maksym Shtembuliak
committed
Always advertise ESP bridge identity
1 parent e08aa7e commit 1bdabf2

4 files changed

Lines changed: 28 additions & 15 deletions

File tree

‎components/eybond_collector/at_handler.cpp‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,15 @@ bool normalize_command(const std::string &raw, std::string *out) {
4646
return true;
4747
}
4848

49+
std::string vdtu_value(const CollectorProfile &profile) {
50+
if (!profile.vdtu.empty()) {
51+
return profile.vdtu;
52+
}
53+
return std::string("esp-collector,") + BRIDGE_VERSION +
54+
";features=local_only,no_cloud,wifi_params,endpoint_write" +
55+
";uart=" + profile.uart;
56+
}
57+
4958
} // namespace
5059

5160
bool parse_at_line(const std::string &line, AtCommand *out) {
@@ -128,10 +137,10 @@ std::string build_at_reply(const AtCommand &command, const CollectorProfile &pro
128137
return build_at_response(name, profile.wifi_scan_list);
129138
}
130139
if (name == "VDTU") {
131-
// Virtual-DTU capability probe: lets a future integration version detect
132-
// the bridge. With an empty profile.vdtu this is byte-identical to the
133-
// factory reference reply for unknown commands.
134-
return build_at_response(name, profile.vdtu);
140+
// Virtual-DTU capability probe. The public ESP bridge must fail closed to
141+
// "local bridge" identity; an empty/factory-like reply makes HA expose
142+
// cloud-only controls for a virtual collector.
143+
return build_at_response(name, vdtu_value(profile));
135144
}
136145
return build_at_response(name, "");
137146
}

‎components/eybond_collector/profile.h‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
namespace eybond {
99

1010
// Bridge firmware version, advertised via AT+VDTU (virtual-DTU capability probe).
11-
constexpr const char *BRIDGE_VERSION = "0.1.3";
11+
constexpr const char *BRIDGE_VERSION = "0.1.4";
1212

1313
struct CollectorProfile {
1414
std::string pn; // set at startup (config override or synthesized from MAC)
@@ -20,8 +20,9 @@ struct CollectorProfile {
2020
std::string link_status = "connected";
2121
std::string wifi_scan_list; // AT+INTPARA49
2222
// AT+VDTU capability string ("esp-collector,<ver>;features=...;uart=...").
23-
// Empty -> reply carries an empty value, byte-identical to the factory
24-
// reference behavior for unknown commands; the platform glue opts in.
23+
// The firmware must always identify itself as an ESP bridge. If this field is
24+
// empty, the AT handler emits a minimal fallback identity instead of a
25+
// factory-like empty reply.
2526
std::string vdtu;
2627
};
2728

‎host_tests/test_at.cpp‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,18 @@ TEST(at_lower_case_normalized) {
8282
}
8383

8484
TEST(at_vdtu_capability_probe) {
85-
// Default profile: no capability string -> byte-identical to the factory
86-
// reference reply for an unknown command.
87-
CHECK_STR(reply_for("AT+VDTU?\r\n"), "AT+VDTU:\r\n");
85+
// Default profile still advertises the ESP bridge identity. The firmware must
86+
// not fall back to a factory-like empty VDTU reply because HA uses this probe
87+
// to hide cloud-only controls for virtual collectors.
88+
CHECK_STR(reply_for("AT+VDTU?\r\n"),
89+
"AT+VDTU:esp-collector,0.1.4;features=local_only,no_cloud,wifi_params,endpoint_write;"
90+
"uart=2400,8,1,NONE\r\n");
8891

8992
CollectorProfile profile = test_profile();
90-
profile.vdtu = "esp-collector,0.1.3;features=local_only,no_cloud,wifi_params,endpoint_write;uart=2400,8,1,NONE;spacing_ms=850;queue=4";
93+
profile.vdtu = "esp-collector,0.1.4;features=local_only,no_cloud,wifi_params,endpoint_write;uart=2400,8,1,NONE;spacing_ms=850;queue=4";
9194
AtCommand command;
9295
CHECK(parse_at_line("AT+VDTU?\r\n", &command));
9396
CHECK_STR(build_at_reply(command, profile, test_runtime()),
94-
"AT+VDTU:esp-collector,0.1.3;features=local_only,no_cloud,wifi_params,endpoint_write;uart=2400,8,1,NONE;"
97+
"AT+VDTU:esp-collector,0.1.4;features=local_only,no_cloud,wifi_params,endpoint_write;uart=2400,8,1,NONE;"
9598
"spacing_ms=850;queue=4\r\n");
9699
}

‎host_tests/test_core.cpp‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -354,14 +354,14 @@ TEST(core_vdtu_capabilities_string) {
354354
CollectorProfile profile = Fixture::make_profile();
355355
CoreConfig config;
356356
CHECK_STR(build_vdtu_capabilities(profile, config),
357-
"esp-collector,0.1.3;features=local_only,no_cloud,wifi_params,endpoint_write;uart=2400,8,1,NONE;"
357+
"esp-collector,0.1.4;features=local_only,no_cloud,wifi_params,endpoint_write;uart=2400,8,1,NONE;"
358358
"spacing_ms=850;queue=4");
359359

360360
config.command_spacing_ms = 100;
361361
config.forward_queue_limit = 8;
362362
profile.uart = "9600,8,1,NONE";
363363
CHECK_STR(build_vdtu_capabilities(profile, config),
364-
"esp-collector,0.1.3;features=local_only,no_cloud,wifi_params,endpoint_write;uart=9600,8,1,NONE;"
364+
"esp-collector,0.1.4;features=local_only,no_cloud,wifi_params,endpoint_write;uart=9600,8,1,NONE;"
365365
"spacing_ms=100;queue=8");
366366
}
367367

@@ -383,7 +383,7 @@ TEST(core_vdtu_served_over_tcp) {
383383
const auto calls = actions.take();
384384
CHECK(calls.size() == 1);
385385
CHECK_STR(std::string(calls[0].data.begin(), calls[0].data.end()),
386-
"AT+VDTU:esp-collector,0.1.3;features=local_only,no_cloud,wifi_params,endpoint_write;uart=2400,8,1,NONE;"
386+
"AT+VDTU:esp-collector,0.1.4;features=local_only,no_cloud,wifi_params,endpoint_write;uart=2400,8,1,NONE;"
387387
"spacing_ms=850;queue=4\r\n");
388388
}
389389

0 commit comments

Comments
 (0)