Connecting esp01 with arduino nano 33 ble

Im making a project about a fire detection system using arduino nano 33 ble sense with an esp01. The system is supposed to send an email to the user in case of a fire. I'm facing a problem with the esp01, every time i'm trying to upload the sketch i would get this error: "A fatal esptool.py error occurred: Failed to connect to ESP8266: Timed out waiting for packet header"

This is the circuit that i'm following:

And this is my code:

#include <ESP8266WiFi.h>

const char* ssid = "xxxxx";
const char* password = "xxxxxx";
const char* host = "maker.ifttt.com";

void setup() 
{
    Serial.begin(115200);
    Serial.println("Email from Node Mcu");
    delay(100);
    Serial.print("Connecting to ");
    Serial.println(ssid);
    WiFi.begin(ssid, password);
    while (WiFi.status() != WL_CONNECTED) 
    {
      delay(500);
      Serial.print(".");
    }
  
    Serial.println("");
    Serial.println("IP address: ");
    Serial.println(WiFi.localIP());  
}

void loop() 
{ 

     WiFiClient client; 
     const int httpPort = 80;  
     if (!client.connect(host, httpPort)) 
     {  
       Serial.println("connection failed");  
       return;
     } 
    if(Serial.available( ) > 0) //  It will only send data when the received data is greater than 0.  
   {  
    int receivedData  = Serial.read();  // It will read the incoming or arriving data byte 
    //Serial.println(receivedData,DEC);
    char state = char(receivedData); // print the character for the ASCII value
    //Serial.println(exercise);
    int value = state - '0';
    if(state == '1')
      {
         String url = "/trigger/fire_detected/json/with/key/(key)";  //the key is supposed to be added here
         Serial.print("Requesting URL: ");
         Serial.println(url);
         client.print(String("GET ") + url + " HTTP/1.1\r\n" + 
                                    "Host: " + host + "\r\n" +   
                                           "Connection: close\r\n\r\n");    
      }
    
   }  
}

Any suggestions on what could be wrong here?

Disconnect the Tx & Rx!

put the SerialPassthrough example into the Nano BLE. set it to use 115200 baud

but did you put the esp8266 into bootloader mode? (io 0 to gnd at boot)

I actually haven't. I will check that.

thanks a lot it worked. For the wifi connection it connects and disconnects after approximately 1 min , any idea why that happens? I'm using the same code that I posted

how do you know? does it reset?

It prints out the ip address, i used my phone's hotspot to connect with it. On my phone it says a device is connected. But after nearly a minute it starts printing out "connection failed" nonstop, and it doesn't try to connect again. I also tried to connect directly to my house's router but I still get the same issue.

in the sketch you connect every loop(). then you don't use the connection most of the time and don't stop it

should i keep the connection in the setup instead?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.