Problem with fingerprint sensor and esp8266-01

Hello there, I have a simple project to create a security system with internet, for security device I use fingerprint sensor (ZFM60), esp8266-01 as internet connection provider and send data to iot web cloud, and arduino uno as microcontroller.

And I have a problem about sending fingerprint sensor data via esp8266-01 to the iot web cloud, the data always fails to be sent. Help me to know where the problem is :sob:

there the code:

#include <Adafruit_Fingerprint.h>
#include <SoftwareSerial.h>
#define SSID "5NY"
#define PASS "masukaja890"

SoftwareSerial mySerial(2, 3);
Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);
SoftwareSerial esp8266(12,13);
char *apiKey ="80594f339bbaff6afb045334f1faa5da"; 

void setup()  
{
  Serial.begin(9600);
  
  esp8266.begin(115200);   
  Serial.println("Test ESP");
  setupesp8266();
  connectwifi();
  
  finger.begin(57600);
  
  if (finger.verifyPassword()) 
  {
    Serial.println("Found fingerprint sensor!");
  } 
  else 
  {
    Serial.println("Did not find fingerprint sensor :(");
    while (1);
  }
  Serial.println("Waiting for valid finger...");
}

void loop()
{
  int getFingerprintIDez();
  uint8_t p = finger.getImage();
  if (p != FINGERPRINT_OK)  return -1;

  p = finger.image2Tz();
  if (p != FINGERPRINT_OK)  return -1;

  p = finger.fingerFastSearch();
  if (p != FINGERPRINT_OK)  return -1;
  
  if(finger.fingerID==2)                                                                         //my number ID is 2
  {
    Serial.print("Found ID #"); Serial.print(finger.fingerID); 
    Serial.print(" as Yunus ");
    Serial.print(" with confidence of "); Serial.println(finger.confidence);
    
    Serial.println("Sending data");
    
    int user;
    user = finger.fingerID;
    senddata("No", user);
  }
}


void senddata(String ID,int No)
{
  String cmd = "AT+CIPSTART=\"TCP\",\"";
  cmd += "geeknesia.com";
  cmd += "\",80";
  esp8266.println(cmd);
  delay(2000);
  cmd="";
  if(esp8266.find("Error"))
  {
    Serial.println("AT+CIPSTART Error");
    return;
  }
  else
  {
    Serial.println("AT+CIPSTART Success");
  }
  

  String getStr = "GET /api/data?api_key=";
  getStr += apiKey;
  getStr += "&attributes={\"";
  getStr += ID;
  getStr += "\":\"";
  getStr += No;
  getStr +="\"}";    
  getStr += "\r\n\r\n";  
  cmd = "AT+CIPSEND=";
  cmd += String(getStr.length());
  esp8266.println(cmd);
  Serial.println(getStr.length());
  Serial.println(getStr);
  delay(100);
  if(esp8266.find(">"))
  {
    esp8266.print(getStr);
    Serial.print("Data Sent");
  }
  else
   {
    esp8266.println("AT+CIPCLOSE");
    Serial.print("Data Error");
  }
  cmd="";
  delay(1000); 
}

void setupesp8266()
{
  esp8266.println("AT+RST");
  delay(3000);
  esp8266.println("AT");
  if (esp8266.find("OK"))
  {
  Serial.println("ESP Okey");}
  else
  {
  Serial.println("ESP Failed");}
}

void connectwifi()
{
  esp8266.println("AT+CWMODE=3");
  delay(2000);
  String cmd = "AT+CWJAP=\"";
  cmd+=SSID;
  cmd+="\",\"";
  cmd+=PASS;
  cmd+="\"";
  esp8266.println(cmd);
  delay(5000);
  cmd="";
  if (esp8266.find("OK"))
  {Serial.println("Connect to internet");}
  else
  {Serial.println("Failed to connect internet");}
}

and this in serial monitor

Test ESP
ESP Okey
Connect to internet
Found fingerprint sensor!
Waiting for valid finger...
Found ID #2 as Yunus  with confidence of 108
Sending data
AT+CIPSTART Success
80
GET /api/data?api_key=80594f339bbaff6afb045334f1faa5da&attributes={"No":"2"}


Data Error

And I've tried to send random data using only esp8266-01, and it works that proves that my esp8266-01 is not broken, there the code:

#include <SoftwareSerial.h>
#define SSID "5NY"
#define PASS "masukaja890"
SoftwareSerial esp8266(12,13);
char *apiKey ="80594f339bbaff6afb045334f1faa5da";

void setup()
{
   Serial.begin(9600);
   esp8266.begin(115200);   
   Serial.println("Test ESP");
   delay(2000);   
   setupesp8266();
   connectwifi();
   
}

void loop() 
{
  int data2;                           //this random data
  data2 = 2;
  senddata ("No", data2);
  delay(1000);
}
  

void setupesp8266()
{
  esp8266.println("AT+RST");
  delay(3000);
  esp8266.println("AT");
  if (esp8266.find("OK"))
  {
  Serial.println("ESP Okey");}
  else
  {
  Serial.println("ESP Failed");}
}

void connectwifi()
{
  esp8266.println("AT+CWMODE=3");
  delay(2000);
  String cmd = "AT+CWJAP=\"";
  cmd+=SSID;
  cmd+="\",\"";
  cmd+=PASS;
  cmd+="\"";
  esp8266.println(cmd);
  delay(5000);
  cmd="";
  if (esp8266.find("OK"))
  {Serial.println("Connect to internet");}
  else
  {Serial.println("Failed to connect internet");}
}

void senddata(String ID,int No)  // fungsi untuk send data 
  {
  String cmd = "AT+CIPSTART=\"TCP\",\"";
  cmd += "geeknesia.com";
  cmd += "\",80";
  esp8266.println(cmd);
  delay(2000);
  cmd="";
  if(esp8266.find("Error"))
  {Serial.println("AT+CIPSTART Error");
   return;}
   else
  {Serial.println("AT+CIPSTART Success");}
  

  String getStr = "GET /api/data?api_key=";
  getStr += apiKey;
  getStr += "&attributes={\"";
  getStr += ID;
  getStr += "\":\"";
  getStr += No;
  getStr +="\"}";    
  getStr += "\r\n\r\n";  
  cmd = "AT+CIPSEND=";
  cmd += String(getStr.length());
  esp8266.println(cmd);
  Serial.println(getStr.length());
  Serial.println(getStr);
  delay(1000);
  if(esp8266.find(">"))
  {
    esp8266.print(getStr);
    Serial.print("Data Sent");
  }
  else
   {
    esp8266.println("AT+CIPCLOSE");
    Serial.print("Data Error");
  }
  cmd="";
  delay(1000); 
  }

and in serial monitor:

Test ESP
ESP Okey
Connect to internet
AT+CIPSTART Success
80
GET /api/data?api_key=80594f339bbaff6afb045334f1faa5da&attributes={"No":"2"}


Data Sent

I have not seen Software serial work, relibly, at over 38400 baud.

You never actually send the getStr to the ESP.

Are you sure you don't need any headers? Host? Content-Length?

Pieter

Hello there, thanks for your attention :smiley:

groundFungus:
I have not seen Software serial work, relibly, at over 38400 baud.

Baud rate for serial monitor is 9600, 115200 for esp8266-01 and 57600 for fingerprint sensor.

PieterP:
You never actually send the getStr to the ESP.

Are you sure you don't need any headers? Host? Content-Length?

Pieter

but getStr already sent, in serial monitor

GET /api/data?api_key=80594f339bbaff6afb045334f1faa5da&attributes={"No":"2"}

Headers its like library? I have included all the necessary libraries, and for host is in void connectserver()

PieterP:
You never actually send the getStr to the ESP.

Are you sure you don't need any headers? Host? Content-Length?

Pieter

Ah you are right, where is my mistake?