Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void ATCmdSetup() {
- bt.listen();
- bt.print(atStart + Initialize + atSetEnd); //initialize device (only has to be done once)
- bt.print(atStart + accesCode + atSetEnd); //defines the accesCode this device shares with the others
- bt.print(atStart + deviceType + atSetEnd); //defines device type (32 bit indicating device type and what is supported)
- bt.print(atStart + searchRSSI + atSetEnd); //looks for "open" bluetooth devices in the area and lists them with RSSI
- }
- void listRSSI() {
- bt.listen();
- bt.print(atStart + receiveRSSI + atSetEnd); //looks for devices and their RSSI and lists them
- }
- void filterCode() {
- if (message.substring(0, 5) == "+INQ:") {
- deviceAddress = splitString(message, ",", 0).substring(5);
- deviceClass = splitString(message, ",", 1);
- deviceRSSI = splitString(message, ",", 2);
- if (RSSIVisible) {
- Serial.print("\t");
- printAddressRSSI();
- Serial.print("Rssi in decimale: ");
- Serial.println(hexToDec(deviceRSSI));
- }
- }
- message = "";
- }
- String splitString(String str, String devider, int arrayNumber) {
- int previousDevider = 0;
- int deviders = 1;
- for (int i = 0; i < str.length(); i++) {
- if (str.substring(i, i + devider.length()) == devider) {
- deviders++;
- }
- }
- int devideCounter = 0;
- String devidedString[deviders + 1];
- for (int i = 0; i < str.length(); i++) {
- if (str.substring(i, i + devider.length()) == devider) {
- if (devideCounter) {
- devidedString[devideCounter] = str.substring(devidedString[devideCounter - 1].length() + 1, i);
- } else {
- devidedString[0] = str.substring(0, i);
- }
- devideCounter++;
- previousDevider = i + devider.length();
- }
- }
- devidedString[devideCounter] = str.substring(previousDevider, str.length());
- if (arrayNumber > deviders) {
- return "ERROR; array number not found. Array number is to big.";
- } else {
- return devidedString[arrayNumber];
- }
- }
- unsigned int hexToDec(String hexString) { //converts HEX to DEC
- unsigned int decValue = 0;
- int nextInt;
- for (int i = 0; i < hexString.length(); i++) {
- nextInt = int(hexString.charAt(i));
- if (nextInt >= 48 && nextInt <= 57) nextInt = map(nextInt, 48, 57, 0, 9);
- if (nextInt >= 65 && nextInt <= 70) nextInt = map(nextInt, 65, 70, 10, 15);
- if (nextInt >= 97 && nextInt <= 102) nextInt = map(nextInt, 97, 102, 10, 15);
- nextInt = constrain(nextInt, 0, 15);
- decValue = (decValue * 16) + nextInt;
- }
- return decValue;
- }
- void printAddressRSSI() {
- Serial.print("Address:");
- Serial.print(deviceAddress);
- Serial.print(" RSSI:");
- Serial.println(deviceRSSI);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement