Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.69 KB | None | 0 0
  1. void ATCmdSetup() {
  2. bt.listen();
  3. bt.print(atStart + Initialize + atSetEnd); //initialize device (only has to be done once)
  4. bt.print(atStart + accesCode + atSetEnd); //defines the accesCode this device shares with the others
  5. bt.print(atStart + deviceType + atSetEnd); //defines device type (32 bit indicating device type and what is supported)
  6. bt.print(atStart + searchRSSI + atSetEnd); //looks for "open" bluetooth devices in the area and lists them with RSSI
  7. }
  8.  
  9. void listRSSI() {
  10. bt.listen();
  11. bt.print(atStart + receiveRSSI + atSetEnd); //looks for devices and their RSSI and lists them
  12. }
  13.  
  14. void filterCode() {
  15. if (message.substring(0, 5) == "+INQ:") {
  16. deviceAddress = splitString(message, ",", 0).substring(5);
  17. deviceClass = splitString(message, ",", 1);
  18. deviceRSSI = splitString(message, ",", 2);
  19. if (RSSIVisible) {
  20. Serial.print("\t");
  21. printAddressRSSI();
  22. Serial.print("Rssi in decimale: ");
  23. Serial.println(hexToDec(deviceRSSI));
  24.  
  25. }
  26. }
  27. message = "";
  28. }
  29.  
  30. String splitString(String str, String devider, int arrayNumber) {
  31. int previousDevider = 0;
  32. int deviders = 1;
  33. for (int i = 0; i < str.length(); i++) {
  34. if (str.substring(i, i + devider.length()) == devider) {
  35. deviders++;
  36. }
  37. }
  38. int devideCounter = 0;
  39. String devidedString[deviders + 1];
  40. for (int i = 0; i < str.length(); i++) {
  41. if (str.substring(i, i + devider.length()) == devider) {
  42. if (devideCounter) {
  43. devidedString[devideCounter] = str.substring(devidedString[devideCounter - 1].length() + 1, i);
  44. } else {
  45. devidedString[0] = str.substring(0, i);
  46. }
  47. devideCounter++;
  48. previousDevider = i + devider.length();
  49. }
  50. }
  51. devidedString[devideCounter] = str.substring(previousDevider, str.length());
  52. if (arrayNumber > deviders) {
  53. return "ERROR; array number not found. Array number is to big.";
  54. } else {
  55. return devidedString[arrayNumber];
  56. }
  57. }
  58.  
  59. unsigned int hexToDec(String hexString) { //converts HEX to DEC
  60. unsigned int decValue = 0;
  61. int nextInt;
  62. for (int i = 0; i < hexString.length(); i++) {
  63. nextInt = int(hexString.charAt(i));
  64. if (nextInt >= 48 && nextInt <= 57) nextInt = map(nextInt, 48, 57, 0, 9);
  65. if (nextInt >= 65 && nextInt <= 70) nextInt = map(nextInt, 65, 70, 10, 15);
  66. if (nextInt >= 97 && nextInt <= 102) nextInt = map(nextInt, 97, 102, 10, 15);
  67. nextInt = constrain(nextInt, 0, 15);
  68. decValue = (decValue * 16) + nextInt;
  69. }
  70. return decValue;
  71. }
  72.  
  73.  
  74. void printAddressRSSI() {
  75. Serial.print("Address:");
  76. Serial.print(deviceAddress);
  77. Serial.print(" RSSI:");
  78. Serial.println(deviceRSSI);
  79.  
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement