• 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
Przekazywanie danych z czujników do MYSQL
#1
Mam kod który wyświetla wyrzuca temperaturę z czujników na stronę.
Potrzebuję by dane te trafiały do mysql co 1 godzinę .
Może ktoś pomóc
Kod:
#include <ESP8266WebServer.h>
#include <OneWire.h>
#include <DallasTemperature.h>

// Data wire is plugged into port D2 on the ESP8266
#define ONE_WIRE_BUS D2

// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);

float tempSensor1, tempSensor2, tempSensor3;

uint8_t sensor1[8] = { 0x28, 0xFF, 0x10, 0x52, 0x00, 0x16, 0x02, 0x10  };
uint8_t sensor2[8] = { 0x28, 0xFF, 0x1C, 0xA5, 0x00, 0x16, 0x02, 0xC8  };
uint8_t sensor3[8] = { 0x28, 0x61, 0x64, 0x12, 0x3F, 0xFD, 0x80, 0xC6  };

/*Put your SSID & Password*/
const char* ssid = "Dom";  // Enter SSID here
const char* password = "789789";  //Enter Password here

ESP8266WebServer server(80);            

void setup() {
  Serial.begin(115200);
  delay(100);
 
  sensors.begin();             

  Serial.println("Connecting to ");
  Serial.println(ssid);

  //connect to your local wi-fi network
  WiFi.begin(ssid, password);

  //check wi-fi is connected to wi-fi network
  while (WiFi.status() != WL_CONNECTED) {
  delay(1000);
  Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected..!");
  Serial.print("Got IP: ");  Serial.println(WiFi.localIP());

  server.on("/", handle_OnConnect);
  server.onNotFound(handle_NotFound);

  server.begin();
  Serial.println("HTTP server started");
}
void loop() {
  server.handleClient();
}

void handle_OnConnect() {
  sensors.requestTemperatures();
  tempSensor1 = sensors.getTempC(sensor1); // Gets the values of the temperature
  tempSensor2 = sensors.getTempC(sensor2); // Gets the values of the temperature
  tempSensor3 = sensors.getTempC(sensor3); // Gets the values of the temperature
  server.send(200, "text/html", SendHTML(tempSensor1,tempSensor2,tempSensor3));
}

void handle_NotFound(){
  server.send(404, "text/plain", "Not found");
}

String SendHTML(float tempSensor1,float tempSensor2,float tempSensor3){
  String ptr = "<!DOCTYPE html> <html>\n";
  ptr +="<head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, user-scalable=no\">\n";
  ptr +="<title>ESP8266 Temperature Monitor</title>\n";
  ptr +="<style>html { font-family: Helvetica; display: inline-block; margin: 0px auto; text-align: center;}\n";
  ptr +="body{margin-top: 50px;} h1 {color: #444444;margin: 50px auto 30px;}\n";
  ptr +="p {font-size: 24px;color: #444444;margin-bottom: 10px;}\n";
  ptr +="</style>\n";
  ptr +="</head>\n";
  ptr +="<body>\n";
  ptr +="<div id=\"webpage\">\n";
  ptr +="<h1>ESP8266 Temperature Monitor</h1>\n";
  ptr +="<p>Living Room: ";
  ptr +=tempSensor1;
  ptr +="&deg;C</p>";
  ptr +="<p>Bedroom: ";
  ptr +=tempSensor2;
  ptr +="&deg;C</p>";
  ptr +="<p>Kitchen: ";
  ptr +=tempSensor3;
  ptr +="&deg;C</p>";
  ptr +="</div>\n";
  ptr +="</body>\n";
  ptr +="</html>\n";
  return ptr;
}
 
Odpowiedź
#2
Przecież parę dni temu wrzuciłeś tu kod, tylko nie umiałeś obsłużyć interwału czasu, cofnąłeś się w tamtym projekcie?
Miło być decenianym https://buycoffee.to/kaczakat
 
Odpowiedź
#3
Tak masz rację cofnołrm się w projekcie bo próbuje zrozumieć co robię źle
 
Odpowiedź
#4
Jak co robisz źle? TY nic nie robisz. Zarżnąłeś gotowy jakiś projekt i myślisz że ktoś przerobi...
Arduino zostało wymyślone po to, by robić dobrze jedną prostą rzecz – migać diodą. 
 
Odpowiedź
#5
(16-10-2021, 10:08)Jarewa0606 napisał(a): Jak co robisz źle? TY nic nie robisz. Zarżnąłeś gotowy jakiś projekt i myślisz że ktoś przerobi...

Wydawało mi się, że nauka powinna polegać na uczeniu się z gotowych projektów również.

Czy mnie coś ominęło i Arduino jest tylko dla "specjalistów"?
 
Odpowiedź
#6
No właśnie "UCZENIU"

https://forum.arduinopolska.pl/watek-dod...-co-30-min

Jakoś widać nie ma ochoty się uczyć mimo że dostał bardzo dobrą odpowiedź...
Arduino zostało wymyślone po to, by robić dobrze jedną prostą rzecz – migać diodą. 
 
Odpowiedź
  


Skocz do:


Przeglądający: 1 gości