Esp32 fire detection

Hello I'm new here,I need help in my project,it's 2 esp32 board both version 1 as I see in the back,
The 1st esp32 is transmitter and 2nd is reciever,
Transmitter components:
Esp32 v1
Dht11
Flame sensor
Neo6mv2 gps
Mq2 sensor
Ov7670 camera
Reciever components:
Esp32 v1
480*320 tft espi with ili9488 driver
Buzzer
This is a smoke/fire detection project
When smoke/fire is detected by the sensors
The camera will take picture
And the esp32 transmitter will send the data to the reciever
And the data received will be displayed on the tft including temperature, coordinates,smoke/fire status and image take by the camera,and the buzzer will beep each time data was received,
The data transmission should be every 2 minutes while the smoke/fire still exist,after 3 times of data sent and fire still exist the data transmission will become 4minutes
Thanks in advance

Welcome to the Arduino forum. What do you need help with? Best to begin by getting the transmitter and the receiver to work together, if you haven't done that, yet.

Topic moved. Please do not post in "Uncategorized"; see the sticky topics in Uncategorized - Arduino Forum.

I want it to communicate to each other through internal wifi so that I don't have to connect to internet
But when I try uploading code with espnow it always have errors even tried Bluetooth connection the same,
But when I try the code that uses external network,my home wifi it connects with no error in the code ,the only problem is the image doesn't displayed on the tft and the gps always n/a

give more details? e.g.

  1. compile time errors? post compiler error output (as text not an image)
  2. run time errors? post serial monitor output, what do you expect to happen? what actually happens?

Unfortunately I don't have the laptop now coz I just borrowed it from my brother
The first error is no such file or directory so I downloaded multiple espnow libraries
2nd in the code it's always that line where espnow_register-rcv-cb,

What is your internal wifi? How is it different from your home wifi using a router? There is no reason to connect to the internet if you don't want to do it?

you call espnow_register-rcv-cb to register the callback function of receiving ESPNOW data, e.g.

typedef void (*esp_now_recv_cb_t)(const esp_now_recv_info_t *esp_now_info, const uint8_t *data, int data_len)

post your code?, e.g. select “Edit>Copy for forum” then select < CODE/ > and paste the code or text where it says “type or paste code here”

#include <BluetoothLib.h>
#include <ESPNowLib.h>
#include <DHT.h>
#include <Wire.h>
#include <TinyGPS++.h>
#include <Adafruit_Sensor.h>
#include <ESP32_OV7670.h>
#include <base64.h>

#define DHTPIN 4 // Pin where the DHT sensor is connected
#define DHTTYPE DHT11 // DHT 11 sensor
#define FLAME_SENSOR_PIN 34 // Pin where the flame sensor is connected
#define SMOKE_SENSOR_PIN 35 // Pin where the smoke sensor is connected

DHT dht(DHTPIN, DHTTYPE);
TinyGPSPlus gps;
ESP32_OV7670 camera;

HardwareSerial SerialGPS(1);

// Initialize Bluetooth and ESP-NOW libraries
BluetoothLib bt;
ESPNowLib espNow;

uint8_t receiverMacAddr[] = {0x24, 0x0A, 0xC4, 0x2D, 0xA6, 0x8B}; // Example MAC address of the receiver

unsigned long sendInterval = 120000; // Initial interval of 2 minutes
unsigned long lastSendTime = 0;
int fireCount = 0;

void btReceiveCallback(const String& data) {
Serial.println("Received via Bluetooth: " + data);
// Send the received data over ESP-NOW
espNow.send(receiverMacAddr, (uint8_t*)data.c_str(), data.length());
}

void setup() {
Serial.begin(115200);
dht.begin();
pinMode(FLAME_SENSOR_PIN, INPUT);
pinMode(SMOKE_SENSOR_PIN, INPUT);

// Initialize GPS
SerialGPS.begin(9600, SERIAL_8N1, 16, 17);

// Initialize Camera
camera.setup(33, 32); // Adjust pins as necessary

// Initialize Bluetooth
bt.begin("ESP32_BT_Transmitter");
bt.onReceive(btReceiveCallback);

// Initialize ESP-NOW
espNow.begin();

}

void loop() {
unsigned long currentTime = millis();
if (currentTime - lastSendTime >= sendInterval) {
lastSendTime = currentTime;

    // Read temperature and humidity from DHT sensor
    float humidity = dht.readHumidity();
    float temperature = dht.readTemperature();

    // Read flame sensor value
    int flameValue = digitalRead(FLAME_SENSOR_PIN);

    // Read smoke sensor value
    int smokeValue = analogRead(SMOKE_SENSOR_PIN);

    // Read GPS data
    while (SerialGPS.available() > 0) {
        gps.encode(SerialGPS.read());
    }

    if (isnan(humidity) || isnan(temperature)) {
        Serial.println("Failed to read from DHT sensor!");
        return;
    }

    // Capture image from camera
    camera.run();
    String imageBase64 = base64::encode(camera.getfb(), camera.getSize());

    // Prepare data to send
    String data = "Temp: " + String(temperature) + " *C, Humidity: " + String(humidity) + " %, Flame: " + String(flameValue) + ", Smoke: " + String(smokeValue);
    if (gps.location.isValid()) {
        data += ", Lat: " + String(gps.location.lat(), 6) + ", Lon: " + String(gps.location.lng(), 6);
    }
    data += ", Image: " + imageBase64;

    // Send data via Bluetooth
    bt.send(data);

    // Send data via ESP-NOW
    espNow.send(receiverMacAddr, (uint8_t*)data.c_str(), data.length());

    // Print data to Serial Monitor
    Serial.println(data);

    // Check fire detection
    if (flameValue == 1) {
        fireCount++;
    } else {
        fireCount = 0;
        sendInterval = 120000; // Reset to 2 minutes
    }

    // Adjust send interval if fire persists
    if (fireCount >= 3) {
        sendInterval = 240000; // Increase interval to 4 minutes
    }
}

}
This is one of the codes that I tried

#include <ESPNowLib.h>
#include <TFT_eSPI.h>
#include <Wire.h>
#include <base64.h>

#define BUZZER_PIN 32 // Pin where the buzzer is connected

// Initialize ESP-NOW library
ESPNowLib espNow;

// Initialize TFT display
TFT_eSPI tft = TFT_eSPI();

void espNowReceiveCallback(const uint8_t *macAddr, const uint8_t *data, int len) {
// Convert received data to String
String receivedData = "";
for (int i = 0; i < len; i++) {
receivedData += (char)data[i];
}

// Print received data to Serial Monitor
Serial.println("Received via ESP-NOW: " + receivedData);

// Extract image data from received data
int imageIndex = receivedData.indexOf("Image: ") + 7;
String imageBase64 = receivedData.substring(imageIndex);
String sensorData = receivedData.substring(0, imageIndex - 8);

// Display received data on TFT display
tft.fillScreen(TFT_BLACK);
tft.setCursor(0, 0);
tft.setTextColor(TFT_WHITE);
tft.setTextSize(2);
tft.println("Received data:");
tft.setTextSize(1);
tft.println(sensorData);

// Decode and display image
if (imageBase64.length() > 0) {
    uint8_t* image = base64::decode(imageBase64);
    tft.drawRGBBitmap(0, 50, image, 320, 240); // Adjust size and position as necessary
    free(image);
}

// Check for flame detection
if (receivedData.indexOf("Flame: 1") != -1) {
    // Trigger buzzer
    digitalWrite(BUZZER_PIN, HIGH);
} else {
    digitalWrite(BUZZER_PIN, LOW);
}

}

void setup() {
Serial.begin(115200);
pinMode(BUZZER_PIN, OUTPUT);
digitalWrite(BUZZER_PIN, LOW);

// Initialize TFT display
tft.init();
tft.setRotation(1);
tft.fillScreen(TFT_BLACK);
tft.setTextColor(TFT_WHITE);
tft.setTextSize(2);
tft.setCursor(0, 0);
tft.println("Waiting for data...");

// Initialize ESP-NOW
espNow.begin();
espNow.onReceive(espNowReceiveCallback);

}

