|
| 1 | +/************************************************************************************** |
| 2 | + * |
| 3 | + * Name : bluetooth.cpp |
| 4 | + * |
| 5 | + * Version : 1.0 |
| 6 | + * |
| 7 | + * Author : Raji |
| 8 | + * |
| 9 | + * Description : This library is to connect bluetooth module with nodemcu12e |
| 10 | + * in order to connect to wifi and ip address by sending wifi |
| 11 | + * credentials via bluetooth of SWMS |
| 12 | + * |
| 13 | + * WiFi Input : {"ssid":"yyyyy","password":"xxxx"} |
| 14 | + * |
| 15 | + * Pin Discription: (bluetooth->nodemcu12E) |
| 16 | + * Rx->Tx |
| 17 | + * Tx->Rx |
| 18 | + * Vcc->Vcc |
| 19 | + * Gnd->Gnd. |
| 20 | + **************************************************************************************/ |
| 21 | + #include "bluetooth.h" |
| 22 | + #include "Arduino.h" |
| 23 | + #include "BluetoothSerial.h" |
| 24 | + #include<EEPROM.h> |
| 25 | + #include <String.h> |
| 26 | + /********************************#define************************************/ |
| 27 | + #define DELAY_10 10 |
| 28 | + BluetoothSerial ESP_BT; |
| 29 | + #define DELAY_100 100 |
| 30 | +/******string declarations************/ |
| 31 | + String input_bluetooth_string; |
| 32 | + String output_bluetooth_string; |
| 33 | + |
| 34 | +/*******************************************bluetooth*********************************************** |
| 35 | + * FUNCTION : bluetooth |
| 36 | + * |
| 37 | + * DISCRIPTION: This function gets ssid and password from the mobile phone and stores in eeprom |
| 38 | + * which is used for connecting with wifi continously even after re-starting the device |
| 39 | + * |
| 40 | + * PARAMETERS : int |
| 41 | + * |
| 42 | + * RETURNS : if connected to wifi returns 11 else 9 |
| 43 | +****************************************************************************************************/ |
| 44 | +String bluetooth_connect(){ |
| 45 | + |
| 46 | +/***********************************************inialize the bluetooth variables*****************************************************/ |
| 47 | + input_bluetooth_string = ""; |
| 48 | + output_bluetooth_string=""; |
| 49 | + |
| 50 | + |
| 51 | +/*****************************************************Read the string from the bluetooth*****************************************/ |
| 52 | + while (ESP_BT.available()) { |
| 53 | + { |
| 54 | + delay(DELAY_10); //small delay to allow input buffer to fill |
| 55 | + char get_string = ESP_BT.read(); //gets one byte from serial buffer |
| 56 | + /***breaks out of capture loop to print readstring***/ |
| 57 | + input_bluetooth_string += get_string; |
| 58 | + } //makes the string readString |
| 59 | + |
| 60 | + if (input_bluetooth_string.length() > 0 ) |
| 61 | + { |
| 62 | + Serial.println(input_bluetooth_string); //prints string to serial port out |
| 63 | + Serial.println( "the input string from bluetooth is" ); |
| 64 | +/*****************************************************JSON pharsing*****************************************/ |
| 65 | + delay(DELAY_100); |
| 66 | + output_bluetooth_string=""; |
| 67 | + output_bluetooth_string=output_bluetooth_string+input_bluetooth_string; |
| 68 | +/*****************************CLEAR THE INPUT TEXT OF BLUETOOTH***********************/ |
| 69 | + input_bluetooth_string=""; //clears variable for new input |
| 70 | + } |
| 71 | + |
| 72 | + return output_bluetooth_string; |
| 73 | +} |
| 74 | +} |
| 75 | +/*******************************************bluetooth_initialization*********************************************** |
| 76 | + * FUNCTION : bluetooth_initialization |
| 77 | + * |
| 78 | + * DISCRIPTION: This function gets ssid and password from the mobile phone and stores in eeprom |
| 79 | + * which is used for connecting with wifi continously even after re-starting the device |
| 80 | + * |
| 81 | + * PARAMETERS : int |
| 82 | + * |
| 83 | + * RETURNS : if connected to wifi returns 11 else 9 |
| 84 | +****************************************************************************************************/ |
| 85 | +int bluetooth_initialization(){ |
| 86 | +/***********************************initialize bluetooth*************************************************/ |
| 87 | + Serial.println("hii im ble"); |
| 88 | + ESP_BT.begin("Vehicle_tracking"); //Name of your Bluetooth Signal |
| 89 | + return 1; |
| 90 | +} |
| 91 | + |
0 commit comments