Skip to content

Commit 5dd0758

Browse files
committed
Merge branch 'test' into new_call_api
2 parents 47376bf + 76a137d commit 5dd0758

File tree

2 files changed

+85
-0
lines changed

2 files changed

+85
-0
lines changed

examples/test/server_test

3.97 MB
Binary file not shown.

examples/test/test.ino

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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("\r\n"+String(i));
39+
i++;
40+
41+
// working
42+
Bridge.call("0_args_no_result");
43+
44+
if (Bridge.call("0_args_no_result")){
45+
Monitor.println("0_args_no_result TRUE without result"); // return true because no result
46+
}
47+
else{
48+
Monitor.println("0_args_no_result FALSE without result");
49+
}
50+
51+
if (Bridge.call("0_args_bool_result")){
52+
Monitor.println("0_args_bool_result TRUE without result");
53+
}
54+
else{
55+
Monitor.println("0_args_bool_result FALSE without result"); // return false because you need check the result
56+
}
57+
58+
x=false;
59+
if (Bridge.call("0_args_bool_result").result(x)){
60+
Monitor.println("0_args_bool_result TRUE with result: "+String(x)); // return true - the perfect call
61+
}
62+
else{
63+
Monitor.println("0_args_bool_result FALSE witt result: "+String(x));
64+
}
65+
66+
int y = -1;
67+
if (Bridge.call("0_args_bool_result").result(y)){
68+
Monitor.println("0_args_bool_result TRUE with result: "+String(y)+" (wrong result type)"); // return true - the perfect call
69+
}
70+
else{
71+
Monitor.println("0_args_bool_result FALSE with result: "+String(y)+" (wrong result type)");
72+
}
73+
74+
75+
// avoid to do followings
76+
77+
RpcResult result = Bridge.call("0_args_bool_result"); // the call happens but you won't get the result
78+
79+
bool x = false;
80+
RpcResult result2 = Bridge.call("0_args_bool_result");
81+
result2.result(x);
82+
Monitor.println("Result of assignment and then result: "+String(x)); // return true, so the right result
83+
84+
delay(1000);
85+
}

0 commit comments

Comments
 (0)