void loop() {
// Nothing to do here; everything is handled in callbacks
}
Reciever code

Can I try this codes?

your code in post 9 is not using code tags correctly making it unreadable and difficult to copy - try posting again?

it would be difficult to run your code as it includes specific hardware support, e.g. TFT display, DHT sensor, etc

as suggested by @Paul_KD7HB in post 2 try running a very simple test to check that ESPNOW works between two ESP32 micros - when that works try adding your other devices

e.g. a simple ESPNOW transmitter transmitting a structure containing various data (note it is transmitting using the multicast address therefore all receivers should receive the packets)

//  ESP32 test of ESP-NOW transmit a structure
// tested with ES32 and ESP32C3

/*
  Rui Santos
  Complete project details at https://RandomNerdTutorials.com/esp-now-esp32-arduino-ide/
  
  Permission is hereby granted, free of charge, to any person obtaining a copy
  of this software and associated documentation files.
  
  The above copyright notice and this permission notice shall be included in all
  copies or substantial portions of the Software.
*/

#include <esp_now.h>
#include <WiFi.h>

// REPLACE WITH YOUR RECEIVER MAC Address
//uint8_t broadcastAddress[] = { 0xCC, 0x7B, 0x5C, 0x27, 0xE5, 0x8C };  //{0x0C,0xB8,0x15,0xEC,0x1F,0xD0};
uint8_t broadcastAddress[] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };  // or use multicast address

// Structure example to send data
// Must match the receiver structure
struct struct_message {
  char a[32];
  int b;
  float c;
  bool d;
} myData = { "THIS IS A CHARx", random(1, 20), 3.1415926, true };

esp_now_peer_info_t peerInfo;

// callback when data is sent
void OnDataSent(const uint8_t *mac_addr, esp_now_send_status_t status) {
  Serial.print("\r\nLast Packet Send Status: ");
  Serial.print(status);
  Serial.println(status == ESP_NOW_SEND_SUCCESS ? " Delivery Success" : " Delivery Fail");
}

void setup() {
  // Init Serial Monitor
  Serial.begin(115200);
  delay(1000);
  Serial.println("\nESP32 ESP-NOW sender test");
  // Set device as a Wi-Fi Station
  WiFi.STA.begin();  // required for ESP32 core 3 to get MAC address ??
  WiFi.mode(WIFI_STA);
  Serial.println(WiFi.macAddress());

  // Init ESP-NOW
  if (esp_now_init() != ESP_OK) {
    Serial.println("Error initializing ESP-NOW");
    return;
  }

  // Once ESPNow is successfully Init, we will register for Send CB to
  // get the status of Trasnmitted packet
  esp_now_register_send_cb(OnDataSent);

  // Register peer
  memcpy(peerInfo.peer_addr, broadcastAddress, 6);
  peerInfo.channel = 0;
  peerInfo.encrypt = false;

  // Add peer
  if (esp_now_add_peer(&peerInfo) != ESP_OK) {
    Serial.println("Failed to add peer");
    return;
  }
}

void loop() {
  // update values to send
  myData.a[14]++;
  myData.b = random(1, 20);
  myData.c += 1.0;
  myData.d = !myData.d;
  // Send message via ESP-NOW
  esp_err_t result = esp_now_send(broadcastAddress, (uint8_t *)&myData, sizeof(myData));
  if (result == ESP_OK) {
    Serial.print("esp_now_send() - returns success ");
    Serial.println(result);
  } else {
    Serial.print("esp_now_send() - returns error ");
    Serial.println(result);
  }
  delay(5000);
}

and associated receiver

// ESP32 test of ESP-NOW receive a structure

/*
  Rui Santos
  Complete project details at https://RandomNerdTutorials.com/esp-now-esp32-arduino-ide/
  
  Permission is hereby granted, free of charge, to any person obtaining a copy
  of this software and associated documentation files.
  
  The above copyright notice and this permission notice shall be included in all
  copies or substantial portions of the Software.
*/

#include <esp_now.h>
#include <WiFi.h>

