When im uploading my code into my ESP8266 NodeMCU board the output shows "A fatal esptool.py error occurred: Failed to connect to ESP8266: Timed out waiting for packet header", but also said that my upload has been completed. I really need this issue to be fixed asap for schooL. Maybe there's a problem with my code. It's AI-Generated since I actually have no idea how to code so mb if it sucks T-T
#include <DFMiniMp3.h>
#include <DfMp3Types.h>
#include <Mp3ChipBase.h>
#include <Mp3ChipIncongruousNoAck.h>
#include <Mp3ChipMH2024K16SS.h>
#include <Mp3ChipOriginal.h>
#include <SoftwareSerial.h>
#include <DFRobotDFPlayerMini.h>
// Pin Definitions
#define BUTTON_PIN D3 // Button GPIO
#define GSM_RX D5 // GSM module TX -> ESP8266 RX
#define GSM_TX D6 // GSM module RX -> ESP8266 TX
#define DFPLAYER_RX D4 // DFPlayer Mini TX -> ESP8266 RX
#define DFPLAYER_TX D8 // DFPlayer Mini RX -> ESP8266 TX
// Define phone number (Change this to your number)
#define PHONE_NUMBER "+63068451029" // Replace with actual number
// Create SoftwareSerial for DFPlayer Mini
SoftwareSerial dfSerial(DFPLAYER_RX, DFPLAYER_TX);
DFRobotDFPlayerMini dfPlayer;
// Use Hardware Serial1 for GSM Module
HardwareSerial gsmSerial(1);
// Function prototypes
void makeCall(String number);
void endCall();
void playAudioLoop();
void setup() {
Serial.begin(115200); // Debugging
Serial.println("ESP8266 Setup...");
// GSM Module (Using SoftwareSerial)
gsmSerial.begin(9600); // Only the baud rate is needed here
// DFPlayer Mini (Software Serial)
dfSerial.begin(9600);
if (!dfPlayer.begin(dfSerial)) {
Serial.println("DFPlayer Mini not detected!");
return;
}
dfPlayer.volume(20); // Set volume (0-30)
// Button Configuration
pinMode(BUTTON_PIN, INPUT_PULLUP);
}
void loop() {
// Detect Button Press
if (digitalRead(BUTTON_PIN) == LOW) {
Serial.println("Button Pressed! Making call...");
// Make Call using GSM
makeCall(PHONE_NUMBER);
// Wait until the call is answered
delay(5000); // Adjust delay as needed
// Play MP3 in Loop until call ends
playAudioLoop();
// End Call
endCall();
}
}
// Function to Make Call
void makeCall(String number) {
gsmSerial.println("ATD" + number + ";"); // AT command to dial
delay(1000);
}
// Function to End Call
void endCall() {
gsmSerial.println("ATH"); // Hang up
Serial.println("Call ended.");
dfPlayer.stop(); // Stop audio
}
// Function to Play MP3 File in Loop (File 001.mp3)
void playAudioLoop() {
Serial.println("Playing audio in loop...");
dfPlayer.loop(1); // Loops the first MP3 file
delay(10000); // Adjust duration based on need
}