Skip to content

Instantly share code, notes, and snippets.

@nickswalker
Forked from volca/serial.ino
Last active August 29, 2015 13:58
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 nickswalker/10227307 to your computer and use it in GitHub Desktop.
Save nickswalker/10227307 to your computer and use it in GitHub Desktop.
Get Bytes from BLE Serial Connection (BlueShield)
#define MESSAGE_SIZE 18 //Message is capped at 18 bytes due to the BLE profile. If we try to get any more we simply get the same values on loop
byte message[MESSAGE_SIZE];
void setup() {
Serial.begin(9600);
}
void loop() {
while (Serial.available() > 0) {
Serial.setTimeout(100);
Serial.readBytes((char *)message,sizeof(message));
}
//First bit is the command bit. We can assume that the buffer is niled out if this bit is 0
if(message[0] > 0) {
//Do stuff based on the message
}
//Log out all the bytes in the message
//for(int i=0; i< sizeof(message); i++) Serial.println(message[i]);
memset(message, 0, sizeof(message)); //set all indexes to 0, flush the buffer.
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment