-
-
Save nickswalker/10227307 to your computer and use it in GitHub Desktop.
Get Bytes from BLE Serial Connection (BlueShield)
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
#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