1
1
// This #include statement was automatically added by the Spark IDE.
2
- #include " tentacle-particle/tentacle-particle .h"
2
+ #include " tentacle-particle.h"
3
3
4
- // #define server "tentacle.octoblu.com"
5
- // #define port 80
4
+ #define server " tentacle.octoblu.com"
5
+ #define port 80
6
6
7
+ // IPAddress server(192,168,100,9);
8
+ // #define port 8111
7
9
8
- IPAddress server (192 ,168 ,0 ,112 );
9
- #define port 8111
10
-
11
- static const char uuid[] = " ff12c403-04c7-4e63-9073-2e3b1f8e4450" ;
12
- static const char token[] = " 28d2c24dfa0a5289799a345e683d570880a3bc41" ;
10
+ static const char uuid[] = " 91f33395-847a-4d71-af25-fd3abe3371bc" ;
11
+ static const char token[] = " 24fefe99413b16283f41c7cf8c82d376211392f7" ;
13
12
14
13
TCPClient conn;
15
14
16
15
TentacleArduino tentacle;
17
16
Pseudopod pseudopod (conn, conn, tentacle);
18
17
18
+ uint32_t lastPing = 0 ;
19
+
19
20
void setup () {
20
21
Serial.begin (9600 );
21
22
Serial.println (F (" The Day of the Tentacle has begun!" ));
22
- waitForWifi ();
23
23
connectToServer ();
24
24
}
25
25
26
26
void loop () {
27
- if (!WiFi.ready ()) {
28
- Serial.println (F (" WiFi wasn't ready. waiting." ));
29
- }
30
- if (!conn.connected ()) {
27
+ if (!isConnected ()) {
31
28
conn.stop ();
32
29
connectToServer ();
33
30
}
@@ -40,26 +37,36 @@ void loop() {
40
37
Serial.print (configSize);
41
38
Serial.print (F (" bytes written while broadcasting pins" ));
42
39
}
40
+
43
41
}
44
42
45
- void readData () {
43
+ bool isConnected () {
44
+ if (!conn.connected ()) {
45
+ return false ;
46
+ }
47
+
48
+ // send keepalive every 5 seconds.
49
+ if ( (millis () - lastPing) > 5000 ) {
50
+ Serial.println (F (" Pinging the server" ));
51
+ Serial.flush ();
52
+ lastPing = millis ();
53
+ return pseudopod.isConnected ();
54
+
55
+ }
56
+
57
+ return true ;
58
+ }
46
59
60
+ void readData () {
47
61
while (conn.available ()) {
48
62
Serial.println (F (" Received message" ));
49
63
Serial.flush ();
50
64
51
65
if (pseudopod.readMessage () == TentacleMessageTopic_action) {
66
+ Serial.println (F (" Got an action message" ));
52
67
pseudopod.sendPins ();
53
68
}
54
69
}
55
-
56
- }
57
-
58
- void waitForWifi () {
59
- while (!WiFi.ready ()) {
60
- Serial.println (F (" Waiting for wifi" ));
61
- delay (200 );
62
- }
63
70
}
64
71
65
72
void connectToServer () {
@@ -77,5 +84,4 @@ void connectToServer() {
77
84
size_t authSize = pseudopod.authenticate (uuid, token);
78
85
Serial.print (authSize);
79
86
Serial.println (F (" bytes written for authentication" ));
80
-
81
87
}
0 commit comments