// Structure example to receive data
// Must match the sender structure
typedef struct struct_message {
  char a[32];
  int b;
  float c;
  bool d;
} struct_message;

// Create a struct_message called myData
struct_message myData;

// callback function that will be executed when data is received
//void OnDataRecv(const uint8_t * mac, const uint8_t *incomingData, int len) {//
void OnDataRecv(const esp_now_recv_info* mac, const uint8_t* incomingData, int len) {
  memcpy(&myData, incomingData, sizeof(myData));
  Serial.print("Bytes received: ");
  Serial.println(len);
  Serial.print("Char: ");
  Serial.println(myData.a);
  Serial.print("Int: ");
  Serial.println(myData.b);
  Serial.print("Float: ");
  Serial.println(myData.c);
  Serial.print("Bool: ");
  Serial.println(myData.d);
  Serial.println();
}

void setup() {
  // Initialize Serial Monitor
  Serial.begin(115200);
  delay(1000);
  Serial.println("\nESP32 ESP-NOW receiver test");
  // Set device as a Wi-Fi Station
  WiFi.STA.begin();       // required for ESP32 core 3 to get MAC address ??
  WiFi.mode(WIFI_STA);
  Serial.println(WiFi.macAddress());

  // Init ESP-NOW
  if (esp_now_init() != ESP_OK) {
    Serial.println("Error initializing ESP-NOW");
    return;
  }

  // Once ESPNow is successfully Init, we will register for recv CB to
  // get recv packer info
  esp_now_register_recv_cb(OnDataRecv);
}

void loop() {
}

resultant serial monitor output

ESP32C3 transmitter
16:20:56.013 -> ESP32 ESP-NOW sender test
16:20:56.046 -> 10:91:A8:02:00:E8
16:20:56.046 -> Sent with success
16:20:56.046 -> 
16:20:56.046 -> Last Packet Send Status:	Delivery Success
16:21:01.057 -> Sent with success
16:21:01.057 -> 
16:21:01.057 -> Last Packet Send Status:	Delivery Success
16:21:06.039 -> Sent with success
16:21:06.039 -> 
16:21:06.039 -> Last Packet Send Status:	Delivery Success
16:21:11.046 -> Sent with success

------------------------------------------------------------
ESP32 receiver
6:20:38.836 -> ESP32 ESP-NOW receiver test
16:20:38.932 -> CC:7B:5C:27:E5:8C
16:20:56.046 -> Bytes received: 44
16:20:56.046 -> Char: THIS IS A CHARy
16:20:56.046 -> Int: 12
16:20:56.046 -> Float: 4.14
16:20:56.046 -> Bool: 0
16:20:56.046 -> 
16:21:01.057 -> Bytes received: 44
16:21:01.057 -> Char: THIS IS A CHARz
16:21:01.057 -> Int: 2
16:21:01.057 -> Float: 5.14
16:21:01.057 -> Bool: 1
16:21:01.057 -> 
16:21:06.071 -> Bytes received: 44
16:21:06.071 -> Char: THIS IS A CHAR{
16:21:06.071 -> Int: 11
16:21:06.071 -> Float: 6.14
16:21:06.071 -> Bool: 0

I'll try this code that you provided,and both works I'll try again with my code and post it here again if still the same results as before

Hello sir I'm back again
I've tried the example code on esp_now_broadcast_master and
Esp_now_broadcast_slave
The code works but after uploading the code on the master the Arduino ide turns all white and the code disappear it's like a frozen or hung lcd
But the slave displays the serial monitor receiving and displaying hello world,
It only means that my two boards both works on espnow
I just wonder the Arduino ide turned all white after uploading

And I can't even exit or close the ide after it turns all white

But the other window or tab of the ide is good I can close it
It's just on the tab that I used on the master

never seen such a thing? post a photo?

There might just have an error I restarted the laptop and it doesn't happen again

Now we know it's working on espnow
How can I make it work with all the sensors
Can you help me with the code sir

have a look to see if there are libraries which support the sensors
test each sensor in a separate program
when you are sure they work start adding them to your project