https://github.com/shuai132/esp_rpc
Tiny RPC library for ESP8266/ESP32 based on rpc_core
https://github.com/shuai132/esp_rpc
arduino esp32 esp8266 esp8266-arduino rpc
Last synced: about 2 months ago
JSON representation
Tiny RPC library for ESP8266/ESP32 based on rpc_core
- Host: GitHub
- URL: https://github.com/shuai132/esp_rpc
- Owner: shuai132
- Created: 2022-11-03T10:26:59.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-09-21T08:04:26.000Z (over 1 year ago)
- Last Synced: 2025-03-21T02:51:05.104Z (2 months ago)
- Topics: arduino, esp32, esp8266, esp8266-arduino, rpc
- Language: C++
- Homepage:
- Size: 33.2 KB
- Stars: 10
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# esp_rpc
a Tiny RPC library for ESP32/ESP8266, and can be ported to any platform easily.
RPC based on [rpc_core](https://github.com/shuai132/rpc_core)
## Requirements
* C++11
* implement
```c++
namespace esp_rpc {
void dispatch(std::function runnable) {
// dispatch runnable to main thread looper
// because tcp callback may from interrupt or other thread
}void set_timeout(uint32_t ms, std::function cb) {
// timeout implement
}
} // namespace esp_rpc
```## Usage
* RPC
```c++
// server
rpc_server server(8080);
server.on_session = [](const std::weak_ptr& rs) {
auto session = rs.lock();
session->on_close = [rs] {
};
session->rpc->subscribe("cmd", [](const std::string& data) -> std::string {
return "world";
});
};
server.start();
``````c++
// client
rpc_client client;
client.on_open = [&](const std::shared_ptr& rpc) {
rpc->cmd("cmd")
->msg(std::string("hello"))
->rsp([&](const std::string& data) {
})
->call();
};
client.on_close = [&] {
};
client.open("localhost", 8080);
```# Links
* for the platform with Operating System, there is a library based on
asio: [asio_net](https://github.com/shuai132/asio_net)