computer
Programowanie Mikroprocesory Mikrokontrolery Last.fmProgramowanie Mikroprocesory Mikrokontrolery FacebookTwitter

Valid XHTML 1.0 Transitional

Poprawny CSS!

Programowanie mikrokontrolerów

Uruchomienie serwera www na Wifi ESP8266

s

 

//********************************************** #include "DHT.h" #include #include #define DHTPIN 4 // what pin we're connected to #define DHTTYPE DHT22 // DHT 22 (AM2302) #define SERIAL Serial DHT dht(DHTPIN, DHTTYPE); float temp_hum_val[2] = {0}; float temp,hum; // Replace with your network credentials const char* ssid = "TendaPit"; const char* password = "xxx"; // Set web server port number to 80 WiFiServer server(80); // Variable to store the HTTP request String header; // REPLACE with your Domain name and URL path or IP address with path const char* serverName = "http://mikrokontrolery24.pl/Arduino/esp.php"; // Keep this API Key value to be compatible with the PHP code provided in the project page. // If you change the apiKeyValue value, the PHP file /post-esp-data.php also needs to have the same key String apiKeyValue = "tPmAT5Ab3j7F9"; String sensorName = "AM2302"; String sensorLocation = "Sypialnia"; int licznik=0; void setup() { pinMode(LED_BUILTIN, OUTPUT); // Initialize the LED_BUILTIN pin as an output SERIAL.begin(115200); SERIAL.println("DHTxx test!"); Wire.begin(); dht.begin(); // Connect to Wi-Fi network with SSID and password Serial.print("Connecting to "); Serial.println(ssid); // WiFi.mode(WIFI_STA); // server.addAP(ssid, password); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { // if (wifi < 5){ // if (WiFi.status() != WL_CONNECTED) { delay(5000); Serial.print("."); // } else {oled.setCursor(0, 1);oled.print("WIFI Conected!");} } Serial.print(WiFi.localIP()); server.begin(); } // the loop function runs over and over again forever void loop() { www_request(); sql_sypialnia(); sql_aktualne(); if(!dht.readTempAndHumidity(temp_hum_val)){ SERIAL.print("Humidity: "); SERIAL.print(hum); SERIAL.print(" %\t"); SERIAL.print("Temperature: "); SERIAL.print(temp); SERIAL.println(" *C"); } else{ SERIAL.println("Failed to get temprature and humidity value."); } delay(50); } void www_request (void) { WiFiClient client = server.available(); // Listen for incoming clients if (client) { // If a new client connects, Serial.println("New Client."); // print a message out in the serial port String currentLine = ""; // make a String to hold incoming data from the client while (client.connected()) { // loop while the client's connected if (client.available()) { // if there's bytes to read from the client, char c = client.read(); // read a byte, then Serial.write(c); // print it out the serial monitor header += c; if (c == '\n') { // if the byte is a newline character // if the current line is blank, you got two newline characters in a row. // that's the end of the client 5, so send a response: if (currentLine.length() == 0) { // HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK) // and a content-type so the client knows what's coming, then a blank line: // if (header.indexOf("GET /html") >= 0) { client.println("HTTP/1.1 200 OK"); client.println("Content-type:text/html"); client.println("Connection: close"); client.println(); int index; Serial.print(header); //**************************************************************************** // turns the GPIOs on and off if (header.indexOf("GET /5/on") >= 0) { Serial.println("GPIO 5 on"); } else if (header.indexOf("GET /5/off") >= 0) { Serial.println("GPIO 5 off"); } else { Serial.print ("Nieznane zapytanie"); } //************************************************************************ //*********************************************

s

s

s

s

 


23-Mar-2020 21:35:39 CET
by Pioter




Wszelkie prawa zastrzeżone! Kopiowanie, powielanie i wykorzystywanie zdjęć, treści oraz jej fragmentów bez zgody autora zabronione.
© mikroprocesory.info.pl@gmail.com 2013.