• Witaj na Forum Arduino Polska! Zapraszamy do rejestracji!
  • Znajdziesz tutaj wiele informacji na temat hardware / software.
Witaj! Logowanie Rejestracja


Ocena wątku:
  • 0 głosów - średnia: 0
  • 1
  • 2
  • 3
  • 4
  • 5
Błąd związany z odświeżaniem danych
#1
Witam jak mam szczytowanie danych z czujnika temperatury i strony www to dane nie odświeżają się dlaczego taki problem powstał na serial monitor ładnie temperatura się wyświetla  
kod
Kod:
#include <OneWire.h>
#include <DallasTemperature.h>
#include <Ethernet.h>
#include <SPI.h>
#include <Wire.h>
#include <FastIO.h>
#include <I2CIO.h>
#include <LCD.h>
#include <LiquidCrystal.h>
#include <LiquidCrystal_I2C.h>
#include <LiquidCrystal_SR.h>
#include <LiquidCrystal_SR2W.h>
#include <LiquidCrystal_SR3W.h>
//termometr
#define ONE_WIRE_BUS 2
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
// lcd
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);  // Ustawienie adresu ukladu na 0x27

//network NB: Pins 10, 11, 12 and 13 are reserved for Ethernet module.
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192, 168, 0, 177 };
byte gateway[] = { 192, 168, 1, 1 };
byte subnet[] = { 255, 255, 255, 0 };

String readString;

String Led;

int led[] = {00, 3, 4 , 5 , 6 , 7 , 8, 9  }; //Led pins num 0 in arry is not used
int numofleds = 7; //numofleds
String value[] = {"on", "on", "on", "on", "on", "on", "on", "on"}; //startup all led are off
String value1[] = {"1", "1", "1", "1", "1", "1", "1", "1"}; //startup all led are off
EthernetServer server(80);
String data;
void setup()
{
 lcd.begin(16, 2);  // Inicjalizacja LCD 2x16
 lcd.backlight(); // zalaczenie podwietlenia
 delay(500);
 lcd.setCursor(2, 0); // Ustawienie kursora w pozycji 0,0 (pierwszy wiersz, pierwsza kolumna)
 lcd.print("Witaj Dawid!");
 lcd.setCursor(1, 0); // Ustawienie kursora w pozycji 0,0 (pierwszy wiersz, pierwsza kolumna)
 delay(300);
 lcd.clear();
 lcd.setCursor(0, 0); // Ustawienie kursora w pozycji 0,0 (pierwszy wiersz, pierwsza kolumna)
 lcd.print("Temp:");
 lcd.setCursor (6, 0);
 Serial.begin(9600);
 sensors.begin();
 // internt
 Ethernet.begin(mac, ip, gateway, subnet);
 server.begin();
 //set pin mode
 for (int j = 1; j < (numofleds + 1); j++) {
 pinMode(led[j], OUTPUT);
 }
 Serial.println("Serial READY");
 Serial.println("Ethernet READY");
 Serial.println("Server READY");
}

void loop()
{
 sensors.requestTemperatures();
 

 // wyświetla temperaturę
 lcd.print(sensors.getTempCByIndex(0));
 Serial.println(sensors.getTempCByIndex(0));
 lcd.setCursor (11, 0);
 lcd.print("C");

 
 EthernetClient client = server.available();

 // wyświetla status
 lcd.setCursor (3, 1);
 lcd.print(value1[1]);
 lcd.setCursor (5, 1);
 lcd.print(value1[2]);
 lcd.setCursor (7, 1);
 lcd.print(value1[3]);
 lcd.setCursor (9, 1);
 lcd.print(value1[4]);
 lcd.setCursor (11, 1);
 lcd.print(value1[5]);
 lcd.setCursor (13, 1);
 lcd.print(value1[6]);
 lcd.setCursor (15, 1);
 lcd.print(value1[7]);

 if (client) {
   // an http request ends with a blank line
   boolean current_line_is_blank = true;
   while (client.connected()) {
     if (client.available()) {
       char c = client.read();

       if (readString.length() < 100) {
         readString += c;
       }
       if (c == '\n' && current_line_is_blank) {

         // send a standard http response header
         client.println("HTTP/1.1 200 OK");
         client.println("Content-Type: text/html");
         client.println();
         client.println("<html><body><form method=get>");
         client.println("<p>Led controller</p>");

         for (int i = 1; i < (numofleds + 1) ; i++) {
           Led = String("led") + i;

           if (readString.indexOf(Led + "=on") > 0 || readString.indexOf("all=on") > 0) {
             Serial.println(Led + "on");
             digitalWrite(led[i], HIGH);
             value[i] = "off";
             value1[i] = "0";
           } else if (readString.indexOf(Led + "=off") > 0 || readString.indexOf("all=off") > 0 ) {
             Serial.println(Led + "off");
             digitalWrite(led[i], LOW);
             value[i] = "on";
             value1[i] = "1";
           }
           client.println("<table><tr>");
           client.println("<td>" + Led + " </td><td> <input type=submit name=" + Led + " value=" + value[i] + "></td>");
           client.println("</tr></table>");
         }
         client.println("<br>All <input type=submit name=all value=on><input type=submit name=all value=off>");
         client.println("</from><br /><br />");
         // Print readings from sensors (DS18B20)
         client.println("Temperatura:  ");
         client.print(sensors.getTempCByIndex(0));
         client.println("C");
         client.println("</html></body>");
         break;
       }
       if (c == '\n') {
         // we're starting a new line
         current_line_is_blank = true;
       } else if (c != '\r') {
         // we've gotten a character on the current line
         current_line_is_blank = false;
       }
     }
   }
   
   delay(1);
   readString = "";
   client.stop();
 }
}
 
Odpowiedź
  


Skocz do:


Przeglądający: 1 gości