Wifi + OLED + serial + HTTP GET

Vyčte hodntoy z webu a zobrazí na OLED displeji:

 

/*
  2017_10_17
  Author: Makerbro + mhr2017
  Platforms: ESP8266
  Language: C++
  File: HelloOLED.ino
  ------------------------------------------------------------------------
  Description: 
  Demo for OLED display showcasing writing text to the screen.
  ------------------------------------------------------------------------
  Please consider buying products from ACROBOTIC to help fund future
  Open-Source projects like this! We'll always put our best effort in every
  project, and release all our design files and code for you to use. 
  https://acrobotic.com/
  ------------------------------------------------------------------------
  License:
  Released under the MIT license. Please check LICENSE.txt for more
  information.  All text above must be included in any redistribution. 
*/
#include <Wire.h>
#include <ACROBOTIC_SSD1306.h>
#include <ESP8266WiFi.h>

const char* ssid     = "Brno4";
const char* password = "Zakosteli63";

const char* host = "hruby-foto.cz";

void setup()
{
  Wire.begin();  
  oled.init();                      // Initialze SSD1306 OLED display
  oled.clearDisplay();              // Clear screen 

  Serial.begin(115200);             // Start 
      Serial.println();
      Serial.println();
      Serial.print("Connecting to ");
      Serial.println(ssid);

  oled.setTextXY(1,0);              // Set cursor position, start of line 1
  oled.putString("Wi-Fi:");
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
     delay(500);
       oled.putString(".");
       Serial.print(".");
  }


  oled.setTextXY(4,0);              // Set cursor position, start of line 4
  oled.putString("PRIPOJENO");
  Serial.println("WiFi PRIPOJENO");  
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
      
}

void loop()
{

      delay(3000);                      // pockat 3 vteriny
      oled.clearDisplay();              // Clear screen  

      // Use WiFiClient class to create TCP connections
      WiFiClient client;
      const int httpPort = 80;
      if (!client.connect(host, httpPort)) {
        oled.setTextXY(1,0);
        oled.putString("Connection HTTP failed");
        Serial.println("Connection HTTP failed");
        return;
      }

      // We now create a URI for the request
      String url = "/saliny/saliny.php";
      Serial.print("Requesting URL: ");
      Serial.println(url);

      // This will send the request to the server
      client.print(String("GET ") + url + " HTTP/1.1\r\n" +
                   "Host: " + host + "\r\n" + 
                   "Connection: close\r\n\r\n");
      delay(10);
      oled.clearDisplay();              // Clear screen  

      // Read all the lines of the reply from server and print them to Serial
      int radek = 0;
      while(client.available()){
        
        String line = client.readStringUntil('\r');
        radek++;
        Serial.print(line);
        if (radek==11){
            oled.setTextXY(1,0);
            line.trim();
            oled.putString(line);
          }
        if (radek==12){
            oled.setTextXY(2,0);
            line.trim();
            oled.putString(line);
          }  
        if (radek==13){
             oled.setTextXY(3,0);
            line.trim();
            oled.putString(line);
          } 
        if (radek==14){
             oled.setTextXY(4,0);
            line.trim();
            oled.putString(line);
          }

        //delay(1000);
      }
      
      Serial.println();
      Serial.println("closing connection");
      Serial.print("-----------------------\r\n");



      
  
}

 

Napsat komentář