Skip to content

Commit 63cd825

Browse files
committed
add pub_sub test
1 parent c8db568 commit 63cd825

File tree

2 files changed

+81
-0
lines changed

2 files changed

+81
-0
lines changed

.tests/pub_sub/config.template

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/************************ Adafruit IO Config *******************************/
2+
3+
#define IO_USERNAME "${io_username}"
4+
#define IO_KEY "${io_key}"
5+
6+
/******************************* WIFI **************************************/
7+
8+
#define WIFI_SSID "${wifi_ssid}"
9+
#define WIFI_PASS "${wifi_pass}"
10+
11+
<%
12+
if (["ESP8266", "M0_WINC1500", "WICED", "MKR1000"].contains(platform)) {
13+
println '#include "AdafruitIO_WiFi.h"'
14+
println 'AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);'
15+
}
16+
%>
17+
18+
/******************************* FONA **************************************/
19+
20+
<%
21+
if (["FONA_32U4"].contains(platform)) {
22+
println '#include "AdafruitIO_FONA.h"'
23+
println 'AdafruitIO_FONA io(IO_USERNAME, IO_KEY);'
24+
}
25+
%>
26+
27+
/**************************** ETHERNET ************************************/
28+
29+
<%
30+
if (["M0_ETHERNETWING"].contains(platform)) {
31+
println '#include "AdafruitIO_Ethernet.h"'
32+
println 'AdafruitIO_Ethernet io(IO_USERNAME, IO_KEY);'
33+
}
34+
%>

.tests/pub_sub/pub_sub.ino

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#include <ArduinoTap.h>
2+
#include "config.h"
3+
4+
/************************ Example Starts Here *******************************/
5+
6+
AdafruitIO_Feed *pubsub = io.feed("pubsub");
7+
char time[] = __TIME__;
8+
9+
void setup() {
10+
11+
// start the serial connection
12+
Serial.begin(115200);
13+
14+
// wait for serial monitor to open
15+
while(! Serial);
16+
17+
delay(3000);
18+
19+
plan(2);
20+
21+
io.connect();
22+
pubsub->onMessage(handleMessage);
23+
24+
while(io.status() < AIO_CONNECTED) {
25+
delay(500);
26+
}
27+
28+
ok(io.status() > AIO_CONNECTED, "connected to IO");
29+
ok(pubsub->save(time), "sent message");
30+
31+
}
32+
33+
void loop() {
34+
io.run();
35+
}
36+
37+
void handleMessage(AdafruitIO_Data *data) {
38+
ok(compareChar(time, data->value()), "message received");
39+
done_testing();
40+
}
41+
42+
43+
bool compareChar(char *a, char *b)
44+
{
45+
return strcmp(a,b) == 0;
46+
}
47+

0 commit comments

Comments
 (0)