Yeah the videostreaming somehow blocks the sensor readings updating. Is there any way to to "force" the code to read those sensors ? I dont ask a lot from the video stream.. few updates in a minute is basically enough. Thats why NodeMCU would be good enough, but do I really need a second NodeMCU to read those sensors? I needed to remove big part of the camera code to fit this in, but basically whats happening:
// ESP8266-12E ArduCAM Mini Camera Server
//
// This program demonstrates using an ArduCAM Mini 2MP camera with an ESP8266-12E module.
// An OV2640 2MP ArduCAM Mini was used with this program.
//
// The program has a web interface that will allow:
// - storing and viewing of captured jpg files
// - viewing live streamed video
// - changing the resolution
//
// Captured jpeg files are stored on the ESP8266-12E built in memory.
//
// The capture and streaming features can be reached directly via the browser by using the format:
// http://IPaddress/capture - for still capture
// http://IPaddress/stream - for streaming video
//
// The captured stills or streamed video can be accessed as an HTML image:
// <img src="http://IPaddress/capture">
// or
// <img src="http://IPaddress/stream">
//
//
// Wiring diagram to connect ArduCAM to ESP8266-12E
//
// ArduCAM mini -> ESP8266-12E
// CS -> D0
// MOSI -> D7
// MISC -> D6
// SCK -> D5
// GND -> GND
// VCC -> 3V3
// SDA -> D2
// SCL -> D1
#include <FS.h> // FOR SPIFFS
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <Wire.h>
#include <ArduCAM.h>
#include <SPI.h>
#include <DHT.h>
#include <SimpleTimer.h>
#include "memorysaver.h"
#if !(defined ESP8266 )
#error Please select the ArduCAM ESP8266 UNO board in the Tools/Board
#endif
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "*****";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "*****";
char pass[] = "*******";
//#define BLYNK_PRINT Serial
SimpleTimer timer;
//This demo can only work on OV2640_MINI_2MP or ARDUCAM_SHIELD_V2 platform.
#if !(defined (OV2640_MINI_2MP)||(defined (ARDUCAM_SHIELD_V2) && defined (OV2640_CAM)))
#error Please select the hardware platform and camera module in the ../libraries/ArduCAM/memorysaver.h file
#endif
// set GPIO16 as the slave select :
const int CS = 16;
// if the video is chopped or distored, try using a lower value for the buffer
// lower values will have fewer frames per second while streaming
static const size_t bufferSize = 4096; // 4096; //2048; //1024;
static const int fileSpaceOffset = 700000;
static const int wifiType = 0; // 0:Station 1:AP
// Set DHT11 pin
#define DHTPIN 2 // Digital pin D4
// Uncomment whatever type you're using!
#define DHTTYPE DHT11 // DHT 11
//#define DHTTYPE DHT22 // DHT 22, AM2302, AM2321
//#define DHTTYPE DHT21 // DHT 21, AM2301
DHT dht(DHTPIN, DHTTYPE);
//Ph-SensorStuff:
const int analogInPin = A0;
int sensorValue = 0;
unsigned long int avgValue;
float b;
int buf[10], temp;
void sendSensor()
{
float h = dht.readHumidity();
float t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit
Serial.println(h);
Serial.println(t);
//int newH = ((h+0.05)*10);
//h = (newH / 10.0);
//
//int newT = ((t+0.05)*10);
//t = (newT / 10.0);
// Serial.print("sensor = ");
// Serial.println(phValue);
if (isnan(h) || isnan(t)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
// You can send any value at any time.
// Please don't send more that 10 values per second.
Blynk.virtualWrite(V5, h); //V5 is for Humidity
Blynk.virtualWrite(V6, t); //V6 is for Temperature
//Blynk.virtualWrite(V7, water_sensor_a); //V7 is for Water sensor a
}
//------------------
}
////////////////////////////////
// main setup function //
////////////////////////////////
void setup() {
SPIFFS.begin();
delay(1000);
//Blynk.begin(auth, ssid, password);
// SPIFFS.format(); // uncomment to completely clear data including properties file
// check for properties file
File f = SPIFFS.open(fName, "r");
if (!f) {
// no file exists so lets format and create a properties file
Serial.println("Please wait 30 secs for SPIFFS to be formatted");
SPIFFS.format();
Serial.println("Spiffs formatted");
f = SPIFFS.open(fName, "w");
if (!f) {
Serial.println("properties file open failed");
}
else
{
// write the defaults to the properties file
Serial.println("====== Writing to properties file =========");
f.println(resolution);
f.close();
}
}
else
{
// if the properties file exists on startup, read it and set the defaults
Serial.println("Properties file exists. Reading.");
while (f.available()) {
// read line by line from the file
String str = f.readStringUntil('\n');
Serial.println(str);
resolution = str.toInt();
}
f.close();
}
uint8_t vid, pid;
uint8_t temp;
dht.begin();
// Setup a function to be called every second
timer.setInterval(3000L, sendSensor);
timer.setInterval(4000L, sendPHsensor);
#if defined(__SAM3X8E__)
Wire1.begin();
#else
Wire.begin();
#endif
Serial.begin(115200);
Serial.println("ArduCAM Start!");
// set the CS as an output:
pinMode(CS, OUTPUT);
// initialize SPI:
SPI.begin();
SPI.setFrequency(4000000); //4MHz
Blynk.begin(auth, ssid, pass, IPAddress(139, 59, 206, 133), 80);
// Blynk.begin(auth, ssid, pass);
// // You can also specify server:
// //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 80);
// //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);
}
// timer.setInterval(5000L, sendPHsensor);
// setup handlers
server.on("/capture", HTTP_GET, serverCapture);
server.on("/stream", HTTP_GET, serverStream);
server.on("/submit", handleSubmit);
server.on("/clear", clearData);
server.onNotFound(handleNotFound);
server.begin();
Serial.println("Server started");
Dir dir = SPIFFS.openDir("/pics");
while (dir.next()) {
fileCount++;
}
FSInfo fs_info;
SPIFFS.info(fs_info);
fileTotalKB = (int)fs_info.totalBytes;
fileUsedKB = (int)fs_info.usedBytes;
}
void sendPHsensor() {
for (int i = 0; i < 10; i++)
{
buf[i] = analogRead(analogInPin);
delay(10);
}
for (int i = 0; i < 9; i++)
{
for (int j = i + 1; j < 10; j++)
{
if (buf[i] > buf[j])
{
temp = buf[i];
buf[i] = buf[j];
buf[j] = temp;
}
}
}
avgValue = 0;
for (int i = 2; i < 8; i++)
avgValue += buf[i];
float pHVol = (float)avgValue * 5.0 / 1024 / 6;
// float phValue = -5.70 * pHVol + 21.34;
float phValue = -5.70 * pHVol + 34.00;
Serial.print("sensor = ");
Serial.println(phValue);
Blynk.virtualWrite(V4, phValue);
//delay(20);
}
//void cameraSend(){
// server.handleClient();
//}
/////////////////////////////
// Main loop function //
/////////////////////////////
void loop() {
server.handleClient();
Blynk.run(); // Initiates Blynk
timer.run(); // Initiates SimpleTimer
}