Skip to content

Instantly share code, notes, and snippets.

@towynlin
Created January 17, 2015 03:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save towynlin/a2b5d94aa4ed1fdb70a9 to your computer and use it in GitHub Desktop.
Save towynlin/a2b5d94aa4ed1fdb70a9 to your computer and use it in GitHub Desktop.
Show both serial and Wi-Fi working together
int last = 0;
char buf[256];
int toSerial(String s) {
Serial.print("You said via REST API: ");
Serial.println(s);
memset(buf, 0, 256);
int charsRead = 0;
while (Serial.available() && charsRead < 255) {
buf[charsRead] = Serial.read();
charsRead++;
delay(1);
}
if (0 < charsRead) {
Serial.print("You said over serial: ");
Serial.println(buf);
} else {
Serial.println("You haven't said anything over serial lately.");
}
return charsRead;
}
void setup() {
Serial.begin(9600);
Spark.function("to-serial", toSerial);
}
void loop() {
if (millis() - last > 5000) {
Serial.println("It's been 5 seconds.");
last = millis();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment