|
1 | 1 | #include <webp/decode.h> |
2 | 2 | #include <webp/demux.h> |
3 | 3 |
|
| 4 | +#include <unistd.h> |
| 5 | + |
4 | 6 | #include <chrono> |
5 | 7 | #include <deque> |
6 | 8 | #include <fstream> |
@@ -42,6 +44,15 @@ struct AppState { |
42 | 44 |
|
43 | 45 | static AppState *g_app_state = nullptr; |
44 | 46 |
|
| 47 | +static std::string get_hostname() { |
| 48 | + char buf[256]; |
| 49 | + if (gethostname(buf, sizeof(buf)) == 0) { |
| 50 | + buf[sizeof(buf) - 1] = '\0'; |
| 51 | + return buf; |
| 52 | + } |
| 53 | + return "unknown"; |
| 54 | +} |
| 55 | + |
45 | 56 | static std::string get_mac_address() { |
46 | 57 | for (const char *iface_name : {"eth0", "wlan0"}) { |
47 | 58 | std::ifstream iface(std::format("/sys/class/net/{}/address", iface_name)); |
@@ -385,7 +396,9 @@ int main(int argc, char *argv[]) { |
385 | 396 | {{"firmware_version", FIRMWARE_VERSION}, |
386 | 397 | {"firmware_type", FIRMWARE_TYPE}, |
387 | 398 | {"protocol_version", PROTOCOL_VERSION}, |
388 | | - {"mac", get_mac_address()}}}}; |
| 399 | + {"mac", get_mac_address()}, |
| 400 | + {"hostname", get_hostname()}, |
| 401 | + {"image_url", url}}}}; |
389 | 402 | Log(state, "Sending client info: " + client_info_msg.dump()); |
390 | 403 | ws_client->send(client_info_msg.dump()); |
391 | 404 | } else if (msg.type == ws::MessageType::Message) { |
@@ -438,6 +451,13 @@ int main(int argc, char *argv[]) { |
438 | 451 | state.queue_not_full.notify_all(); |
439 | 452 | immediate_requests++; |
440 | 453 | } |
| 454 | + } else if (json_message.contains("reboot") && |
| 455 | + json_message["reboot"].is_boolean()) { |
| 456 | + if (json_message["reboot"].get<bool>()) { |
| 457 | + Log(state, "Reboot requested via WebSocket"); |
| 458 | + std::cerr << "Rebooting..." << std::endl; |
| 459 | + system("sudo reboot"); |
| 460 | + } |
441 | 461 | } else if (json_message.contains("status") && |
442 | 462 | json_message["status"].is_string() && |
443 | 463 | json_message.contains("message") && |
@@ -471,7 +491,8 @@ int main(int argc, char *argv[]) { |
471 | 491 | } |
472 | 492 | client->set_default_headers( |
473 | 493 | {{"User-Agent", "Tronberry/1.0"}, |
474 | | - {"Accept", "image/webp, image/*;q=0.8, */*;q=0.5"}}); |
| 494 | + {"Accept", "image/webp, image/*;q=0.8, */*;q=0.5"}, |
| 495 | + {"X-Firmware-Version", FIRMWARE_VERSION}}); |
475 | 496 | client->set_connection_timeout(30); |
476 | 497 | client->set_read_timeout(30); |
477 | 498 | auto path = path_start != std::string::npos |
|
0 commit comments