Hi, i have a problem with my html site made with arduino. The site consists in a series of button that turn on/off some leds, and empty spaces that indicate the status of the leds. The problem is: when i click "Accendi" (turn on), the led turns on, and when the page is refreshed, the empty space becomes green (turned on). When I click "spegni" (turn off) from the touch display connected with the arduino, the led turns off, but when the page is refreshed, the empty space becomes red (turned off) and the led turns on because there is still the html request from "Accendi". There are any ways to clear or modify the html request or to fix this problem?
Don't cross-post! Your other post: http://forum.arduino.cc/index.php?topic=481828.msg3289356#msg3289356
There are any ways to clear or modify the html request or to fix this problem?
Almost certainly. But, since you are the only one that can see your code, only you can fix this problem.
You are unlikely to get any help unless you post your Arduino code and your HTML.
And of course, when I write post, I mean post PROPERLY.
Sorry but all the program are 800 lines, so these are the main lines for the problem
#include <Adafruit_Sensor.h>
#include <DHT.h>
#include <DHT_U.h>
#include <dht11.h>
#include <SPI.h>
#include <TimerOne.h>
#include <LiquidCrystal_I2C.h>
#include <Keypad.h>
#include <RTClib.h>
#include <Wire.h>
#include <Dns.h>
#include <Ethernet.h>
#include <Client.h>
#include <Server.h>
//--------------------------- LCD ---------------------------
LiquidCrystal_I2C lcd(0x3F, 16, 2);
//--------------------------- RTC ---------------------------
RTC_DS1307 rtc;
//---------------------------- DHT --------------------------
#define TSOGG 22
#define TCUC 23
#define TCAM 24
#define TBAGNO 26
#define TFUORI 27
#define DHTTYPE DHT22
DHT_Unified dht22(TFUORI, DHTTYPE);
sensors_event_t event;
dht11 DHT;
int chk;
bool errDht = false;
int tSogg;
//--------------------------- LUCI --------------------------
#define LSOGG 7
#define LCUC 5
#define LCAM 6
#define LBAGNO 8
#define LCORR 9
#define LFUORI 28
#define LED 29
bool statoLSOGG = false;
bool statoLCUC = false;
bool statoLCAM = false;
bool statoLBAGNO = false;
bool statoLCORR = false;
bool statoLFUORI = false;
//-------------------------- LADRI --------------------------
#define SSOGG 43
#define SCUC 44
#define SCAM 45
#define SBAGNO 47
bool statoVentola = false;
//---------------------------- GAS ---------------------------
#define GSOGG A0
#define GCUC A1
float sensor_volt;
float RS_air;
float RS_gas;
float R0s;
float R0c;
float sensorValue;
float ratioc;
float ratios;
bool gasRilevato = false;
//--------------------------- ALTRO --------------------------
#define BUZZER 3
#define INA 30
#define INB 31
//-------------------------- ETHERNET ------------------------
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; //Indirizzo MAC
byte ip[] = {192, 168, 1, 134}; //Indirizzo IP
byte subnet[] = {255, 255, 255, 0}; //Subnet mask
EthernetServer server(80); //Porta http per la connessione per la connessione con il server
String readString;
bool premuto1;
bool premuto2;
bool premuto3;
bool premuto4;
bool premuto5;
bool premuto6;
bool premutoV;
//-------------------------- KEYPAD --------------------------
const byte ROWS = 4;
const byte COLS = 3;
char hexaKeys[ROWS][COLS] = {
{'1', '2', '3'},
{'4', '5', '6'},
{'7', '8', '9'},
{'*', '0', '#'}
};
byte rowPins[ROWS] = {38, 37, 36, 35};
byte colPins[COLS] = {34, 33, 32};
Keypad keypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS); //Creazione oggetto keypad
//------------------------- VARIABILI ------------------------
bool sec = false;
bool bitE = true;
bool alarm = false;
bool working;
int luce1 = 3;
boolean vent1 = NULL;
boolean luce2 = NULL;
boolean luce3 = NULL;
boolean luce4 = NULL;
boolean luce5 = NULL;
boolean luce6 = NULL;
bool acc = false;
int statoCode = 0;
int code;
int due = 2000;
int temp;
int dieci;
long previousMills = 0;
char lb;
char hb;
char codeC;
char key;
char bt[3];
void setup() {
Serial.begin(38400);
Serial1.begin(38400);
Wire.begin();
//--------------------------- PIN --------------------------
pinMode(BUZZER, OUTPUT); //Buzzer
pinMode(LSOGG, OUTPUT); //Luce Soggiorno
pinMode(LCUC, OUTPUT); //Luce Cucina
pinMode(LCAM, OUTPUT); //Luce Camera1
pinMode(LBAGNO, OUTPUT); //Luce Bagno
pinMode(LCORR, OUTPUT); //Luce Corridoio
pinMode(LFUORI, OUTPUT); //Luce Fuori
pinMode(LED, OUTPUT); //LED Allarme
pinMode(INA, OUTPUT); //Input A Ventola
pinMode(INB, OUTPUT); //Input B Ventola
pinMode(SSOGG, INPUT); //Switch Soggiorno
pinMode(SCUC, INPUT); //Switch Cucina
pinMode(SCAM, INPUT); //Switch Camera
pinMode(SBAGNO, INPUT); //Switch Bagno
pinMode(GSOGG, INPUT); //Gas Soggiorno
pinMode(GCUC, INPUT); //Gas Cucina
//-------------------------- LCD ---------------------------
lcd.init();
lcd.backlight();
lcd.clear();
//-------------------------- DHT ---------------------------
dht22.begin();
//-------------------------- GAS ---------------------------
initGas(GSOGG);
initGas(GCUC);
//-------------------------- RTC ---------------------------
//rtc.adjust(DateTime(2017, 05, 11, 14, 29, 30));
//------------------------- TIMER --------------------------
Timer1.initialize(1000000); //Tempo dell'interupt impostato 1000000ms = 1sec
Timer1.attachInterrupt( timerOneS ); //Funzione da chiamare quando scatta l'interupt
//-------------------------- ETHERNET ------------------------
Ethernet.begin(mac, ip, subnet);
server.begin();
}
void ventola() { //Attivazione ventola in modo automatico ad una certa temperatura
chk = DHT.read(TSOGG);
tSogg = DHT.temperature;
if (tSogg > 28)
{
digitalWrite(INA, LOW);
digitalWrite(INB, HIGH);
} else {
digitalWrite(INA, LOW);
digitalWrite(INB, LOW);
}
Serial.println(tSogg);
}
void initGas(int pin) { //Calcolo del valore dell'aria pulita (effetuato solo una volta ad inizo programma)
for (int x = 0 ; x < 100 ; x++)
{
sensorValue = sensorValue + analogRead(pin);
}
sensorValue = sensorValue / 100.0; //Test su 100 misure
sensor_volt = sensorValue / 1024 * 5.0;
RS_air = (5.0 - sensor_volt) / sensor_volt;
if (pin == GSOGG) {
R0s = RS_air / 9.8;
//Serial.println(R0s);
}
else {
R0c = RS_air / 9.8;
// Serial.println(R0c);
}
}
void gas(int pin) { //Calcolo del valore di gas nell'aria
sensorValue = analogRead(pin);
sensor_volt = (float)sensorValue / 1024 * 5.0;
RS_gas = (5.0 - sensor_volt) / sensor_volt;
if (pin == GSOGG) {
ratios = RS_gas / R0s;
}
else { //Confronto dei valori rilevati con quelli ad aria pulita
ratioc = RS_gas / R0c;
}
if (ratioc < 7 || ratios < 7 ) {
gasRilevato = true;
Serial.print("Gas");
} else {
gasRilevato = false;
}
}
void timerOneS() //Interupt 1sec
{
sec = true;
dieci++;
}
void activeAlarm() { //Accensione Allarme
digitalWrite(LED, HIGH);
tone(BUZZER, 1000);
}
void shutAlarm() { //Spegnimento Allarme
digitalWrite(LED, LOW);
noTone(BUZZER);
}
void checkAlarm() //Controllo Antifurto
{
if (digitalRead(SSOGG) /*|| digitalRead(SCUC) || digitalRead(SCAM) || digitalRead(SBAGNO)*/)
{
activeAlarm();
} else {
shutAlarm();
}
}
void controlloLuci() { //Controllo luci dal sito
if (luce1 == 1)
{
digitalWrite(LSOGG, HIGH);
statoLSOGG = true;
luce1 = 3;
}
if (luce1 == 0) {
digitalWrite(LSOGG, LOW);
statoLSOGG = false;
luce1 = 3;
}
if (vent1) {
digitalWrite(INA, LOW);
digitalWrite(INB, HIGH);
acc = true;
vent1 = NULL;
}
if (!vent1) {
Serial.print(vent1);
digitalWrite(INA, LOW);
digitalWrite(INB, LOW);
acc = false;
vent1 = NULL;
}
if (luce2) {
digitalWrite(LCUC, HIGH);
statoLCUC = true;
luce2 = NULL;
}
if (!luce2) {
digitalWrite(LCUC, LOW);
statoLCUC = false;
luce2 = NULL;
}
if (luce3) {
digitalWrite(LCAM, HIGH);
statoLCAM = true;
luce3 = NULL;
}
if (!luce3) {
digitalWrite(LCAM, LOW);
statoLCAM = false;
luce3 = NULL;
}
if (luce4) {
digitalWrite(LBAGNO, HIGH);
statoLBAGNO = true;
luce4 = NULL;
}
if (!luce4) {
digitalWrite(LBAGNO, LOW);
statoLBAGNO = false;
luce4 = NULL;
}
if (luce5) {
digitalWrite(LFUORI, HIGH);
statoLFUORI = true;
luce5 = NULL;
}
if (!luce5) {
digitalWrite(LFUORI, LOW);
statoLFUORI = false;
luce5 = NULL;
}
if (luce6) {
digitalWrite(LCORR, HIGH);
statoLCORR = true;
luce6 = NULL;
}
if (!luce6) {
digitalWrite(LCORR, LOW);
statoLCORR = false;
luce6 = NULL;
}
}
void controlloBT() { //Controllo dati inviati dal bluetooth
switch (bt[0])
{
case 'a':
dht22.temperature().getEvent(&event);
lb = (int) event.temperature & 0xFF;
Serial.print(event.temperature);
Serial.print(lb);
Serial1.write(lb);
bt[0] = 0;
break;
case 'b':
if (!digitalRead(LFUORI)) {
digitalWrite(LFUORI, HIGH);
statoLFUORI = true;
} else {
digitalWrite(LFUORI, LOW);
statoLFUORI = false;
}
bt[0] = 0;
break;
case 'c':
chk = DHT.read(TCAM);
Serial.print(DHT.temperature);
Serial1.write(DHT.temperature);
bt[0] = 0;
break;
case 'd':
if (!digitalRead(LCAM)) {
digitalWrite(LCAM, HIGH);
statoLCAM = true;
} else {
digitalWrite(LCAM, LOW);
statoLCAM = false;
}
bt[0] = 0;
break;
case 'e':
chk = DHT.read(TBAGNO);
Serial.print(DHT.temperature);
Serial1.write(DHT.temperature);
bt[0] = 0;
break;
case 'f':
if (!digitalRead(LBAGNO)) {
digitalWrite(LBAGNO, HIGH);
statoLBAGNO = true;
} else {
digitalWrite(LBAGNO, LOW);
statoLBAGNO = false;
}
bt[0] = 0;
break;
case 'g':
chk = DHT.read(TSOGG);
Serial.print(DHT.temperature);
Serial1.write(DHT.temperature);
bt[0] = 0;
break;
case 'h':
if (!digitalRead(LSOGG)) {
digitalWrite(LSOGG, HIGH);
statoLSOGG = true;
} else {
digitalWrite(LSOGG, LOW);
statoLSOGG = false;
}
bt[0] = 0;
break;
case 'i':
if (acc) {
Serial.println("Spengo");
digitalWrite(INA, LOW);
digitalWrite(INB, LOW);
acc = false;
} else {
Serial.println("Accendo");
digitalWrite(INA, LOW);
digitalWrite(INB, HIGH);
acc = true;
}
bt[0] = 0;
break;
case 'l':
chk = DHT.read(TCUC);
Serial.print(DHT.temperature);
Serial1.write(DHT.temperature);
bt[0] = 0;
break;
case 'm':
if (!digitalRead(LCUC)) {
digitalWrite(LCUC, HIGH);
statoLCUC = true;
} else {
digitalWrite(LCUC, LOW);
statoLCUC = false;
}
bt[0] = 0;
break;
case 'n':
if (!digitalRead(LCORR)) {
digitalWrite(LCORR, HIGH);
statoLCORR = true;
} else {
digitalWrite(LCORR, LOW);
statoLCORR = false;
}
bt[0] = 0;
break;
}
}
void checkKey() {
key = keypad.getKey();
if (key >= '0' && key <= '9') {
Serial.println(key);
working = true;
checkCode();
}
}
void loop() {
if (Serial1.available()) {
bt[0] = Serial1.read();
bt[1] = Serial1.read();
bt[2] = Serial1.read();
Serial.println(bt[0]);
}
if (bitE) {
lcd.clear();
lcd.setCursor(0, 1);
lcd.print("PIN ALLARME:");
noTone(BUZZER);
digitalWrite(LED, LOW);
}
if (sec) {
agg_oraLcd();
sec = false;
gas(GSOGG);
gas(GCUC);
}
if (dieci == 10) {
dieci = 0;
//ventola();
}
controlloBT();
checkKey();
if (gasRilevato)
activeAlarm();
if (alarm)
checkAlarm();
EthernetClient client = server.available();
if (client) {
while (client.connected()) {
boolean currentLineIsBlank = true;
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' && currentLineIsBlank) {
This is the last one
//CREA LA PAGINA HTML (VERRA' AGGIORNATA AD OGNI ISTRUZIONE NUOVA)
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close"); // the connection will be closed after completion of the response
client.println("Refresh: 10"); // refresh the page automatically every 5 sec
client.println();
client.println("<!DOCTYPE HTML>");
client.println(F("<html><head> <title> Casa Domotica </title> <meta charset=UTF-8/></head><body style=background-color:powderblue;>"));
client.println(F("<h1 align=center style=color:red>Casa Domotica</h1> "));
client.println(F("<div align=center valign=middle>"));
client.println(F("<table>"));
client.println(F("<tr>"));
client.println(F("<td >Luce Soggiorno</td>"));
client.println(F("<td><a href='?L1=1' name=L1 value=1><button> Accendi </button></a></td> "));
if (statoLSOGG) {
client.println(F("<td style=background-color:lime;>            </td>"));
}
else {
client.println(F("<td style=background-color:red;>            </td>"));
}
client.println(F("<td><a href='?L1=0' name=L1 value=0><button> Spegni </button></a></td>"));
client.println(F("<td> Temperatura Soggiorno: </td>"));
chk = DHT.read(TSOGG);
client.println(F("<td>"));
client.println(DHT.temperature);
client.println(F("</td>"));
client.println(F("</tr>"));
client.println(F("<tr>"));
client.println(F("<td >Ventola</td>"));
client.println(F("<td><a href='?V1=1' name=V1 value=1><button> Accendi</button></a></td> "));
if (acc) {
client.println(F("<td style=background-color:lime;>             </td>"));
}
else {
client.println(F("<td style=background-color:red;>             </td>"));
}
client.println(F("<td><a href='?V1=0' name=V1 value=0><button> Spegni</button></a></td>"));
client.println(F("</tr>"));
client.println(F("<tr>"));
client.println(F("<td >Luce Cucina</td>"));
client.println(F("<td><a href='?L2=1' name=L2 value=1><button> Accendi</button></a></td> "));
if (statoLCUC) {
client.println(F("<td style=background-color:lime;>            </td>"));
}
else {
client.println(F("<td style=background-color:red;>            </td>"));
}
client.println(F("<td><a href='?L2=0' name=L2 value=0;><button> Spegni</button></a></td>"));
client.println(F("<td> Temperatura Cucina: </td>"));
chk = DHT.read(TCUC);
client.println(F("<td>"));
client.println(DHT.temperature);
client.println(F("</td>"));
client.println(F("</tr>"));
client.println(F("<tr>"));
client.println(F("<td >Luce Camera</td>"));
client.println(F("<td><a href='?L3=1' name=L3 value=1><button> Accendi </button></a></td> "));
if (statoLCAM) {
client.println(F("<td style=background-color:lime;>            </td>"));
}
else {
client.println(F("<td style=background-color:red;>            </td>"));
}
client.println(F("<td><a href='?L3=0' name=L3 value=0><button> Spegni </button></a></td>"));
client.println(F("<td> Temperatura Camera: </td>"));
chk = DHT.read(TCAM);
client.println(F("<td>"));
client.println(DHT.temperature);
client.println(F("</td>"));
client.println(F("</tr>"));
client.println(F("</table>"));
client.println(F("</div>"));
client.println(F("
"));
client.println(F("
"));
client.println(F("
"));
client.println(F("
"));
client.println(F("<p align=right> © Bortolozzo Federico, Finotello Alessandro, Giordano Luca. </p>"));
//CHIUDE I TAG HTML PER LA PAGINA
client.println(F("</body></html>"));
client.flush();
if (readString.indexOf("L1=1") > 0)
{
luce1 = 1;
}
if (readString.indexOf("V1=1") > 0)
{
vent1 = true;
}
else if (readString.indexOf("L2=1") > 0)
{
luce2 = true;
}
if (readString.indexOf("L3=1") > 0)
{
luce3 = true;
}
else if (readString.indexOf("L4=1") > 0)
{
luce4 = true;
}
else if (readString.indexOf("L5=1") > 0)
{
luce5 = true;
}
else if (readString.indexOf("L6=1") > 0)
{
luce6 = true;
}
else if (readString.indexOf("L1=0") > 0)
{
luce1 = 0;
premuto1 = true;
}
if (readString.indexOf("V1=0") > 0)
{
vent1 = false;
premutoV = true;
}
else if (readString.indexOf("L2=0") > 0)
{
luce2 = false;
premuto2 = true;
}
else if (readString.indexOf("L3=0") > 0)
{
luce3 = false;
premuto3 = true;
}
else if (readString.indexOf("L4=0") > 0)
{
luce4 = false;
premuto4 = true;
}
else if (readString.indexOf("L5=0") > 0)
{
luce5 = false;
premuto5 = true;
}
else if (readString.indexOf("L6=0") > 0)
{
luce6 = false;
premuto6 = true;
}
controlloLuci();
break;
}
if (c == '\n') {
// you're starting a new line
currentLineIsBlank = true;
} else if (c != '\r') {
// you've gotten a character on the current line
currentLineIsBlank = false;
}
}
}
//SI PREPARA PER UNA NUOVA ISTRUZIONE
readString = "";
delay(1);
//TERMINA LE OPERAZIONI CLIENTE
client.stop();
}
}