Arduino ESP8266 at Commands - Code - Ino at Master Oksbwn - Arduino ESP8266 at Commands GitHub
Arduino ESP8266 at Commands - Code - Ino at Master Oksbwn - Arduino ESP8266 at Commands GitHub
master
1 contributor
1 #include <SoftwareSerial.h>
2 #define WIFI_SSID "#####" //WIFI SSID
3 #define WIFI_PASS "********" // Wifi Password
4 #define SERVER_IP "192.168.0.1" // IP of the target server.
5 #define TIMEOUT 5000 //Timeout for the serial communication
6 #define CONTINUE false
7 #define HALT true
8 #define NO_OF_PARAMETERS 1 //No of parameters sending to the server.
9
10 SoftwareSerial esp8266SerialPort(10, 11); // RX, TX
11
12 void exception(String msg){ //Exception occured. Print msg and stops.
13 Serial.println(msg);
14 Serial.println("HALT");
15 while(true){
16 readResponseData("");
17 delay(60000);
18 }
19 }
20 boolean readResponseData(String keyword){ //Receive data from the serial port. Returns true if keyword ma
21 String response;
22 long deadline = millis() + TIMEOUT;
23 while(millis() < deadline){
24 if (esp8266SerialPort.available()){
25 char ch = esp8266SerialPort.read(); // Read one character from serial port and append to a string.
26 response+=ch;
27 if(keyword!=""){
28 if(response.indexOf(keyword)>0){ //Searched keyword found.
29 Serial.println(response);
30 return true;
31 }
32 }
33 }
34 }
35 Serial.println(response);
36 return false;
37 }
38
39 boolean sendCommand(String command, String acknowledgement, boolean stopOnError)
40 {
41 esp8266SerialPort.println(command);
42 if (!readResponseData(acknowledgement))
43 if (stopOnError)
1 of 3 26/03/2023, 20:38
Arduino-ESP8266-AT-Commands/Code.ino at master · oksbwn/Arduin... https://github.com/oksbwn/Arduino-ESP8266-AT-Commands/blob/mas...
2 of 3 26/03/2023, 20:38
Arduino-ESP8266-AT-Commands/Code.ino at master · oksbwn/Arduin... https://github.com/oksbwn/Arduino-ESP8266-AT-Commands/blob/mas...
3 of 3 26/03/2023, 20:38