     // EVERY_N_MILLISECONDS(20) { animations->hueCounter++; } // slowly cycle the "base color" through the rainbow
 }
 
-// void readColorFromRemote() {
-//   client.println("s");
-//   if(client.available()) {
-//       char hueFromController[3];
-//       int readCount = 0;
-//       while(client.available()) {
-//           char c = client.read();
-//           hueFromController[readCount] = c;
-//           readCount++;
-//       }
-//       hueValue = atoi(hueFromController);
-//   }
-//   animations->hueCounter = hueValue;
-// }
+void readColorFromRemote() {
+   if(client.available()) {
+     hueValue = client.read() << 8 | client.read();
+     /*Serial.printlnf("Reading from remote: %d", hueValue);*/
+   }
+   while(client.read() != -1) {
+     /*Serial.println("Shelf lost bytes");*/
+   }
+   client.flush();
+   /*Serial.printlnf("Final from remote: %d", hueValue);*/
+   animations->hueCounter = hueValue;
+}
 
-// void connectToRemote() {
-//   if (client.connect(server, tcpPort)) {
-//       Serial.println("Connected");
-//       Particle.publish("Connected");
-//   } else {
-//       Serial.println("Connection failed");
-//       Particle.publish("Connection failed");
-//   }
-// }
+void connectToRemote() {
+ if (client.connect(server, tcpPort)) {
+     Serial.println("Connected");
+     Particle.publish("Connected");
+ } else {
+     Serial.println("Connection failed");
+     Particle.publish("Connection failed");
+ }
+}
 
 void setupModeFunctions() {
   Particle.function("nextMode", nextMode);


int nextMode(String mode) {
    int currentPattern = animations->nextPattern();
    /*char currentPatternString[5];
    sprintf(currentPatternString, "%i", currentPattern);
    Particle.publish("Current Pattern", currentPatternString);*/
    return 1;
}


  }

void loop() {
    if(client.connected()) {
        readColorFromRemote();
    } else {
      connectToRemote();
    }

    animations->runCurrentAnimation();
    FastLED.show();
