5.4.17

ESP8266 programmieren





Von: https://de.aliexpress.com/store/product/USB-to-ESP8266-Serial-Wireless-Wifi-Module-Developent-Board-8266-Wifi-Module/612195_32729552106.html




ESP8266 programmieren
3.3 V => 3.3V + CH_PD
GND => GND+GPIO0 (neben RX)
RX=> TX
TX=> RX
Zum Ausführen GPIO wieder von GND nehmen.


Von hier 


Interne LED: GPIO16
An:
digitalWrite(2, LOW);




Unter Datei - Voreinstellungen - Boardverwalter URL:
http://arduino.esp8266.com/stable/package_esp8266com_index.json

Werkzeuge - Board - Boardverwalter

 NodeMCU 1.0

Oder mit Wemos D1 mini.

Sketch:
/*
 *  This sketch sends a message to a TCP server
 *
 */

#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>

ESP8266WiFiMulti WiFiMulti;

void setup() {
    Serial.begin(115200);
    delay(10);

    // We start by connecting to a WiFi network
    WiFiMulti.addAP("SSID", "password");

    Serial.println();
    Serial.println();
    Serial.print("Wait for WiFi... ");

    while(WiFiMulti.run() != WL_CONNECTED) {
        Serial.print(".");
        delay(500);
    }

    Serial.println("");
    Serial.println("WiFi connected");
    Serial.println("IP address: ");
    Serial.println(WiFi.localIP());

    delay(500);
}


void loop() {
    const uint16_t port = 80;
    const char * host = "192.168.178.4"; // ip or dns

   
   
    Serial.print("connecting to ");
    Serial.println(host);

    // Use WiFiClient class to create TCP connections
    WiFiClient client;

    if (!client.connect(host, port)) {
        Serial.println("connection failed");
        Serial.println("wait 5 sec...");
        delay(5000);
        return;
    }

    // This will send the request to the server
    client.print("Send this data to server");

    //read back one line from server
    String line = client.readStringUntil('\r');
    client.println(line);

    Serial.println("closing connection");
    client.stop();
   
    Serial.println("wait 5 sec...");
    delay(5000);
}


2.4.17

ESP 8266 DHT11 und Webserver

// SimpleDHT als Library einbinden
// Ggfs. vorher von der URL holen
// http://arduino.esp8266.com/stable/package_esp8266com_index.json
// DHT11
//GND-GND
//VCC - 3.3 V
//Data - Pin/GPIO 2 - D4

#include <SimpleDHT.h>

// Including the ESP8266 WiFi library
#include <ESP8266WiFi.h>

// Replace with your network details
const char* ssid = "SSID";
const char* password = "PASSWORD";

// Web Server on port 80
WiFiServer server(80);

// DHT Sensor
int pinDHT11 = 2;
// Initialize DHT sensor.
SimpleDHT11 dht11;

// Temporary variables
static char celsiusTemp[7];
static char fahrenheitTemp[7];
static char humidityTemp[7];

// only runs once on boot
void setup() {
  // Initializing serial port for debugging purposes
  Serial.begin(115200);
  delay(10);
 
  // Connecting to WiFi network
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);
 
  WiFi.begin(ssid, password);
 
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");
 
  // Starting the web server
  server.begin();
  Serial.println("Web server running. Waiting for the ESP IP...");
  delay(10000);
 
  // Printing the ESP IP address
  Serial.println(WiFi.localIP());
}

// runs over and over again
void loop()
{
  // Listenning for new clients
  WiFiClient client = server.available();
    // read without samples.
  byte temperature = 0;
  byte humidity = 0;
    if (client)
  {
    if (dht11.read(pinDHT11, &temperature, &humidity, NULL))
    {
      Serial.print("Read DHT11 failed.");
      return;
    }
    String remote_ip = client.remoteIP().toString(); // IP Adresse des Client
    
    Serial.println("Neuer Zugriff von : " + remote_ip);
    // bolean to locate when the http request ends
    boolean blank_line = true;
    while (client.connected())
    {
      if (client.available())
      {
        char c = client.read();
                if (c == '\n' && blank_line)
        {
          // Computes temperature values in Celsius + Fahrenheit and Humidity
          // You can delete the following Serial.print's, it's just for debugging purposes
          Serial.print((int)temperature); Serial.print(" *C, ");
          Serial.print((int)humidity); Serial.println(" %");
        }
        client.println("HTTP/1.1 200 OK");
        client.println("Content-Type: text/html");
        client.println("Connection: close");
        client.println();
        // your actual web page that displays temperature and humidity
        client.println("<!DOCTYPE HTML>");
        client.println("<html>");
        client.println("<head></head><body><h1>ESP8266 - Temperature and Humidity</h1><h3>Temperature in Celsius: ");
        client.println((int)temperature);
        client.println("*F</h3><h3>Humidity: ");
        client.println((int)humidity);
        client.println("%</h3><h3>");
        client.println("<hr>" + remote_ip + "<br>");
        client.println("</body></html>");    
        break;
       
        if (c == '\n')
        {
          // when starts reading a new line
          blank_line = true;
        }
        else if (c != '\r')
        {
          // when finds a character on the current line
          blank_line = false;
        }
      }
    } 
    // closing the client connection
    delay(1);
    client.stop();
    Serial.println("Client disconnected.");
    
  }  
  }

Openhab und Ecoflow Max - API Anbindung

 Ich wollte die neu erworbene Powerstation in Openhab einbinden, um den aktuellen Status (Ladestand etc.) über Openhab auswerten zu können. ...