├── calculator.h ├── quote.h ├── stock.h ├── .gitattributes ├── weather.h ├── .gitignore ├── quote.cpp ├── stock.cpp ├── constants.h ├── calculator.cpp ├── weather.cpp └── ESP8266_Assistant_Code.ino /calculator.h: -------------------------------------------------------------------------------- 1 | #ifndef calculator_h 2 | #define calculator_h 3 | 4 | #include 5 | #include 6 | 7 | 8 | 9 | 10 | class calculate 11 | { 12 | public: 13 | calculate(char* lower); 14 | float calculator(char* lower); 15 | private: 16 | char* _lower; 17 | 18 | }; 19 | 20 | #endif 21 | 22 | -------------------------------------------------------------------------------- /quote.h: -------------------------------------------------------------------------------- 1 | #ifndef quote_h 2 | #define quote_h 3 | 4 | #include 5 | #include 6 | 7 | class Quote 8 | { 9 | public: 10 | Quote(String payload); 11 | String saying_response(String payload); 12 | String author_response(String paylaod); 13 | 14 | private: 15 | char* _lower; 16 | 17 | }; 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /stock.h: -------------------------------------------------------------------------------- 1 | #ifndef stock_h 2 | #define stock_h 3 | 4 | #include 5 | #include 6 | 7 | 8 | 9 | 10 | class Stock 11 | { 12 | public: 13 | Stock(char* lower); 14 | void result(String payload); 15 | String Comparison(char* lower); 16 | 17 | private: 18 | char* _lower; 19 | 20 | }; 21 | 22 | #endif 23 | 24 | 25 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /weather.h: -------------------------------------------------------------------------------- 1 | #ifndef weather_h 2 | #define weather_h 3 | 4 | #include 5 | #include 6 | 7 | class Weather 8 | { 9 | public: 10 | Weather(char* response); 11 | float temp_c(); 12 | float temp_f(); 13 | float temp_k(char* response); 14 | String city_name(char* response); 15 | String country_name(char* response); 16 | String city_cond(char* response); 17 | String city_desc(char* response); 18 | String atm_pressure(char* response); 19 | String humidity(char* response); 20 | String clouds(char* response); 21 | 22 | 23 | private: 24 | char* _response; 25 | 26 | }; 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Windows image file caches 2 | Thumbs.db 3 | ehthumbs.db 4 | 5 | # Folder config file 6 | Desktop.ini 7 | 8 | # Recycle Bin used on file shares 9 | $RECYCLE.BIN/ 10 | 11 | # Windows Installer files 12 | *.cab 13 | *.msi 14 | *.msm 15 | *.msp 16 | 17 | # Windows shortcuts 18 | *.lnk 19 | 20 | # ========================= 21 | # Operating System Files 22 | # ========================= 23 | 24 | # OSX 25 | # ========================= 26 | 27 | .DS_Store 28 | .AppleDouble 29 | .LSOverride 30 | 31 | # Thumbnails 32 | ._* 33 | 34 | # Files that might appear in the root of a volume 35 | .DocumentRevisions-V100 36 | .fseventsd 37 | .Spotlight-V100 38 | .TemporaryItems 39 | .Trashes 40 | .VolumeIcon.icns 41 | 42 | # Directories potentially created on remote AFP share 43 | .AppleDB 44 | .AppleDesktop 45 | Network Trash Folder 46 | Temporary Items 47 | .apdisk 48 | -------------------------------------------------------------------------------- /quote.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "quote.h" 4 | 5 | 6 | char* ch1 = "’"; 7 | char* ch2 = "”"; 8 | char* ch3 = "“"; 9 | 10 | Quote::Quote(String payload) 11 | { 12 | String _payload = payload; 13 | } 14 | String Quote::saying_response(String payload) 15 | { 16 | 17 | 18 | 19 | payload.replace(ch1, "'"); 20 | payload.replace("\u2019", "'"); 21 | payload.replace(ch2, "\""); 22 | payload.replace(ch3, "\""); 23 | int i = 0; 24 | while (payload.charAt(i) != '>') 25 | i++; 26 | i++; 27 | payload = payload.substring(i); 28 | i = 0; 29 | while (payload.charAt(i) != '<') 30 | i++; 31 | 32 | String Quote = payload.substring(0, i); 33 | return(Quote); 34 | 35 | 36 | 37 | 38 | 39 | // Serial.println(payload); 40 | } 41 | 42 | String Quote::author_response(String payload) 43 | { 44 | 45 | payload.replace(ch1, "'"); 46 | payload.replace("\u2019", "'"); 47 | payload.replace(ch2, "\""); 48 | payload.replace(ch3, "\""); 49 | // String first = payload.substring(0,i); 50 | // Serial.println(first); 51 | // USE_SERIAL.println(payload); 52 | for (int j = 0 ; j < 5; j++) 53 | { 54 | int i = 0; 55 | while (payload.charAt(i) != '"') 56 | { 57 | i++; 58 | 59 | } 60 | i++; 61 | payload = payload.substring(i); 62 | } 63 | int i = 0; 64 | while (payload.charAt(i) != '"') 65 | i++; 66 | String Author = payload.substring(0, i); 67 | return(Author); 68 | } 69 | 70 | -------------------------------------------------------------------------------- /stock.cpp: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include 4 | #include 5 | #include "Stock.h" 6 | 7 | Stock::Stock(char* lower) 8 | { 9 | _lower = lower; 10 | 11 | } 12 | 13 | String Stock::Comparison(char* _lower) 14 | { 15 | 16 | int i = 0; 17 | while(_lower[i] != 'o' || _lower[i + 1] != 'f') 18 | i++; 19 | String result = (String)_lower; 20 | result = result.substring(i + 3); 21 | return(result); 22 | 23 | } 24 | void Stock::result(String payload) 25 | { 26 | for (int j = 0 ; j < 7; j++) 27 | { 28 | int i = 0; 29 | while (payload.charAt(i) != '"') 30 | { 31 | i++; 32 | 33 | } 34 | i++; 35 | payload = payload.substring(i); 36 | } 37 | int i = 0; 38 | while (payload.charAt(i) != '"') 39 | i++; 40 | String Stock_Name = payload.substring(0, i); 41 | Serial.print("Stock Name: "); Serial.println(Stock_Name); 42 | 43 | for (int j = 0 ; j < 4; j++) 44 | { 45 | int i = 0; 46 | while (payload.charAt(i) != '"') 47 | { 48 | i++; 49 | 50 | } 51 | i++; 52 | payload = payload.substring(i); 53 | } 54 | i = 0; 55 | while (payload.charAt(i) != '"') 56 | i++; 57 | String Broker_Name = payload.substring(0, i); 58 | Serial.print("Broker: "); Serial.println(Broker_Name); 59 | 60 | for (int j = 0 ; j < 4; j++) 61 | { 62 | int i = 0; 63 | while (payload.charAt(i) != '"') 64 | { 65 | i++; 66 | 67 | } 68 | i++; 69 | payload = payload.substring(i); 70 | } 71 | i = 0; 72 | while (payload.charAt(i) != '"') 73 | i++; 74 | String Stock_Price = payload.substring(0, i); 75 | Serial.print("Stock Price: "); Serial.println(Stock_Price); 76 | } 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | -------------------------------------------------------------------------------- /constants.h: -------------------------------------------------------------------------------- 1 | #ifndef constants_h 2 | #define constants_h 3 | 4 | #include 5 | 6 | 7 | char* stock = "stock price"; 8 | 9 | char* date = "date"; 10 | 11 | char* timee = "time"; 12 | 13 | char* ahd = "ahmedabad"; 14 | 15 | char* sur = "surat"; 16 | 17 | char* temp = "temperature"; 18 | 19 | char* weather = "weather"; 20 | 21 | char* mean = "meaning of"; 22 | 23 | char* cal = "calculate"; 24 | 25 | char* quo = "quote"; // https://www.google.com/finance/info?q=NSE:BHEL 26 | char* quot = "sayings"; 27 | 28 | 29 | 30 | 31 | char* listen = "esp listen"; 32 | 33 | char* turn = "turn"; 34 | 35 | char* togg = "toggle"; 36 | 37 | char* high = "on"; 38 | 39 | char* low = "off"; 40 | 41 | char* light = "light"; 42 | 43 | char* fan = "fan"; 44 | 45 | int lightt = 16; 46 | 47 | int fann = 5; 48 | 49 | 50 | 51 | 52 | 53 | char* que1 = "who are you"; 54 | char* que2 = "what is your name"; 55 | char* que3 = "who is your mentor"; 56 | char* que4 = "who you are"; 57 | char* que5 = "your name"; 58 | char* que6 = "what's your name"; 59 | char* que7 = "tell me about yourself"; 60 | char* que8 = "tell me bit about yourself"; 61 | char* que9 = "tell me something about yourself"; 62 | char* que10 = "where are you from";// ** 63 | char* que11 = "who is your inventor"; 64 | char* que12 = "who made you"; //** 65 | char* que13 = "from where you are"; //** 66 | char* que14 = "who is your mentor"; 67 | char* que15 = "How you know all this"; 68 | char* que16 = "who is your teacher"; 69 | char* que17 = "hello"; 70 | char* que18 = "hi"; 71 | 72 | char* aim1 = "what do you want"; 73 | char* aim2 = " what is your aim"; 74 | char* aim3 = "what you want to do"; 75 | char* aim4 = "what you want to become"; 76 | 77 | char* Name1 = "who is techiesms"; 78 | char* Name2 = "tell me bit about techiesms"; 79 | char* Name3 = "what do you mean by techiesms"; 80 | char* Name4 = "what does techiesms means"; 81 | char* Name5 = "tell me about techiesms"; 82 | char* Name6 = "tell me something about techiesms"; 83 | char* Name7 = "what is techiesms"; 84 | 85 | char* help = "help format"; 86 | 87 | char* train1 = "route of train"; 88 | char* train2 = "status of train"; 89 | char* train3 = "code of station"; 90 | char* train4 = "train between"; 91 | char* train5 = "check my pnr"; 92 | 93 | 94 | #endif 95 | 96 | -------------------------------------------------------------------------------- /calculator.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "calculator.h" 3 | #include 4 | 5 | float result; 6 | 7 | //-------------------------------------- constants 8 | char* plus1 = "+"; 9 | char* plus2 = "plus"; 10 | char* minus1 = "-"; 11 | char* minus2 = "minus"; 12 | char* mul1 = "*"; 13 | char* mul2 = "multiply"; 14 | char* mul3 = "multiplied"; 15 | char* mul4 = "into"; 16 | char* div1 = "/"; 17 | char* div2 = "divided"; 18 | char* div3 = "divide"; 19 | char* div4 = "by"; 20 | 21 | 22 | calculate::calculate(char* lower) 23 | { 24 | _lower = lower; 25 | } 26 | 27 | float calculate::calculator(char* _lower) 28 | { 29 | 30 | 31 | String response = (String)_lower; 32 | 33 | String filtered = response.substring(10); //---------- filtering upto "calculate" 34 | 35 | int i = 0; 36 | while (filtered.charAt(i) != ' ')//---------- filtering for the first number by polling "space" 37 | i++; 38 | 39 | String first_num = filtered.substring(0, i); 40 | i++; 41 | 42 | int j = 0; 43 | while (filtered.charAt(j + i) != ' ')//---------- filtering for the sign by polling 2nd space 44 | j++; 45 | 46 | String sign = filtered.substring(i, j + i); 47 | j++; 48 | char* s_con = &sign[0]; 49 | 50 | 51 | int k = 0; 52 | while (filtered.charAt(k + i + j) != '\0' )//---------- filtering for the second number by polling "new line" 53 | k++; 54 | 55 | String second_num = filtered.substring(j + i, k + j + i); 56 | 57 | 58 | float first = first_num.toFloat();//---------- converting String to 59 | float secondd = second_num.toFloat();//------- float 60 | 61 | { 62 | if (strstr(s_con, plus1) || strstr(s_con, plus2)) 63 | { 64 | result = first + secondd; 65 | return (result); 66 | } 67 | else if (strstr(s_con, minus1) || strstr(s_con, minus2)) 68 | { 69 | result = first - secondd; 70 | return (result); 71 | } 72 | else if (strstr(s_con, mul1) || strstr(s_con, mul2) || strstr(s_con, mul3) || strstr(s_con, mul4)) 73 | { 74 | result = first * secondd; 75 | return (result); 76 | } 77 | else if (strstr(s_con,div1) || strstr(s_con,div2) || strstr(s_con,div3) || strstr(s_con,div4)) 78 | { 79 | result = first / secondd; 80 | return (result); 81 | } 82 | 83 | else 84 | { 85 | Serial.println(""); 86 | Serial.println("Please write in proper format, number1 sign number2. for eg. 1 + 2"); 87 | Serial.println("Or check out the spelling"); 88 | Serial.println(""); 89 | 90 | } 91 | } 92 | } 93 | 94 | -------------------------------------------------------------------------------- /weather.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "weather.h" 4 | 5 | String s_response; 6 | float temperature_kelvin; 7 | float temperature_celcius; 8 | float temperature_far; 9 | 10 | Weather::Weather(char* response) 11 | { 12 | _response = response; 13 | s_response = (String)response; 14 | Serial.println("weather.h"); 15 | 16 | } 17 | 18 | 19 | String Weather::city_name(char* _response) 20 | { 21 | int i = 0; 22 | while (_response[i] != 'n' || _response[i + 1] != 'a' || _response[i + 2] != 'm' || _response[i + 3] != 'e' ) 23 | i++; 24 | String s_response = (String)_response; 25 | String city_name = s_response.substring(i + 7); 26 | int j = 0; 27 | // Serial.println(city_name); 28 | while (city_name.charAt(j) != '"') 29 | j++; 30 | city_name = city_name.substring(0, j); 31 | return(city_name); 32 | } 33 | String Weather::country_name(char* _response) 34 | { 35 | int i = 0; 36 | while (_response[i] != 'c' || _response[i + 1] != 'o' || _response[i + 2] != 'u' || _response[i + 3] != 'n' || _response[i + 4] != 't' || _response[i + 5] != 'r' || _response[i + 6] != 'y') 37 | i++; 38 | String country = s_response.substring(i + 10); 39 | int j = 0; 40 | //Serial.println(country); 41 | while (country.charAt(j) != '"') 42 | j++; 43 | country = country.substring(0, j); 44 | return(country); 45 | } 46 | float Weather::temp_k(char* _response) 47 | { 48 | int i = 0; 49 | while (_response[i] != 't' || _response[i + 1] != 'e' || _response[i + 2] != 'm' || _response[i + 3] != 'p' ) 50 | i++; 51 | String city_temp = s_response.substring(i + 6); 52 | int j = 0; 53 | //Serial.println(city_temp); 54 | while (city_temp.charAt(j) != ',') 55 | j++; 56 | city_temp = city_temp.substring(0, j); 57 | temperature_kelvin = (city_temp.toFloat()); 58 | return(temperature_kelvin); 59 | } 60 | float Weather::temp_c() 61 | { 62 | temperature_celcius = temperature_kelvin - 273.15; 63 | return(temperature_celcius); 64 | } 65 | float Weather::temp_f() 66 | { 67 | temperature_far = (temperature_celcius * 9 / 5) + 32; 68 | return(temperature_far); 69 | } 70 | String Weather::city_cond(char* reaponse) 71 | { 72 | int i = 0; 73 | while (_response[i] != 'm' || _response[i + 1] != 'a' || _response[i + 2] != 'i' || _response[i + 3] != 'n' ) 74 | i++; 75 | String city_cond = s_response.substring(i + 7); 76 | int j = 0; 77 | //Serial.println(city_cond); 78 | while (city_cond.charAt(j) != '"') 79 | j++; 80 | city_cond = city_cond.substring(0, j); 81 | return(city_cond); 82 | } 83 | String Weather::city_desc(char* reaponse) 84 | { 85 | int i = 0; 86 | 87 | while (_response[i] != 'd' || _response[i + 1] != 'e' || _response[i + 2] != 's' || _response[i + 3] != 'c' || _response[i + 4] != 'r' || _response[i + 5] != 'i' || _response[i + 6] != 'p' || _response[i + 7] != 't' ) 88 | i++; 89 | String city_desc = s_response.substring(i + 14); 90 | int j = 0; 91 | //Serial.println(city_desc); 92 | while (city_desc.charAt(j) != '"') 93 | j++; 94 | city_desc = city_desc.substring(0, j); 95 | return(city_desc); 96 | } 97 | String Weather::atm_pressure(char* _response) 98 | { 99 | int i = 0; 100 | while (_response[i] != 'p' || _response[i + 1] != 'r' || _response[i + 2] != 'e' || _response[i + 3] != 's' || _response[i + 4] != 's' || _response[i + 5] != 'u' || _response[i + 6] != 'r' || _response[i + 7] != 'e' ) 101 | i++; 102 | String atm_pressure = s_response.substring(i + 10); 103 | int j = 0; 104 | // Serial.println(atm_pressure); 105 | while (atm_pressure.charAt(j) != ',') 106 | j++; 107 | atm_pressure = atm_pressure.substring(0, j); 108 | return(atm_pressure); 109 | } 110 | String Weather::humidity(char* _response) 111 | { 112 | int i = 0; 113 | while (_response[i] != 'h' || _response[i + 1] != 'u' || _response[i + 2] != 'm' || _response[i + 3] != 'i' || _response[i + 4] != 'd' || _response[i + 5] != 'i' || _response[i + 6] != 't' || _response[i + 7] != 'y') 114 | i++; 115 | String humidity = s_response.substring(i + 10); 116 | int j = 0; 117 | //Serial.println(humidity); 118 | while (humidity.charAt(j) != ',') 119 | j++; 120 | humidity = humidity.substring(0, j); 121 | return(humidity); 122 | } 123 | String Weather::clouds(char* _response) 124 | { 125 | int i = 0; 126 | while (_response[i] != 'c' || _response[i + 1] != 'l' || _response[i + 2] != 'o' || _response[i + 3] != 'u' || _response[i + 4] != 'd' || _response[i + 5] != 's' || _response[i + 6] != '"' || _response[i + 7] != ':' || _response[i + 8] != '{' || _response[i + 9] != '"') 127 | i++; 128 | String clouds = s_response.substring(i + 14); 129 | int j = 0; 130 | //Serial.println(clouds); 131 | while (clouds.charAt(j) != '}') 132 | j++; 133 | clouds = clouds.substring(0, j); 134 | return(clouds); 135 | 136 | } 137 | 138 | -------------------------------------------------------------------------------- /ESP8266_Assistant_Code.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * This is the code of Making your own personal assistant for ESP8266 12e board. 3 | * 4 | * This code is written and tested by Sachin Soni. This code is open for all so anyone can use it. 5 | * 6 | * Visit my website, 7 | * www.techiesms.com 8 | * to know more about this and other electronic projects tutorials. 9 | * 10 | * 11 | * techiesms 12 | * explore | learn | share 13 | * 14 | */ 15 | 16 | 17 | //------------------------------------------------- necesarry libraries 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include "constants.h" 23 | 24 | //------------------------------------------------- Optional libraries(include according to requirement of your project) 25 | 26 | #include "stock.h" 27 | #include "calculator.h" 28 | #include "Quote.h" 29 | #include "weather.h" 30 | 31 | 32 | 33 | char* response = " "; 34 | String res = ""; 35 | String RAILWAY_API_KEY = "YOUR_RAILWAY_API_KEY";//---------- API key for www.railwayapi.com 36 | String WEATHER_API_KEY = "YOUR_WEATHER_API_KEY";//---------- API key for api.openweathermap.org 37 | char* Host_Name = "YOUR_HOST_NAME"; 38 | char* Password = "PASSWORD"; 39 | 40 | 41 | ESP8266WiFiMulti WiFiMulti; 42 | 43 | void setup() { 44 | 45 | Serial.begin(115200); 46 | 47 | pinMode(lightt, OUTPUT);//---------- Appilance1 to be controlled 48 | pinMode(fann, OUTPUT); //----------- Appilance2 to be controlled 49 | WiFi.begin(Host_Name, Password); 50 | while (WiFi.status() != WL_CONNECTED) { 51 | delay(500); 52 | Serial.print("."); 53 | } 54 | WiFiMulti.addAP(Host_Name,Password); //---------- Write you SSID and Password of yout router 55 | } 56 | 57 | void loop() { 58 | 59 | if ((WiFiMulti.run() == WL_CONNECTED)) //---------- If connected to the router than go inside 60 | { 61 | 62 | Serial.println("Ask your question:"); 63 | Serial.println("\n"); 64 | 65 | //------------------------------------------------- Reading the String from the Serial, word by word. 66 | while (!Serial.available()); 67 | while (Serial.available()) 68 | { 69 | char add = Serial.read(); 70 | res = res + add; 71 | delay(1); 72 | } 73 | response = &res[0]; 74 | 75 | 76 | //------------------------------------------------- Converting every character of the String in lower form 77 | const int length = strlen( response ); // get the length of the text 78 | char* lower = ( char* )malloc( length + 1 ); // allocate 'length' bytes + 1 (for null terminator) and cast to char* 79 | lower[ length ] = 0; // set the last byte to a null terminator 80 | //------------------------------------------------- copy all character bytes to the new buffer using tolower 81 | for ( int i = 0; i < length; i++ ) 82 | { 83 | lower[ i ] = tolower( response[ i ] ); 84 | } 85 | 86 | Serial.println(lower);// printin the String in lower character form 87 | Serial.println("\n"); 88 | 89 | 90 | 91 | //***************************** From here, different cases will start for different purposes *****************************// 92 | 93 | 94 | 95 | 96 | 97 | 98 | if (strstr(lower, cal)) 99 | { 100 | calculate calci(lower); 101 | float answer = calci.calculator(lower); 102 | Serial.println("\n"); 103 | Serial.println(answer); 104 | Serial.println("\n"); 105 | response = ""; 106 | res = ""; 107 | } 108 | 109 | 110 | 111 | 112 | 113 | 114 | else if (strstr(lower, weather)) 115 | { 116 | int i = 0; 117 | while (lower[i] != 'o' || lower[i + 1] != 'f') 118 | i++; 119 | 120 | String result = (String)lower; 121 | result = result.substring(i + 3); 122 | result = result.substring(0, result.length() - 2); 123 | 124 | if ((WiFiMulti.run() == WL_CONNECTED)) { 125 | Serial.println("Processing...."); 126 | 127 | HTTPClient http; //stringOne.startsahdith("HTTP/1.1") 128 | 129 | http.begin("http://api.openweathermap.org/data/2.5/weather?q=" + result + "&APPID=" + WEATHER_API_KEY); //HTTP 130 | int httpCode = http.GET(); 131 | 132 | // httpCode ahd ill be negative on error 133 | if (httpCode > 0) { 134 | // HTTP header has been send and Server response header has been handled 135 | 136 | 137 | // file found at server 138 | if (httpCode == HTTP_CODE_OK) { 139 | String payload = http.getString(); 140 | char* response = &payload[0]; 141 | Weather weather(response); 142 | float temp_k = weather.temp_k(response); 143 | float temp_c = weather.temp_c(); 144 | float temp_f = weather.temp_f(); 145 | String city_name = weather.city_name(response); 146 | String country_name = weather.country_name(response); 147 | String city_desc = weather.city_desc(response); 148 | String city_cond = weather.city_cond(response); 149 | String humidity = weather.humidity(response); 150 | String clouds = weather.clouds(response); 151 | String atm_pressure = weather.atm_pressure(response); 152 | 153 | Serial.println("\n"); 154 | Serial.print("City: "); Serial.println(city_name); 155 | Serial.print("Country: "); Serial.println(country_name); 156 | Serial.println("Temperature"); 157 | Serial.print(" "); Serial.print(temp_k, 3); Serial.println(" kelvin"); 158 | Serial.print(" "); Serial.print(temp_c, 3); Serial.println(" deg. celcius"); 159 | Serial.print(" "); Serial.print(temp_f, 3); Serial.println(" deg. fahrenheit"); 160 | Serial.print("Weather Status: "); Serial.println(city_cond); 161 | Serial.print("Weather Description: "); Serial.println(city_desc); 162 | Serial.print("Atmospheric Presure: "); Serial.println(atm_pressure + " hPa"); 163 | Serial.print("Humidity: "); Serial.println(humidity + " %rH"); 164 | Serial.print("Clouds: "); Serial.println(clouds + "%"); 165 | Serial.println("\n"); 166 | } 167 | } else { 168 | Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str()); 169 | } 170 | 171 | http.end(); 172 | response = ""; 173 | res = ""; 174 | } 175 | } 176 | 177 | else if (strstr(lower, temp)) 178 | { 179 | 180 | int i = 0; 181 | while (lower[i] != 'o' || lower[i + 1] != 'f') 182 | i++; 183 | // Serial.println(i); 184 | String result = (String)lower; 185 | result = result.substring(i + 3); 186 | result = result.substring(0, result.length() - 2); 187 | 188 | if ((WiFiMulti.run() == WL_CONNECTED)) { 189 | Serial.println("Processing...."); 190 | 191 | HTTPClient http; //stringOne.startsahdith("HTTP/1.1") 192 | http.begin("http://api.openweathermap.org/data/2.5/weather?q=" + result + "&APPID=" + WEATHER_API_KEY); //HTTP 193 | int httpCode = http.GET(); 194 | 195 | // httpCode ahd ill be negative on error 196 | if (httpCode > 0) { 197 | // HTTP header has been send and Server response header has been handled 198 | 199 | 200 | // file found at server 201 | if (httpCode == HTTP_CODE_OK) { 202 | String payload = http.getString(); 203 | char* response = &payload[0]; 204 | 205 | Weather weather(response); 206 | String city_name = weather.city_name(response); 207 | String country = weather.country_name(response); 208 | float temp_k = weather.temp_k(response); 209 | float temp_c = weather.temp_c(); 210 | float temp_f = weather.temp_f(); 211 | 212 | 213 | 214 | Serial.println("\n"); 215 | Serial.print("City: "); Serial.println(city_name); 216 | Serial.print("Country: "); Serial.println(country); 217 | Serial.println("Temperature"); 218 | Serial.print(" "); Serial.print(temp_k, 3); Serial.println(" kelvin"); 219 | Serial.print(" "); Serial.print(temp_c, 3); Serial.println(" deg. celcius"); 220 | Serial.print(" "); Serial.print(temp_f, 3); Serial.println(" deg. fahrenheit"); 221 | Serial.println("\n"); 222 | } 223 | } else { 224 | Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str()); 225 | } 226 | 227 | http.end(); 228 | response = ""; 229 | res = ""; 230 | } 231 | 232 | } 233 | 234 | else if (strstr(lower, mean)) 235 | { 236 | Serial.println("Sorry!!!!!, you don't have data regarding this"); 237 | Serial.println("Wait for the upcoming series on Making your own Smart Assiatant using ESP8266"); 238 | Serial.println("Or you haven't downloaded the latest code, check out my github, Github/techiesms"); 239 | Serial.println(); res = ""; response = ""; 240 | } 241 | 242 | 243 | 244 | else if (strstr(lower, quo) || strstr(lower, quot)) 245 | { 246 | Serial.println("Sorry!!!!!, you don't have data regarding this"); 247 | Serial.println("Wait for the upcoming series on Making your own Smart Assiatant using ESP8266"); 248 | Serial.println("Or you haven't downloaded the latest code, check out my github, Github/techiesms"); 249 | Serial.println(); res = ""; response = ""; 250 | } 251 | else if (strstr(lower, stock)) 252 | { 253 | Stock stock(lower); 254 | String resu = stock.Comparison(lower); 255 | 256 | 257 | if ((WiFiMulti.run() == WL_CONNECTED)) { 258 | Serial.println("Processing...."); 259 | 260 | HTTPClient http; 261 | 262 | http.begin("http://www.google.com/finance/info?q=NSE:" + resu + ""); //HTTP 263 | int httpCode = http.GET(); 264 | 265 | // httpCode ahd ill be negative on error 266 | if (httpCode > 0) { 267 | // HTTP header has been send and Server response header has been handled 268 | 269 | 270 | // file found at server 271 | if (httpCode == HTTP_CODE_OK) { 272 | String payload = http.getString(); 273 | stock.result(payload); 274 | 275 | } 276 | } 277 | else { 278 | Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str()); 279 | } 280 | http.end(); 281 | response = ""; 282 | res = ""; 283 | } 284 | 285 | } 286 | else if (strstr(lower, train1)) 287 | { 288 | if ((WiFiMulti.run() == WL_CONNECTED)) { 289 | Serial.println("Processing...."); 290 | 291 | String Train_Number = (String)lower; 292 | Train_Number = Train_Number.substring(15, 20); 293 | 294 | 295 | HTTPClient http; 296 | 297 | http.begin("http://api.railwayapi.com/route/train/" + Train_Number + "/apikey/" + RAILWAY_API_KEY + "/"); //HTTP 298 | 299 | int httpCode = http.GET(); 300 | 301 | // httpCode will be negative on error 302 | if (httpCode > 0) { 303 | // HTTP header has been send and Server response header has been handled 304 | 305 | 306 | // file found at server 307 | if (httpCode == HTTP_CODE_OK) { 308 | String payload = http.getString(); 309 | 310 | Serial.println("\n"); 311 | Serial.println(payload); 312 | Serial.println("\n"); 313 | } 314 | } else { 315 | Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str()); 316 | } 317 | 318 | http.end(); 319 | response = ""; 320 | res = ""; 321 | } 322 | 323 | } 324 | 325 | else if (strstr(lower, train2)) 326 | { 327 | if ((WiFiMulti.run() == WL_CONNECTED)) { 328 | Serial.println("Processing...."); 329 | 330 | String Train_Number = (String)lower; 331 | Train_Number = Train_Number.substring(16, 21); 332 | 333 | Serial.println("\n"); 334 | Serial.println("Enter the date of journey (YYYYMMDD):"); 335 | Serial.println("\n"); 336 | 337 | res = ""; 338 | while (!Serial.available()); 339 | while (Serial.available()) 340 | 341 | { 342 | char add = Serial.read(); 343 | if (add != '\n') // read until new line 344 | res = res + add; 345 | delay(1); 346 | } 347 | String doj = &res[0]; 348 | doj = doj.substring(0, 8); 349 | 350 | Serial.println("Processing...."); 351 | HTTPClient http; 352 | 353 | http.begin("http://api.railwayapi.com/live/train/" + Train_Number + "/doj/" + doj + "/apikey/" + RAILWAY_API_KEY + "/"); //HTTP 354 | int httpCode = http.GET(); 355 | 356 | // httpCode will be negative on error 357 | if (httpCode > 0) { 358 | // HTTP header has been send and Server response header has been handled 359 | 360 | // file found at server 361 | if (httpCode == HTTP_CODE_OK) { 362 | String payload = http.getString(); 363 | 364 | Serial.println("\n"); 365 | Serial.println(payload); 366 | Serial.println("\n"); 367 | } 368 | 369 | } else { 370 | Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str()); 371 | } 372 | 373 | http.end(); 374 | response = ""; 375 | res = ""; 376 | } 377 | 378 | 379 | } 380 | 381 | else if (strstr(lower, train3)) 382 | { 383 | if ((WiFiMulti.run() == WL_CONNECTED)) { 384 | Serial.println("Processing...."); 385 | 386 | String station_name = (String)lower; 387 | station_name = station_name.substring(16, 21); 388 | 389 | 390 | HTTPClient http; 391 | 392 | http.begin("http://api.railwayapi.com/name_to_code/station/" + station_name + "/apikey/" + RAILWAY_API_KEY + "/"); //HTTP 393 | int httpCode = http.GET(); 394 | 395 | // httpCode will be negative on error 396 | if (httpCode > 0) { 397 | // HTTP header has been send and Server response header has been handled 398 | 399 | 400 | // file found at server 401 | if (httpCode == HTTP_CODE_OK) { 402 | String payload = http.getString(); 403 | 404 | Serial.println("\n"); 405 | Serial.println(payload); 406 | Serial.println("\n"); 407 | } 408 | } else { 409 | Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str()); 410 | } 411 | 412 | http.end(); 413 | response = ""; 414 | res = ""; 415 | } 416 | } 417 | 418 | else if (strstr(lower, train4)) 419 | { 420 | if ((WiFiMulti.run() == WL_CONNECTED)) { 421 | Serial.println("Processing...."); 422 | 423 | String source = (String)lower; 424 | source = source.substring(14); 425 | 426 | char* desti = &source[0]; 427 | int i = 0; 428 | int j = 0; 429 | while (desti[i] != 't' || desti[i + 1] != 'o') 430 | i++; 431 | String destin = (String)desti; 432 | source = source.substring(0, i - 1); // departing station 433 | 434 | while (desti[j] != '\n') 435 | j++; 436 | String dest = destin.substring(i + 3, j - 1); // destination station 437 | 438 | 439 | 440 | Serial.println("Enter the date in format (dd-mm)"); 441 | res = ""; 442 | while (!Serial.available()); 443 | while (Serial.available()) 444 | 445 | { 446 | char add = Serial.read(); 447 | if (add != '\n') // Read untill new line 448 | res = res + add; 449 | delay(1); 450 | } 451 | 452 | String date = &res[0]; 453 | date = date.substring(0, 5); 454 | 455 | HTTPClient http; 456 | Serial.println("Processing...."); 457 | http.begin("http://api.railwayapi.com/between/source/" + source + "/dest/" + dest + "/date/" + date + "/apikey/" + RAILWAY_API_KEY + "/"); //HTTP 458 | int httpCode = http.GET(); 459 | 460 | // httpCode will be negative on error 461 | if (httpCode > 0) { 462 | // HTTP header has been send and Server response header has been handled 463 | 464 | // file found at server 465 | if (httpCode == HTTP_CODE_OK) { 466 | String payload = http.getString(); 467 | Serial.println("\n"); 468 | Serial.println(payload); 469 | Serial.println("\n"); 470 | } 471 | 472 | } else { 473 | 474 | Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str()); 475 | } 476 | 477 | http.end(); 478 | response = ""; 479 | res = ""; 480 | } 481 | } 482 | 483 | 484 | else if (strstr(lower, train5)) 485 | { 486 | if ((WiFiMulti.run() == WL_CONNECTED)) { 487 | Serial.println("Processing...."); 488 | String pnr_no = (String)lower; 489 | pnr_no = pnr_no.substring(13); 490 | // Serial.println(pnr_no); 491 | 492 | 493 | HTTPClient http; 494 | 495 | http.begin("http://api.railwayapi.com/pnr_status/pnr/" + pnr_no + "/apikey/" + RAILWAY_API_KEY + "/"); //HTTP 496 | int httpCode = http.GET(); 497 | 498 | // httpCode will be negative on error 499 | if (httpCode > 0) { 500 | // HTTP header has been send and Server response header has been handled 501 | 502 | 503 | // file found at server 504 | if (httpCode == HTTP_CODE_OK) { 505 | String payload = http.getString(); 506 | 507 | Serial.println("\n"); 508 | Serial.println(payload); 509 | Serial.println("\n"); 510 | } 511 | } else { 512 | Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str()); 513 | } 514 | 515 | http.end(); 516 | response = ""; 517 | res = ""; 518 | } 519 | 520 | } 521 | 522 | else if (strstr(lower, que1) || strstr(lower, que2) || strstr(lower, que3) || 523 | strstr(lower, que4) || strstr(lower, que5) || strstr(lower, que6) || strstr(lower, que7) || 524 | strstr(lower, que8) || strstr(lower, que9)) 525 | { 526 | if ((WiFiMulti.run() == WL_CONNECTED)) { 527 | Serial.println("Processing...."); 528 | 529 | HTTPClient http; //stringOne.startsahdith("HTTP/1.1") 530 | 531 | http.begin("api.thingspeak.com", 80, "/apps/thinghttp/send_request?api_key=39D61DPXIY3K4DQL"); //HTTP 532 | int httpCode = http.GET(); 533 | 534 | // httpCode will be negative on error 535 | if (httpCode > 0) { 536 | // HTTP header has been send and Server response header has been handled 537 | 538 | 539 | // file found at server 540 | if (httpCode == HTTP_CODE_OK) { 541 | String payload = http.getString(); 542 | Serial.println("\n"); 543 | Serial.println(payload); 544 | Serial.println("\n"); 545 | } 546 | } else { 547 | Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str()); 548 | } 549 | 550 | http.end(); 551 | response = ""; 552 | res = ""; 553 | } 554 | } 555 | 556 | 557 | 558 | 559 | else if ( strstr(lower, que10) || strstr(lower, que11) || strstr(lower, que12) || strstr(lower, que13)) 560 | { 561 | if ((WiFiMulti.run() == WL_CONNECTED)) { 562 | Serial.println("Processing...."); 563 | 564 | HTTPClient http; //stringOne.startsahdith("HTTP/1.1") 565 | 566 | http.begin("api.thingspeak.com", 80, "/apps/thinghttp/send_request?api_key=366ZP8SF6ZS3UMZL"); //HTTP 567 | int httpCode = http.GET(); 568 | 569 | // httpCode will be negative on error 570 | if (httpCode > 0) { 571 | // HTTP header has been send and Server response header has been handled 572 | 573 | 574 | // file found at server 575 | if (httpCode == HTTP_CODE_OK) { 576 | String payload = http.getString(); 577 | Serial.println("\n"); 578 | Serial.println(payload); 579 | } 580 | 581 | } else { 582 | Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str()); 583 | } 584 | 585 | http.end(); 586 | response = ""; 587 | res = ""; 588 | } 589 | } 590 | 591 | 592 | else if (strstr(lower, que14) || strstr(lower, que15) || strstr(lower, que16)) 593 | { 594 | if ((WiFiMulti.run() == WL_CONNECTED)) { 595 | Serial.println("Processing...."); 596 | 597 | HTTPClient http; //stringOne.startsahdith("HTTP/1.1") 598 | 599 | http.begin("api.thingspeak.com", 80, "/apps/thinghttp/send_request?api_key=PKHTTDCEHB7PR1IB"); //HTTP 600 | int httpCode = http.GET(); 601 | 602 | // httpCode will be negative on error 603 | if (httpCode > 0) { 604 | // HTTP header has been send and Server response header has been handled 605 | 606 | 607 | // file found at server 608 | if (httpCode == HTTP_CODE_OK) { 609 | String payload = http.getString(); 610 | Serial.println("\n"); 611 | Serial.println(payload); 612 | Serial.println("\n"); 613 | } 614 | } else { 615 | Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str()); 616 | } 617 | 618 | http.end(); 619 | response = ""; 620 | res = ""; 621 | } 622 | } 623 | 624 | else if (strstr(lower, Name1) || strstr(lower, Name2) || strstr(lower, Name3) || 625 | strstr(lower, Name4) || strstr(lower, Name5) || strstr(lower, Name6) || strstr(lower, Name7)) 626 | { 627 | if ((WiFiMulti.run() == WL_CONNECTED)) { 628 | Serial.println("Processing...."); 629 | 630 | HTTPClient http; //stringOne.startsahdith("HTTP/1.1") 631 | 632 | http.begin("api.thingspeak.com", 80, "/apps/thinghttp/send_request?api_key=AKEWCGNBEYXH8FJ3"); //HTTP 633 | int httpCode = http.GET(); 634 | 635 | // httpCode will be negative on error 636 | if (httpCode > 0) { 637 | // HTTP header has been send and Server response header has been handled 638 | 639 | 640 | // file found at server 641 | if (httpCode == HTTP_CODE_OK) { 642 | String payload = http.getString(); 643 | Serial.println("\n"); 644 | Serial.println(payload); 645 | Serial.println("\n"); 646 | } 647 | } else { 648 | Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str()); 649 | } 650 | 651 | http.end(); 652 | response = ""; 653 | res = ""; 654 | } 655 | } 656 | 657 | else if (strstr(lower, aim1) || strstr(lower, aim2) || strstr(lower, aim3) || strstr(lower, aim4)) 658 | { 659 | if ((WiFiMulti.run() == WL_CONNECTED)) { 660 | Serial.println("Processing...."); 661 | 662 | HTTPClient http; //stringOne.startsahdith("HTTP/1.1") 663 | 664 | http.begin("api.thingspeak.com", 80, "/apps/thinghttp/send_request?api_key=W2NKTO59K941TF8H"); //HTTP 665 | int httpCode = http.GET(); 666 | 667 | // httpCode will be negative on error 668 | if (httpCode > 0) { 669 | // HTTP header has been send and Server response header has been handled 670 | 671 | 672 | // file found at server 673 | if (httpCode == HTTP_CODE_OK) { 674 | String payload = http.getString(); 675 | Serial.println("\n"); 676 | Serial.println(payload); 677 | Serial.println("\n"); 678 | } 679 | } else { 680 | Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str()); 681 | } 682 | 683 | http.end(); 684 | response = ""; 685 | res = ""; 686 | } 687 | } 688 | 689 | else if (strstr(lower, que17) || strstr(lower, que18)) 690 | { 691 | if ((WiFiMulti.run() == WL_CONNECTED)) { 692 | Serial.println("Processing...."); 693 | 694 | HTTPClient http; //stringOne.startsahdith("HTTP/1.1") 695 | 696 | http.begin("api.thingspeak.com", 80, "/apps/thinghttp/send_request?api_key=KMZUYWUTTW59ZJ2M"); //HTTP 697 | int httpCode = http.GET(); 698 | 699 | // httpCode will be negative on error 700 | if (httpCode > 0) { 701 | // HTTP header has been send and Server response header has been handled 702 | 703 | 704 | // file found at server 705 | if (httpCode == HTTP_CODE_OK) { 706 | String payload = http.getString(); 707 | Serial.println("\n"); 708 | Serial.println(payload); 709 | Serial.println("\n"); 710 | } 711 | } else { 712 | Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str()); 713 | } 714 | 715 | http.end(); 716 | response = ""; 717 | res = ""; 718 | } 719 | } 720 | 721 | 722 | else if (strstr(lower, help)) 723 | { 724 | Serial.println(" "); 725 | Serial.println("Want to ask basic questions regarding me, my inventor, manufacturer, origin etc you can ask"); 726 | Serial.println("eg."); 727 | Serial.println(" i) who are you?"); 728 | Serial.println("  ii) who is you inventor?"); 729 | Serial.println("  iii) where are you from?"); 730 | Serial.println("  iv) who is techiesms?"); 731 | Serial.println("  v) who is your teacher?"); 732 | Serial.println("  vi) what is your aim?"); Serial.println("\n"); 733 | Serial.println("Want to know the weather information of your city, just type - weather information of CITY_NAME"); 734 | Serial.println("eg. weather information Ahmedabad"); Serial.println("\n"); 735 | Serial.println("Want to know the temperature of your city, just type - temperature of CITY_NAME"); 736 | Serial.println("eg. temperature of Surat"); Serial.println("\n"); 737 | Serial.println("Want to know a quote to get motivated, type - tell me a quote or sayings of great personality"); 738 | Serial.println("eg. tell me a quote"); Serial.println("\n"); 739 | Serial.println("Want to know meaning or synonym of a particular word, type - meaning of WORD"); 740 | Serial.println("eg. meaning of Beguile"); Serial.println("\n"); 741 | Serial.println("Want to know stock price of the share you have, type - stock price of SHARE_NAME(Right now strictly for shares under NSE broker)"); 742 | Serial.println("eg. stock price of MRF"); Serial.println("\n"); 743 | Serial.println("Want to know the route of any train, type - route of train TRAIN_NUMBER(Right now strictly for Indian Railways)"); 744 | Serial.println("eg. route of train 12433"); Serial.println("\n"); 745 | Serial.println("Want to know the live status of any train, type - status of  TRAIN_NUMBER(Right now strictly for Indian Railways)"); 746 | Serial.println("eg. status of train 12433"); Serial.println("\n"); 747 | Serial.println("Want to know your PNR status, type - check my pnr PNR_NUMBER(Right now strictly for Indian Railways)"); 748 | Serial.println("eg. check my pnr XXXXXXXXXX"); Serial.println("\n"); 749 | Serial.println("Want to know the train between two station, type - train between SOURCE_STATION_CODE to DESTINATION_STATION_CODE(Right now strictly for Indian Railways)"); 750 | Serial.println("eg. train between adi to lko"); Serial.println("\n"); 751 | Serial.println("Want to know the station code, type - code of station STATION_NAME(Right now strictly for Indian Railways)"); 752 | Serial.println("eg. code of station Ahmedabad"); Serial.println("\n"); 753 | Serial.println("Want to do basic calculations, type - calculate number1 SIGN number2"); 754 | Serial.println("eg. i) calculate 54 / 23"); 755 | Serial.println(" ii) calculate 33 into 8"); 756 | Serial.println(" iii) calculate 45589 + 12332"); Serial.println("\n"); 757 | Serial.println("Want to control your appliances, type - esp listen turn ON/OFF the LIGHT/FAN"); 758 | Serial.println("eg. i) esp listen turn on the light"); 759 | Serial.println(" ii) esp listen turn off the fan"); Serial.println("\n"); 760 | 761 | 762 | response = ""; 763 | res = ""; 764 | } 765 | else 766 | { 767 | Serial.println(" "); 768 | Serial.println("I didn't understand what you just typed."); 769 | Serial.println("I'm not able to answer in following situations"); 770 | Serial.println(" >spelling of the statement is incorrect. Solution:- Please recheck the spelling and type again"); 771 | Serial.println(" >improper format of the statement. Solution:- To know the format of every trick, type \"help format\""); 772 | Serial.println(" >don't know the answer of the question you asked. Solution:- mail the statement you typed at espsms@techiesms.com so that I can answer this question next time by learning it."); 773 | Serial.println(""); 774 | response = ""; 775 | res = ""; 776 | } 777 | } 778 | } 779 | 780 | 781 | --------------------------------------------------------------------------------