Skip to content

Commit 8f59bc1

Browse files
author
Federico Fissore
committed
SpacebrewYun: added new example
1 parent dec06c0 commit 8f59bc1

File tree

4 files changed

+591
-0
lines changed

4 files changed

+591
-0
lines changed
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
#include <Bridge.h>
2+
#include <SpacebrewYun.h>
3+
4+
/**
5+
* Arduino Yun Spacebrew Library Example
6+
*
7+
* This example code is in the public domain.
8+
*
9+
* @date July 16, 2013
10+
* @author Julio Terra
11+
*
12+
*/
13+
14+
SpacebrewYun sb = SpacebrewYun("aYun", "Arduino Yun spacebrew test");
15+
16+
int counter = 0;
17+
long last = 0;
18+
int interval = 2000;
19+
20+
void setup() {
21+
22+
Serial.begin(57600);
23+
delay(4000);
24+
while (!Serial) { Serial.println("connecting"); }
25+
26+
27+
//Initialize Console and wait for port to open:
28+
Bridge.begin();
29+
Serial.println("Bridge Started");
30+
31+
Serial.println("Configuring Spacebrew Client");
32+
sb.verbose(true);
33+
sb.addPublish("string test", "string");
34+
sb.addPublish("range test", "range");
35+
sb.addPublish("boolean test", "boolean");
36+
sb.addPublish("custom test", "crazy");
37+
sb.addSubscribe("string test", "string");
38+
sb.addSubscribe("range test", "range");
39+
sb.addSubscribe("boolean test", "boolean");
40+
sb.addSubscribe("custom test", "crazy");
41+
sb.onRangeMessage(handleRange);
42+
sb.onStringMessage(handleString);
43+
sb.onBooleanMessage(handleBoolean);
44+
sb.onCustomMessage(handleCustom);
45+
sb.connect("sandbox.spacebrew.cc");
46+
47+
}
48+
49+
50+
void loop() {
51+
sb.monitor();
52+
if ( sb.connected() ) {
53+
if ( (millis() - last) > interval ) {
54+
String test_str_msg = "testing, testing, ";
55+
test_str_msg += counter;
56+
counter ++;
57+
58+
sb.send("string test", test_str_msg);
59+
sb.send("range test", 500);
60+
sb.send("boolean test", true);
61+
sb.send("custom test", "youre loco");
62+
63+
last = millis();
64+
65+
}
66+
}
67+
}
68+
69+
void handleRange (String route, int value) {
70+
Serial.print("Range msg ");
71+
Serial.print(route);
72+
Serial.print(", value ");
73+
Serial.println(value);
74+
}
75+
76+
void handleString (String route, String value) {
77+
Serial.print("String msg ");
78+
Serial.print(route);
79+
Serial.print(", value ");
80+
Serial.println(value);
81+
}
82+
83+
void handleBoolean (String route, boolean value) {
84+
Serial.print("Boolen msg ");
85+
Serial.print(route);
86+
Serial.print(", value ");
87+
Serial.println(value ? "true" : "false");
88+
}
89+
90+
void handleCustom (String route, String value, String type) {
91+
Serial.print("Custom msg ");
92+
Serial.print(route);
93+
Serial.print(" of type ");
94+
Serial.print(type);
95+
Serial.print(", value ");
96+
Serial.println(value);
97+
}
98+

0 commit comments

Comments
 (0)