Skip to content

Instantly share code, notes, and snippets.

@redaphid
Created July 26, 2015 00:37
Show Gist options
  • Save redaphid/991a7903605964d56f4f to your computer and use it in GitHub Desktop.
Save redaphid/991a7903605964d56f4f to your computer and use it in GitHub Desktop.
#include <Bridge.h>
#include <YunClient.h>
#include "tentacle-build.h"
IPAddress server(192,168,1,69);
#define port 8111
static const char uuid[] = "1335d63e-3494-45d7-9e0b-d08c42818c6d";
static const char token[] = "3dd5fe1764ab21ae07ea20f16c3b0e63fa30e6c8";
YunClient conn;
TentacleArduino tentacle;
Pseudopod pseudopod(conn, conn, tentacle);
void setup() {
Serial.begin(9600);
Serial.println(F("The Day of the Tentacle has begun!"));
Bridge.begin();
connectToServer();
}
void loop() {
if (!conn.connected()) {
conn.stop();
connectToServer();
}
readData();
if(pseudopod.shouldBroadcastPins() ) {
delay(pseudopod.getBroadcastInterval());
Serial.println(F("Sending pins"));
pseudopod.sendConfiguredPins();
}
}
void readData() {
while (conn.available()) {
Serial.println(F("Received message"));
Serial.flush();
if(pseudopod.readMessage() == TentacleMessageTopic_action) {
pseudopod.sendPins();
}
}
}
void connectToServer() {
Serial.println(F("Connecting to the server."));
Serial.flush();
while(!conn.connect(server, port)) {
Serial.println(F("Can't connect to the server."));
Serial.flush();
conn.stop();
}
size_t authSize = pseudopod.authenticate(uuid, token);
Serial.print(authSize);
Serial.println(F(" bytes written for authentication"));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment