#include <SoftwareSerial.h>
#define RX A2
#define TX A3
#define DEBUG true
String AP = "********************";
String PASS = "***************";
String sendData;
int sendVal;
String ROW1 = "", ROW2 = "";
String fuelDispenserId = "123" , vehicleId = "567";
SoftwareSerial espSerial(RX, TX);
int buttonState = 0;
void setup() {
Serial.begin(115200);
espSerial.begin(115200);
pinMode(8, INPUT_PULLUP);
espData("AT+RST", 1000, DEBUG); //Reset the ESP8266 module
espData("AT+CWMODE=1", 1000, DEBUG); //Set the ESP mode as station mode
espData("AT+CWJAP=\"" + AP + "\",\"" + PASS + "\"", 1000, DEBUG); //Connect to WiFi network
delay(2000);
}
void loop() {
sendData = "GET http://192.168.3.109/fuelapi.php?ROW1=786&ROW2=786";
"&ROW1=" + ROW1 +
"&ROW2=" + ROW2;
espData("AT+CIPMUX=1", 1000, DEBUG); //Allow multiple connections
////// espData("AT+CIPSTART=0,\"TCP\",\""+ myHOST +"\","+ myPORT, 1000, DEBUG);/////
espData("AT+CIPSTART=0,\"TCP\",\"192.168.3.109\",80", 1000, DEBUG);
espData("AT+CIPSEND=0," + String(sendData.length() + 4), 1000, DEBUG);
espSerial.find(">");
espSerial.println(sendData);
Serial.print("Value to be sent: ");
Serial.println(sendData);
espData("AT+CIPCLOSE=0", 1000, DEBUG);
delay(2000);
}
String espData(String command, const int timeout, boolean debug)
{
Serial.print("AT Command ==> ");
Serial.print(command);
Serial.println(" ");
String response = "";
espSerial.println(command);
long int time = millis();
while ( (time + timeout) > millis())
{
while (espSerial.available())
{
char c = espSerial.read();
response += c;
}
}
if (debug)
{
Serial.print(response);
}
return response;
}