Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Arduino UNO ESP8266-12E Wifi Module

Status
Not open for further replies.

imranahmed

Advanced Member level 3
Advanced Member level 3
Joined
Dec 4, 2011
Messages
817
Helped
3
Reputation
6
Reaction score
3
Trophy points
1,298
Location
Karachi,Pakistan
Activity points
6,493
Please let me know I want to send data to my database, data is sending but when I initializes ESP in setup() but when I initialize in loop() or other function it is not working why?
Working code is attached. I want to initial ESP reset,cwmode and cwjap in other method not in setup() because if I want to change SSID and PASSWORD so I would easily change it without doing reset Arduino.


Code:
#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;
}
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top