please see the code below:
I get error:
C:\Users\Roee\Documents\Arduino\AdvancedWebServer_v5_ok\AdvancedWebServer_v5_ok.ino: In function 'void roee_clk_run_always()':
C:\Users\Roee\Documents\Arduino\AdvancedWebServer_v5_ok\AdvancedWebServer_v5_ok.ino:194:15: error: invalid operands of types 'int' and '' to binary 'operator<'
194 | if (min_old < min) ){
| ~~~~^
C:\Users\Roee\Documents\Arduino\AdvancedWebServer_v5_ok\AdvancedWebServer_v5_ok.ino:194:22: error: expected primary-expression before ')' token
194 | if (min_old < min) ){
| ^
exit status 1
Compilation error: invalid operands of types 'int' and '' to binary 'operator<'
while if I put the lines:
if (min_old < min) ){
Serial.print("one min ");
Serial.print(min_count);
Serial.print(" Temp:");
Serial.println (temp_int);
min_old= int(min);
min_count++;
}
inside
void handleRoot
this is working...
The reason I want to change the place is since I want to have minutes count even if the HTTP page is not connected to server
Here is the full code with error:
/*
Copyright (c) 2015, Majenko Technologies
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.
* * Neither the name of Majenko Technologies nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
#include <StreamString.h>
#ifndef STASSID
#define STASSID "Roee2"
#define STAPSK "0502147870"
#define Temp_array_size 10
#endif
const char *ssid = STASSID;
const char *password = STAPSK;
const int analogInPin = A0; // ESP8266 Analog Pin ADC0 = A0
//Roee for Temp
int Vo;
float R1 = 1586.1;
float logR2, R2, T, Tc, Tf;
float c1 = 1.630740587e-03, c2 = 1.387891336e-04, c3 = 17.90745831e-07,deg1=0;
int x=10,y2=10,temp_int,temp_int_old,sec_old,sec=0,min_old=0,min_count=1;
int Temp_array[Temp_array_size],Temp_array_place;
//
ESP8266WebServer server(80);
const int led = 13;
int sensorValue = 0; // value read from the port A0
void handleRoot() {
digitalWrite(led, 1);
sec_old=sec;
sec = millis() / 1000;
int min = sec / 60;
int hr = min / 60;
// Serial.println("handler");
if (sec != sec_old) Serial.println("one sec");
StreamString temp;
temp.reserve(500); // Preallocate a large chunk to avoid memory fragmentation
temp.printf("\
<html>\
<head>\
<meta http-equiv='refresh' content='5'/>\
<title>ESP8266 Demo</title>\
<style>\
body { background-color: #cccccc; font-family: Arial;font-size: 30; Helvetica, Sans-Serif; Color: #000088; }\
</style>\
</head>\
<body>\
<h2>Temperature Meter By Roee B</h2>\
<p>Uptime: %02d:%02d:%02d</p>\
<h1> Temperature: %2.1f C</h1>\
<img src=\"/test.svg\" />\
</body>\
</html>",
hr, min % 60, sec % 60, Tc);
server.send(200, "text/html", temp.c_str());
digitalWrite(led, 0);
sensorValue = analogRead(analogInPin);
}
void handleNotFound() {
digitalWrite(led, 1);
String message = "File Not Found\n\n";
message += "URI: ";
message += server.uri();
message += "\nMethod: ";
message += (server.method() == HTTP_GET) ? "GET" : "POST";
message += "\nArguments: ";
message += server.args();
message += "\n";
for (uint8_t i = 0; i < server.args(); i++) { message += " " + server.argName(i) + ": " + server.arg(i) + "\n"; }
server.send(404, "text/plain", message);
digitalWrite(led, 0);
}
void drawGraph() {
String out;
out.reserve(2600);
char temp[70];
Roee_temp_calc();
out += "<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" width=\"400\" height=\"150\">\n";
out += "<rect width=\"400\" height=\"150\" fill=\"rgb(250, 230, 210)\" stroke-width=\"1\" stroke=\"rgb(0, 0, 0)\" />\n";
out += "<g stroke=\"black\">\n";
// int y = rand() % 130;
while (x<390)
{
temp_int = int(round(Tc));
int y=100;
while (x<390){
sprintf(temp, "<line x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" stroke-width=\"1\" />\n", x, 100+temp_int_old, x + 10, 100 +temp_int);
// out += temp;
x=x+10;
}
out += "</g>\n</svg>\n";
server.send(200, "image/svg+xml", out);
}
}
void setup(void) {
pinMode(led, OUTPUT);
digitalWrite(led, 0);
Serial.begin(115200);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
Serial.println("");
for (int j=0;j<Temp_array_size; j++)
Temp_array[j]=0;
// Wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
if (MDNS.begin("esp8266")) { Serial.println("MDNS responder started"); }
server.on("/", handleRoot);
server.on("/test.svg", drawGraph);
server.on("/inline", []() {
server.send(200, "text/plain", "this works as well");
});
server.onNotFound(handleNotFound);
server.begin();
Serial.println("HTTP server started");
}
void Roee_temp_calc()
{
temp_int_old = int(round(Tc));
Vo = analogRead(analogInPin);
R2 = R1 * (1023.0 / (float)Vo - 1.0);
logR2 = log(R2);
T = (1.0 / (c1 + c2*logR2 + c3*logR2*logR2*logR2));
Tc = T - 273.15;
Tf = (Tc * 9.0)/ 5.0 + 32.0;
deg1=Tc;
// Serial.print("temp calc");
}
void roee_clk_run_always()
{
//min = sec / 60;
if (min_old < min) ){
Serial.print("one min ");
Serial.print(min_count);
Serial.print(" Temp:");
Serial.println (temp_int);
min_old= int(min);
min_count++;
}
}
void Push_array_temp( int new_temperature) // push new value to array
{
for (int j=1; j<Temp_array_size; j++)
Temp_array[j+1] = Temp_array[j];
Temp_array[0] = new_temperature;
}
void loop(void) {
server.handleClient();
roee_clk_run_always();
MDNS.update();
}
type or paste code here
type or paste code here