Created
April 9, 2017 08:50
-
-
Save zaifz/20f6eea68525f779ac1bbd42966e02a8 to your computer and use it in GitHub Desktop.
IoT Noise Reduction Receiver Logic
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bool didRemoveNoise() { | |
bool didRemoveNoise = false; | |
while (didRemoveNoise == false) { | |
// Read Serial input | |
String inputData; | |
char c; | |
while (esp.available() > 0) { | |
c = esp.read(); | |
inputData.concat(c); | |
} | |
inputData.trim(); | |
Serial.println("Validating " + inputData); | |
if (previousData != "") { | |
Serial.println("Previous data: " + previousData); | |
// If true, noise removed, else stay in the loop | |
if (previousData.compareTo(inputData) == 0) { | |
Serial.println("if "); | |
didRemoveNoise = true; | |
Serial.println("Received"); | |
esp.println("ack"); | |
} else { | |
Serial.println("else "); | |
previousData = inputData; | |
} | |
} | |
else { | |
previousData = inputData; | |
} | |
delay(1000); | |
} | |
return didRemoveNoise; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment