Greetings, I have an issue regarding compilation of my code. The error message is exit status 1. I want to connect esp32cam with my blynk. I am using Ai Thinker baord. Below is my code.
#include <ESP32QRCodeReader.h>
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
// Blynk credentials
#define BLYNK_TEMPLATE_ID "TMPL6bPkPpEMG"
#define BLYNK_TEMPLATE_NAME "Parcel List"
#define BLYNK_AUTH_TOKEN "WFYvhggO_XlLqKK4sp6YU_WwXUn5DArR"
ESP32QRCodeReader reader(CAMERA_MODEL_AI_THINKER);
// WiFi credentials
char ssid[] = "hakeem";
char pass[] = "28092000";
BlynkTimer timer;
const int numLocations = 3;
float datalat = 0;
float datalong = 0;
// Arrays to store parsed latitude and longitude
float latitudes[numLocations];
float longitudes[numLocations];
char latStr[10];
char lonStr[11];
// Constants for Earth's radius and conversion factors
const float EARTH_RADIUS_KM = 6371.0; // Earth's radius in kilometers
const float DEG_TO_RAD_CONV = 0.01745329251; // Degrees to radians conversion factor
// Function to calculate distance between two GPS coordinates using Haversine formula
float haversine(float lat1, float lon1, float lat2, float lon2) {
// Convert coordinates from degrees to radians
float latRad1 = lat1 * DEG_TO_RAD_CONV;
float lonRad1 = lon1 * DEG_TO_RAD_CONV;
float latRad2 = lat2 * DEG_TO_RAD_CONV;
float lonRad2 = lon2 * DEG_TO_RAD_CONV;
// Calculate differences in latitudes and longitudes
float deltaLat = latRad2 - latRad1;
float deltaLon = lonRad2 - lonRad1;
// Haversine formula to calculate distance
float a = pow(sin(deltaLat / 2), 2) + cos(latRad1) * cos(latRad2) * pow(sin(deltaLon / 2), 2);
float c = 2 * atan2(sqrt(a), sqrt(1 - a));
float distance = EARTH_RADIUS_KM * c;
return distance; // Distance in kilometers
}
void onQrCodeTask(void *pvParameters) {
struct QRCodeData qrCodeData;
while (true) {
if (reader.receiveQrCode(&qrCodeData, 100)) {
Serial.println("Found QRCode");
if (qrCodeData.valid) {
Serial.print("Payload: ");
Serial.println((const char *)qrCodeData.payload);
// Clear any previous location data
// memset(locationData, 0, sizeof(locationData));
// Copy the payload into the locationData array
String locationPayload = (const char *)qrCodeData.payload;
// Parse the location data
if (parseLocation(locationPayload, datalat, datalong)) {
// Convert float values to strings with six decimal places
dtostrf(datalat, 8, 6, latStr);
dtostrf(datalong, 9, 6, lonStr);
Serial.print("Parsed latitude: ");
Serial.println(latStr);
Serial.print("Parsed longitude: ");
Serial.println(lonStr);
// Send to Blynk Terminal
Blynk.virtualWrite(V3, "Parsed latitude: ");
Blynk.virtualWrite(V3, latStr);
Blynk.virtualWrite(V3, "\nParsed longitude: ");
Blynk.virtualWrite(V4, lonStr);
Blynk.virtualWrite(V4, "\n");
calculation();
} else {
Serial.println("Invalid location format");
Blynk.virtualWrite(V3, "Invalid location format\n");
}
} else {
Serial.print("Invalid: ");
Serial.println((const char *)qrCodeData.payload);
Blynk.virtualWrite(V3, "Invalid: ");
Blynk.virtualWrite(V3, (const char *)qrCodeData.payload);
Blynk.virtualWrite(V3, "\n");
}
}
vTaskDelay(100 / portTICK_PERIOD_MS);
}
}
// This function is called every time the Virtual Pin 0 state changes
BLYNK_WRITE(V6)
{
// Set incoming value from pin V0 to a variable
int value = param.asInt();
// Update state
Blynk.virtualWrite(V1, value);
}
// This function is called every time the device is connected to the Blynk.Cloud
BLYNK_CONNECTED()
{
// Change Web Link Button message to "Congratulations!"
Blynk.setProperty(V5, "offImageUrl", "https://static-image.nyc3.cdn.digitaloceanspaces.com/general/fte/congratulations.png");
Blynk.setProperty(V5, "onImageUrl", "https://static-image.nyc3.cdn.digitaloceanspaces.com/general/fte/congratulations_pressed.png");
Blynk.setProperty(V5, "url", "https://docs.blynk.io/en/getting-started/what-do-i-need-to-blynk/how-quickstart-device-was-made");
}
// This function sends Arduino's uptime every second to Virtual Pin 2.
void myTimerEvent()
{
// You can send any value at any time.
// Please don't send more than 10 values per second.
Blynk.virtualWrite(V2, millis() / 1000);
}
void setup() {
Serial.begin(115200);
Serial.println();
reader.setup();
Serial.println("Setup QRCode Reader");
reader.beginOnCore(1);
Serial.println("Begin on Core 1");
xTaskCreate(onQrCodeTask, "onQrCode", 4 * 1024, NULL, 4, NULL);
// Blynk setup
Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
timer.setInterval(1000L, myTimerEvent);
}
void loop() {
Blynk.run();
timer.run();
}
void calculation() {
// Fixed coordinates for the central location (latitude and longitude in degrees)
float lat1 = 2.9622653; // Central location latitude
float lon1 = 101.7549858; // Central location longitude
// Example coordinates for other locations (latitude and longitude in degrees)
float lat2 = atof(latStr);
float lon2 = atof(lonStr);
// Calculate distances between the central location and other locations using Haversine formula
float distance1_2 = haversine(lat1, lon1, lat2, lon2);
// Print distances to serial monitor for debugging
Serial.print("Distance between Central Location and Waypoint 1: ");
Serial.print(distance1_2);
Serial.println(" kilometers");
Blynk.virtualWrite(V0, distance1_2);
delay(1000); // Delay for 1 second before repeating the calculation
}
// Function to parse location data in the format "latitude,longitude"
bool parseLocation(String location, float &latitude, float &longitude) {
int commaIndex = location.indexOf(',');
if (commaIndex != -1) {
latitude = location.substring(0, commaIndex).toFloat();
longitude = location.substring(commaIndex + 1).toFloat();
return true;
} else {
return false;
}
}