ranczo-io/services/energymeter_svc/main.cpp
Bartosz Wieczorek 6da01a2f6b Add HTTP get
2025-12-12 16:57:05 +01:00

41 lines
864 B
C++

#include <boost/asio.hpp>
#include <boost/system/error_code.hpp>
#include <fmt/core.h>
#include <iostream>
#include <memory_resource>
#include <spdlog/spdlog.h>
#include <config.hpp>
#include <ranczo-io/utils/http.hpp>
namespace ranczo {
} // namespace ranczo
int main() {
boost::asio::io_context io;
boost::asio::co_spawn(
io,
[&]() -> ranczo::awaitable< void > {
ranczo::HttpGetClient cli{io.get_executor()};
auto r = co_await cli.async_get("http://192.168.20.11:80/state", std::pmr::get_default_resource());
if(!r) {
spdlog::error("HTTP GET failed: {}", r.error().message());
} else {
std::cout << *r;
// spdlog::info("Response: {}", *r);
}
co_return;
},
boost::asio::detached);
io.run();
}