0

I am trying to connect to Wi-Fi with Digital pin declaration in setup() function it's not connecting to wi-fi. But connecting to wi-fi without digital pin diclaration. `

#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
int m1 = 5;
int m2 = 6;
const char* ssid = "KS Infotech";
const char* password = "kalamsalam";
String readc = ""; 
void setup () {
pinMode(m1, OUTPUT);
digitalWrite(m1, LOW);
pinMode(m2, OUTPUT);
digitalWrite(m2, LOW);
Serial.begin(9600);
WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED) {

delay(1000);
Serial.print("Connecting..");

}

}

void loop() {
while (Serial.available()){  //Check if there is an available byte to read
delay(10); //Delay added to make thing stable 
char c = Serial.read(); 
String T = String(readc);
    Serial.println(T); 
if (WiFi.status() == WL_CONNECTED) { //Check WiFi connection status

HTTPClient http;  //Declare an object of class HTTPClient

http.begin("http://ksinfotech.co/kslab/write_to_database.php?incoming="+T+"&UID=surya");  //Specify request destination
int httpCode = http.GET();                                                                  


if (httpCode > 0) { //Check the returning code

  String payload = http.getString();   //Get the request response payload
  Serial.println(payload);                     //Print the response payload
  if (payload == 'N');
  {
  digitalWrite(m1, HIGH);
  digitalWrite(m2, LOW);
  delay(2000);
  digitalWrite(m1, LOW);
  digitalWrite(m1, LOW);
}
      if (payload == 'F');
  {
  digitalWrite(m1, LOW);
  digitalWrite(m2, HIGH);
  delay(2000);
  digitalWrite(m1, LOW);
  digitalWrite(m1, LOW);
}

http.end();   //Close connection

}

delay(30000);    //Send a request every 30 seconds

}

The above code not working but the below code working.

#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>

const char* ssid = "KS Infotech";
const char* password = "kalamsalam";
String readc = ""; 
void setup () {

Serial.begin(9600);
WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED) {

delay(1000);
Serial.print("Connecting..");

}

}

void loop() {
while (Serial.available()){  //Check if there is an available byte to read
delay(10); //Delay added to make thing stable 
char c = Serial.read(); 
if (c == '#'){
  break;                   //Stop the loop once # is detected after a word
}//Conduct a serial read
readc += c; //build the string- "forward", "reverse", "left" and "right"
} 
String T = String(readc);
    Serial.println(T); 
if (WiFi.status() == WL_CONNECTED) { //Check WiFi connection status

HTTPClient http;  //Declare an object of class HTTPClient

http.begin("http://ksinfotech.co/kslab/write_to_database.php?incoming="+T+"&UID=surya");  //Specify request destination
int httpCode = http.GET();                                                                  
 //Send the request

if (httpCode > 0) { //Check the returning code

  String payload = http.getString();   //Get the request response payload
  Serial.println(payload);                     //Print the response payload

}

http.end();   //Close connection

}

delay(30000);    //Send a request every 30 seconds

}
  • Pins 5 and 6 are not what you think they are. 5 != D5 6 != D6 – gre_gor Feb 6 '18 at 18:53
  • 2
    posted on arduino forum forum.arduino.cc/index.php?topic=527272 – Juraj Feb 6 '18 at 18:57
  • 2
    Lack of formatting makes your code very hard to read. Use the format tools available in Arduino IDE – user31481 Feb 6 '18 at 19:03
  • Thanks for your answers and suggestions. My problem solved. – Surya Prakash Feb 7 '18 at 4:01
2

use D5 and D6, not 5 and 6. D5 is IO 14, D6 is IO 12. IO 5 is D1 and IO 6 is SDIO_CLK for the flash memory and that is your problem.

the reference

  • I think GPIO06 is connected to flash and that's why it fails. – gre_gor Feb 6 '18 at 19:38
  • yes. I edited the answer. it is is SDIO_CLK for the flash memory – Juraj Feb 6 '18 at 19:57
  • but pin5 is the best pin on board, tied with pin4... – dandavis Feb 6 '18 at 21:44
  • then please mark the answer as accepted – Juraj Feb 7 '18 at 5:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.