You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+78Lines changed: 78 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,6 +2,84 @@
2
2
3
3
A MessagePack RPC library for Arduino allows to create a client/server architecture using MessagePack as the serialization format. It follows the [MessagePack-RPC protocol specification](https://github.com/msgpack-rpc/msgpack-rpc/blob/master/spec.md). It is designed to be lightweight and easy to use, making it suitable for embedded systems and IoT applications.
4
4
5
+
6
+
## Server
7
+
8
+
```cpp
9
+
#include<Arduino_RPClite.h>
10
+
11
+
RPCServer server(Serial1);
12
+
13
+
int add(int a, int b){
14
+
return a+b;
15
+
}
16
+
17
+
String loopback(String message){
18
+
return message;
19
+
}
20
+
21
+
void setup() {
22
+
Serial1.begin(115200);
23
+
while(!Serial1);
24
+
25
+
Serial.begin(9600);
26
+
while(!Serial);
27
+
28
+
server.bind("add", add);
29
+
server.bind("loopback", loopback);
30
+
31
+
}
32
+
33
+
void loop() {
34
+
server.run();
35
+
}
36
+
37
+
```
38
+
39
+
40
+
## Client
41
+
42
+
```cpp
43
+
#include <Arduino_RPClite.h>
44
+
45
+
RPCClient client(Serial1);
46
+
47
+
void setup() {
48
+
Serial1.begin(115200);
49
+
while(!Serial1);
50
+
51
+
pinMode(LED_BUILTIN, OUTPUT);
52
+
53
+
Serial.begin(9600);
54
+
while(!Serial);
55
+
}
56
+
57
+
void loop() {
58
+
59
+
bool ok;
60
+
61
+
String response;
62
+
ok = client.call("loopback", response, "Sending a greeting");
63
+
if (ok) Serial.println(str_res);
64
+
65
+
int sum_result;
66
+
ok = client.call("add", sum_result, 2. 3);
67
+
if (ok) Serial.println(sum_result); // must print 5
68
+
69
+
// ERROR handling
70
+
float result;
71
+
bool ok = client.call("unbound_method", result, 10.0);
72
+
if (!ok) {
73
+
Serial.print("Testing Server-side exception OK. ERR code: ");
74
+
Serial.print(client.lastError.code);
75
+
Serial.print(" ERR trace: ");
76
+
Serial.println(client.lastError.traceback);
77
+
}
78
+
79
+
}
80
+
81
+
```
82
+
5
83
### Credits
6
84
7
85
This library is based on the MsgPack library by @hideakitai.
0 commit comments