Go Down

Topic: ESP82666.h  (Read 220 times) previous topic - next topic

Abhijeet8919

Hello Guys..I am working on ESP01 wifi project with Arduino UNO board and Arduino IDE 1.8.2...Ive also added the ESP8266 Generic Board to it..But when i tried to add ESP8266.h file it gives me error like

warning: espcomm_sync failed
error: espcomm_open failed
error: espcomm_upload_mem failed
error: espcomm_upload_mem failed


Does anyone know what I am doing wrong?

This is my ino Code:

//This example will set up a static IP - in this case 192.168.1.99
 
#include <ESP8266WiFi.h>
 
const char* ssid = "ssid name";
const char* password = "ssid password";
 
int ledPin = 11;
WiFiServer server(80);
IPAddress ip(192, 168, 1, 99); // where xx is the desired IP Address
IPAddress gateway(192, 168, 1, 1); // set gateway to match your network
 
void setup() {
  Serial.begin(115200);
  delay(10);
 
 
  pinMode(ledPin, OUTPUT);
  digitalWrite(ledPin, LOW);
 
  Serial.print(F("Setting static ip to : "));
  Serial.println(ip);
 
  // Connect to WiFi network
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);
  IPAddress subnet(255, 255, 255, 0); // set subnet mask to match your network
  WiFi.config(ip, gateway, subnet);
  WiFi.begin(ssid, password);
 
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");
 
  // Start the server
  server.begin();
  Serial.println("Server started");
 
  // Print the IP address
  Serial.print("Use this URL : ");
  Serial.print("http://");
  Serial.print(WiFi.localIP());
  Serial.println("/");
 
}
 
void loop() {
  // Check if a client has connected
  WiFiClient client = server.available();
  if (!client) {
    return;
  }
 
  // Wait until the client sends some data
  Serial.println("new client");
  while(!client.available()){
    delay(1);
  }
 
  // Read the first line of the request
  String request = client.readStringUntil('\r');
  Serial.println(request);
  client.flush();
 
  // Match the request
 
  int value = LOW;
  if (request.indexOf("/LED=ON") != -1) {
    digitalWrite(ledPin, HIGH);
    value = HIGH;
  }
  if (request.indexOf("/LED=OFF") != -1){
    digitalWrite(ledPin, LOW);
    value = LOW;
  }
 
 
 
  // Return the response
  client.println("HTTP/1.1 200 OK");
  client.println("Content-Type: text/html");
  client.println(""); //  do not forget this one
  client.println("<!DOCTYPE HTML>");
  client.println("<html>");
 
  client.print("Led pin is now: ");
 
  if(value == HIGH) {
    client.print("On"); 
  } else {
    client.print("Off");
  }
  client.println("<br><br>");
  client.println("Click <a href=\"/LED=ON\">here</a> turn the LED on pin 5 ON<br>");
  client.println("Click <a href=\"/LED=OFF\">here</a> turn the LED on pin 5 OFF<br>");
  client.println("</html>");
 
  delay(1);
  Serial.println("Client disconnected");
  Serial.println("");
 
}


 

pert

Please use code tags (</> button on the toolbar) when you post code or warning/error messages. The reason is that the forum software can interpret parts of your code as markup, leading to confusion, wasted time, and a reduced chance for you to get help with your problem. This will also make it easier to read your code and to copy it to the IDE or editor. Using code tags and other important information is explained in the How to use this forum post. Please read it.

I am working on ESP01 wifi project with Arduino UNO board
Are you uploading to the Uno or are you using the Uno as a USB-serial adapter to upload to the ESP-01?

Abhijeet8919

Thanks Pert for advice and your reply...Actually Both ESP01 and UNO are attached with each other..and i am trying to upload to UNO.

pert

Ok, then you need to select Tools > Board > Arduino/Genuino Uno.

You will also not be able to use the ESP8266WiFi library as that library is written for use when programming the ESP8266 directly, rather than using a standard Arduino board to control an ESP8266. For that purpose I recommend this library:
https://github.com/bportaluri/WiFiEsp

Nick_Pyner

that library is written for use when programming the ESP8266 directly,
But still using the Arduino IDE?
(Pardon the hijack, I have a similar problem)

pert

#5
Jul 06, 2017, 06:11 pm Last Edit: Jul 06, 2017, 06:12 pm by pert
Yes, it's a part of the "ESP8266 core for Arduino" 3rd party plugin that makes it super easy to directly program ESP8266 via the Arduino IDE using the standard Arduino API. Installation instructions are here:
https://github.com/esp8266/Arduino#installing-with-boards-manager

Nick_Pyner

Thanks, that link looks like what I need.
Good night

Abhijeet8919

Yes, it's a part of the "ESP8266 core for Arduino" 3rd party plugin that makes it super easy to directly program ESP8266 via the Arduino IDE using the standard Arduino API. Installation instructions are here:
https://github.com/esp8266/Arduino#installing-with-boards-manager
Thank you, I will try this.

pert

Thank you, I will try this.
I think you already did try it. That's how you got that "ESP8266 Generic Board" option in your Tools > Board menu. The problem is that it's made for programming the ESP8266 directly, no Uno involved. If you're trying to program the Uno and just use the ESP8266 as a WiFi module then it won't help you and you should use the WiFiEsp library I linked previously.

Programming the ESP8266 is definitely a good option but the ESP-01 is pretty limited for standalone use. It doesn't have all the components necessary to be used as a standalone board. These can be added easily enough if you want. It is possible to use the Uno merely as a USB-serial adapter for programming the ESP-01 and getting serial debug output to the Serial Monitor but I would strongly recommend getting a dedicated USB-serial adapter board (FTDI FT232, CH340, etc) for this purpose instead. The ESP-01 is very limited in GPIO and also has less flash memory (512 kB or 1 MB depending on which version you got). I would much prefer to spend a couple dollars extra for a WeMos D1 Mini, which will work as a standalone board, has all the useful pins broken out, and 4 MB of flash. On the other hand, the ESP-01 is super small and cheap so it may be the best option for a specific application.

Go Up