Hi, i'm trying to figure out how to show in a continuos loop the temperature on the arduino webserver and change an arlarm variable with two buttons (plus button and minus button).
This should allow me to make a buzzer play a tone if the actual temperature reaches the value i decide with the buttons + or -
I have realized the following but it's not working the way i want :
#include <SPI.h>
#include <Ethernet.h>
int pos = 0;
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 192, 168, 1, 20 }; // ip in lan (that's what you need to use in your browser. ("192.168.1.178")
byte gateway[] = { 192, 168, 1, 1 }; // internet access via router
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
EthernetServer server(80); //server port
String readString;
int temp_soglia = 18;
int temp_allarme = 22;
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
// start the Ethernet connection and the server:
Ethernet.begin(mac, ip, gateway, subnet);
server.begin();
Serial.print("Server IP : ");
Serial.println(Ethernet.localIP());
}
void loop() {
// Create a client connection
EthernetClient client = server.available();
client.println("");
client.print("Temperatura di soglia = ");
client.print(temp_soglia);
client.println("
");
client.print("Temperatura d'allarme = ");
client.print(temp_allarme);
client.println("
");
client.println("");
if (client) {
while (client.connected()) {
if (client.available()) {
char c = client.read();
//read char by char HTTP request
if (readString.length() < 100) {
//store characters to string
readString += c;
//Serial.print(c);
}
//if HTTP request has ended
if (c == '\n') {
Serial.print("Valore readstring = ");
Serial.println(readString); //print to serial monitor for debuging
client.println("HTTP/1.1 200 OK"); //send new page
client.println("Content-Type: text/html");
client.println();
client.println("");
client.println("");
client.println("");
client.println("");
client.println("Cat House Monitoring");
client.println("");
client.println("");
client.println("
Progetto di monitoraggio temperatura
");client.println("
");
client.println("
");
client.println("
Arduino con Ethernet Shield
");client.println("
");
client.print("Temperatura di soglia = ");
client.print(temp_soglia);
client.print(" ");
client.print("<a href="/?plus_soglia"">Piu");
client.print(" ");
client.println("<a href="/?minus_soglia"">Meno
");
client.println("
");
client.print("Temperatura di allarme = ");
client.print(temp_allarme);
client.print(" ");
client.print("<a href="/?plus_allarme"">Piu");
client.print(" ");
client.print("<a href="/?minus_allarme"">Meno
");
client.println("
");
client.println("
");
client.println("");
client.println("");
delay(1);
//stopping client
client.stop();
//controls the Arduino if you press the buttons
if (readString.indexOf("?plus_soglia") >0){
temp_soglia = temp_soglia +1 ;
}
if (readString.indexOf("?minus_soglia") >0){
temp_soglia = temp_soglia -1 ;
}
if (readString.indexOf("?plus_allarme") >0){
temp_allarme = temp_allarme +1 ;
}
if (readString.indexOf("?minus_allarme") >0){
temp_allarme = temp_allarme -1 ;
}
//clearing string for next read
readString="";
client.print("<meta http-equiv="refresh" content="0">");
client.println("");
}
}
}
}
}
Can someone help me please ?
I just can't understand how to get on the same page the continuos values of temperature reading and the ability to change the value of temp_soglia or temp_allarme in ordere to be able to recall a certain void for allarm.