Skip to content

Commit 33cf861

Browse files
committed
added test sketch
1 parent a06e182 commit 33cf861

File tree

2 files changed

+76
-0
lines changed

2 files changed

+76
-0
lines changed

examples/test/server_test

3.97 MB
Binary file not shown.

examples/test/test.ino

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
This file is part of the Arduino_RouterBridge library.
3+
4+
Copyright (c) 2025 Arduino SA
5+
6+
This Source Code Form is subject to the terms of the Mozilla Public
7+
License, v. 2.0. If a copy of the MPL was not distributed with this
8+
file, You can obtain one at http://mozilla.org/MPL/2.0/.
9+
10+
*/
11+
12+
// to run this test example, launch server_test in a shell and then this sketch
13+
14+
15+
/* available registers
16+
register("ping")
17+
register("0_args_no_result")
18+
register("1_args_no_result")
19+
register("2_args_no_result")
20+
register("0_args_bool_result")
21+
register("1_args_bool_result")
22+
register("2_args_bool_result")
23+
*/
24+
25+
#include "Arduino_RouterBridge.h"
26+
27+
bool x;
28+
int i=0;
29+
30+
void setup() {
31+
Bridge.begin();
32+
Monitor.begin();
33+
}
34+
35+
void loop() {
36+
37+
//testing monitor
38+
Monitor.println(String(i)+"\t"+String(x));
39+
i++;
40+
//working
41+
Bridge.call("0_args_no_result");
42+
43+
if (Bridge.call("0_args_no_result")){
44+
Monitor.println("ok"); // return true because no result
45+
}
46+
else{
47+
Monitor.println("no");
48+
}
49+
50+
if (Bridge.call("0_args_bool_result")){
51+
Monitor.println("ok");
52+
}
53+
else{
54+
Monitor.println("no"); // return false because you need check the result
55+
}
56+
57+
x=false;
58+
if (Bridge.call("0_args_bool_result").result(x)){
59+
Monitor.println("ok "+String(x)); // return true - the perfect call
60+
}
61+
else{
62+
Monitor.println("no "+String(x));
63+
}
64+
65+
66+
//avoid to do followings
67+
68+
RpcResult result = Bridge.call("0_args_bool_result"); // the call happens but you won't get the result
69+
70+
bool x = false;
71+
RpcResult result2 = Bridge.call("0_args_bool_result");
72+
result2.result(x);
73+
Monitor.println("Result: "+String(x)); // return true, so the right result
74+
75+
delay(1000);
76+
}

0 commit comments

Comments
 (0)