| 191 | } |
| 192 | |
| 193 | std::string LoadOrCreateDeviceId(const std::string& data_dir) { |
| 194 | const auto path = std::filesystem::path(data_dir) / "device.id"; |
| 195 | std::ifstream in(path); |
| 196 | std::string id; |
| 197 | if (in >> id; !id.empty()) return id; |
| 198 | |
| 199 | id = GenerateUuid(); |
| 200 | std::filesystem::create_directories(path.parent_path()); |
| 201 | std::ofstream out(path, std::ios::trunc); |
| 202 | out << id << "\n"; |
| 203 | return id; |
| 204 | } |
| 205 | |
| 206 | // device.token holds the long-lived shared secret minted by the cloud after |
| 207 | // the operator confirms pairing in the browser. Phase 3 stores it raw on |