Hello I try to make this sketch work but there is a conflict with sensor_t and I can't seem to find a solution.
Sketch:
#define BLYNK_TEMPLATE_ID "TMPL5me-22yZE"
#define BLYNK_TEMPLATE_NAME "Plantevander 2"
#define BLYNK_AUTH_TOKEN "lXuIlcR_gSDyWSdg4KO8FRF9huqjVlWv"
#define BLYNK_PRINT Serial
#include "OV2640.h"
#include <WiFi.h>
#include <WebServer.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include <Adafruit_Sensor.h>
#include <DHT.h>
#include <DHT_U.h>
#define DHTPIN 12
#define DHTTYPE DHT11 // DHT 11
DHT_Unified dht(DHTPIN, DHTTYPE);
#define PWDN_GPIO_NUM 32
#define RESET_GPIO_NUM -1
#define XCLK_GPIO_NUM 0
#define SIOD_GPIO_NUM 26
#define SIOC_GPIO_NUM 27
#define Y9_GPIO_NUM 35
#define Y8_GPIO_NUM 34
#define Y7_GPIO_NUM 39
#define Y6_GPIO_NUM 36
#define Y5_GPIO_NUM 21
#define Y4_GPIO_NUM 19
#define Y3_GPIO_NUM 18
#define Y2_GPIO_NUM 5
#define VSYNC_GPIO_NUM 25
#define HREF_GPIO_NUM 23
#define PCLK_GPIO_NUM 22
char auth[] = BLYNK_AUTH_TOKEN;
const char* ssid = "****";
const char* password = "****";
float dry = 1700; // value for dry sensor
float wet = 1600; // value for wet sensor
float DryAlarm = 0;
float WetValue = 0;
float DryValue = 0;
float AutoCal = 0;
// This function creates the timer object. It's part of Blynk library
BlynkTimer timer;
OV2640 cam;
WebServer server(80);
const char HEADER[] = "HTTP/1.1 200 OK\r\n" \
"Access-Control-Allow-Origin: *\r\n" \
"Content-Type: multipart/x-mixed-replace; boundary=123456789000000000000987654321\r\n";
const char BOUNDARY[] = "\r\n--123456789000000000000987654321\r\n";
const char CTNTTYPE[] = "Content-Type: image/jpeg\r\nContent-Length: ";
const int hdrLen = strlen(HEADER);
const int bdrLen = strlen(BOUNDARY);
const int cntLen = strlen(CTNTTYPE);
void handle_jpg_stream(void)
{
char buf[32];
int s;
WiFiClient client = server.client();
client.write(HEADER, hdrLen);
client.write(BOUNDARY, bdrLen);
while (true)
{
if (!client.connected()) break;
cam.run();
s = cam.getSize();
client.write(CTNTTYPE, cntLen);
sprintf( buf, "%d\r\n\r\n", s );
client.write(buf, strlen(buf));
client.write((char *)cam.getfb(), s);
client.write(BOUNDARY, bdrLen);
}
}
const char JHEADER[] = "HTTP/1.1 200 OK\r\n" \
"Content-disposition: inline; filename=capture.jpg\r\n" \
"Content-type: image/jpeg\r\n\r\n";
const int jhdLen = strlen(JHEADER);
void handle_jpg(void)
{
WiFiClient client = server.client();
cam.run();
if (!client.connected()) return;
client.write(JHEADER, jhdLen);
client.write((char *)cam.getfb(), cam.getSize());
}
void handleNotFound()
{
String message = "Server is running!\n\n";
message += "URI: ";
message += server.uri();
message += "\nMethod: ";
message += (server.method() == HTTP_GET) ? "GET" : "POST";
message += "\nArguments: ";
message += server.args();
message += "\n";
server.send(200, "text / plain", message);
}
//What to do when successfully connected to Blynk
BLYNK_CONNECTED() {
//Makes sure that V1 is in sync in case of lost connection.
Blynk.syncVirtual(V0);
Blynk.syncVirtual(V6);
Blynk.syncVirtual(V7);
Blynk.syncVirtual(V8);
// Blynk.syncVirtual(V9);
//Message that shows up in Serial Monitor.
BLYNK_LOG("Connected to Blynk 🙌");
//A LED lights up when connected to server.
//digitalWrite(13, HIGH);
}
//What to do when not connected to Blynk
BLYNK_DISCONNECTED() {
//Message that shows up in Serial Monitor.
BLYNK_LOG("Blynk disconnected");
}
BLYNK_WRITE(V9)
{
// Set incoming value from pin V0 to a variable
DryAlarm = param.asInt();
}
BLYNK_WRITE(V8)
{
// Set incoming value from pin V0 to a variable
AutoCal = param.asInt();
}
BLYNK_WRITE(V7)
{
// Set incoming value from pin V0 to a variable
DryValue = param.asInt();
}
BLYNK_WRITE(V6)
{
// Set incoming value from pin V0 to a variable
WetValue = param.asInt();
}
const int R1 = 9750;//we read the voltage acrosst this resistor ()
const int R2 = 35860;
float VB1;
int mV;
const int VinPin = 36; // Potentiometer connected to GPIO4
//This is for preventing dataoverflow so it only sends the updated value with certain intervals.
//The update interval is defined by timer.setInterval in the void setup section.
void myTimerEvent() {
uint32_t voltage_mV = analogReadMilliVolts(VinPin); // Read the voltage in millivolts
mV = voltage_mV;
VB1 = (((float) voltage_mV) / 1000.0) * (1 + (float)R2/(float)R1);
Serial.print("VB1 Voltage: ");
Serial.print(VB1); // Convert millivolts to volts
Serial.println("V ");
Blynk.virtualWrite(V4, VB1);
int sensorVal = analogRead(35);
int percentageHumididy = map(sensorVal, wet, dry, 100, 0);
if ((AutoCal) == 1){
Serial.println("AutoCal ON");
if (percentageHumididy > 100)
{
wet = sensorVal;
Blynk.virtualWrite(V6, wet);
Serial.print("Wet = ");
Serial.print(wet);
}
if (percentageHumididy < 0)
{
dry = sensorVal;
Blynk.virtualWrite(V7, dry);
Serial.print(" | Dry = ");
Serial.print(dry);
}
}
else{
dry = DryValue;
wet = WetValue;
}
Blynk.virtualWrite(V3, percentageHumididy);
Blynk.virtualWrite(V5, sensorVal);
Serial.print(F("Ground Humidity: "));
Serial.print(percentageHumididy);
Serial.println(F("%"));
if(percentageHumididy < DryAlarm){
Blynk.logEvent("Dry");
Serial.println("tørt");
}
// Get temperature event and print its value.
sensors_event_t event;
dht.temperature().getEvent(&event);
if (isnan(event.temperature)) {
Serial.println(F("Error reading temperature!"));
}
else {
Serial.print(F("Temperature: "));
Serial.print(event.temperature);
Serial.println(F("°C"));
Blynk.virtualWrite(V1, event.temperature);
}
// Get humidity event and print its value.
dht.humidity().getEvent(&event);
if (isnan(event.relative_humidity)) {
Serial.println(F("Error reading humidity!"));
}
else {
Serial.print(F("Humidity: "));
Serial.print(event.relative_humidity);
Serial.println(F("%"));
Blynk.virtualWrite(V2, event.relative_humidity);
}
// You can send any value at any time.
// Please don't send more that 10 values per second.
//send among of seconds that has past to virtual pin V0
Blynk.virtualWrite(V0, millis() / 1000);
// This function describes what will happen with each timer tick
// e.g. writing sensor value to datastream V2
}
void setup()
{
Serial.begin(115200);
//while (!Serial); //wait for serial connection.
dht.begin();
sensor_t sensor;
dht.temperature().getSensor(&sensor);
dht.humidity().getSensor(&sensor);
// Setup a function to be called every second
timer.setInterval(2000L, myTimerEvent);
camera_config_t config;
config.ledc_channel = LEDC_CHANNEL_0;
config.ledc_timer = LEDC_TIMER_0;
config.pin_d0 = Y2_GPIO_NUM;
config.pin_d1 = Y3_GPIO_NUM;
config.pin_d2 = Y4_GPIO_NUM;
config.pin_d3 = Y5_GPIO_NUM;
config.pin_d4 = Y6_GPIO_NUM;
config.pin_d5 = Y7_GPIO_NUM;
config.pin_d6 = Y8_GPIO_NUM;
config.pin_d7 = Y9_GPIO_NUM;
config.pin_xclk = XCLK_GPIO_NUM;
config.pin_pclk = PCLK_GPIO_NUM;
config.pin_vsync = VSYNC_GPIO_NUM;
config.pin_href = HREF_GPIO_NUM;
config.pin_sscb_sda = SIOD_GPIO_NUM;
config.pin_sscb_scl = SIOC_GPIO_NUM;
config.pin_pwdn = PWDN_GPIO_NUM;
config.pin_reset = RESET_GPIO_NUM;
config.xclk_freq_hz = 20000000;
config.pixel_format = PIXFORMAT_JPEG;
// Frame parameters
// config.frame_size = FRAMESIZE_UXGA;
config.frame_size = FRAMESIZE_QVGA;
config.jpeg_quality = 12;
config.fb_count = 2;
#if defined(CAMERA_MODEL_ESP_EYE)
pinMode(13, INPUT_PULLUP);
pinMode(14, INPUT_PULLUP);
#endif
cam.init(config);
IPAddress ip;
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(F("."));
}
ip = WiFi.localIP();
Serial.println(F("WiFi connected"));
Serial.println("");
// Configure Blynk
Blynk.config(auth);
Serial.println("Connecting to Blynk");
while (Blynk.connect() == false) {
delay(500);
Serial.print(".");
}
Serial.println("\nConnected to Blynk");
Serial.println(ip);
Serial.print("Stream Link: http://");
Serial.print(ip);
Serial.println("/mjpeg/1");
server.on("/mjpeg/1", HTTP_GET, handle_jpg_stream);
server.on("/jpg", HTTP_GET, handle_jpg);
server.onNotFound(handleNotFound);
server.begin();
}
void loop()
{
timer.run();
server.handleClient();
Blynk.run();
}
Error message:
In file included from C:\Users\Asus ROG\Downloads\live-video-streaming-esp32-cam-blynk-iot\live-streaming\live-streaming.ino:14:
c:\Users\Asus ROG\Documents\Arduino\libraries\Adafruit_Unified_Sensor/Adafruit_Sensor.h:194:3: error: conflicting declaration 'typedef struct sensor_t sensor_t'
} sensor_t;
^~~~~~~~
In file included from C:\Users\Asus ROG\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.17/tools/sdk/esp32/include/esp32-camera/driver/include/esp_camera.h:71,
from C:\Users\Asus ROG\Downloads\live-video-streaming-esp32-cam-blynk-iot\live-streaming\OV2640.h:9,
from C:\Users\Asus ROG\Downloads\live-video-streaming-esp32-cam-blynk-iot\live-streaming\live-streaming.ino:9:
C:\Users\Asus ROG\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.17/tools/sdk/esp32/include/esp32-camera/driver/include/sensor.h:253:3: note: previous declaration as 'typedef struct _sensor sensor_t'
} sensor_t;
^~~~~~~~
exit status 1
Compilation error: exit status 1
It would be nice to use the DHT sensor without Adafruit, also what does adafruit do?
Thank you in advance.