Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By theonlytruth
#57701 Hey,

I use a NodeMCU from LoLin with the Arduino IDE (1.6.5 with ESP8266 2.3.0). I build a kind of little weather station witch sends its informations to a server. This works quite well.

The NodeMCU connects to my Wifi without problems. Additionally it opens op another Wifi called "ESP_D60005". This one is open and unsecured but I don't know what I can do with it. Does anybody knows this Wifi and how to use and configure it?

You can find my code on the bottom. Maybe it results of something in there :roll:

Thanks.
Carsten

Code: Select all#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
const char* ssid = "***";
const char* password = "***";

#include "DHT.h"
#define DHTPIN D4     // what digital pin we're connected to
#define DHTTYPE DHT22   // DHT 22  (AM2302), AM2321
DHT dht(DHTPIN, DHTTYPE);

const int led = 0;

 
// Define website settings
#define WEBSITE  "***"  // Domainname
#define WEBPAGE  "***"            // URL + Name der Datei die aufgerufen werden soll
#define privateKey "***"                                  // Dieser Key steht als sha1 hash in der insertValues.php
uint32_t ip;               // IP Adresse des Servers wird im setup() mit getHostByName aus der URL ermittelt

WiFiClient client;
 
long previousMillis = 0;
long interval = 0.5;         // Upload-Interval in Minuten
float h;                       // Luftfeuchte
float t;                       // Temperatur
 
                     

                                         
void setup(void)
{

  pinMode(led, OUTPUT);
  digitalWrite(led, 0);
  Serial.begin(115200);
  Serial.println("WiFi Wetter-Station (Node-MCU)\n");
  dht.begin();
  WiFi.begin(ssid, password);
  Serial.println("Warte auf Verbindung\n");

  // Wait for connection
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.print("Verbunden mit ");
  Serial.println(ssid);
  Serial.print("IP-Adresse: ");
  Serial.println(WiFi.localIP());
  if (MDNS.begin("esp8266")) {
    Serial.println("MDNS responder started");
  }
 
  interval = interval * 1000 * 60; // Das in Minuten angegebene Interval in Millisekunden umrechnen
}
 
 
 
void loop(void)
{
  unsigned long currentMillis = millis();
 
  if(currentMillis - previousMillis > interval) {
    previousMillis = currentMillis;   
     
    // Temperatur und Luftfeuchte ermitteln
    h = dht.readHumidity();
    t = dht.readTemperature();

      // Check if any reads failed and exit early (to try again).
    if (isnan(h) || isnan(t)) {
      Serial.println("Failed to read from DHT sensor!");
      return;
    }
   
    // Messwerte ausgeben
    Serial.print(F("Temperatur:  "));
    Serial.println(t);
    Serial.print(F("Luftfeuchte: "));
    Serial.println(h);
    Serial.println("");
 
    //Werte des DHT22 an Website senden
    send_request(t, h);
  }
 delay(2000);
}



/**************************************************************************
    Messwerte an Server senden und Antwort des Servers ausgeben
/**************************************************************************/
void send_request (float t, float h)
{     
    Serial.println("\nVerbinde mit Server...");
    // if you get a connection, report back via serial:
    if (client.connect(WEBSITE, 80)) {
    //if (client.connect("de.wikipedia.org", 80)) {
    Serial.println("Erfolgreich verbunden.");

    char buffer[10];
    String SendString = "GET " + String(WEBPAGE) + "?private_key=" + String(privateKey) + "&temp=" + dtostrf(t, 4, 1, buffer) + "&hum=" + dtostrf(h, 4, 1, buffer) + " HTTP/1.1";
    Serial.println(SendString);
    client.println(SendString);
    SendString = "Host: " + String(WEBSITE);
    Serial.println(SendString);
    client.println(SendString);
    client.println("Connection: close");
    client.println();
         
     }
    else {
      Serial.println("Verbindung fehlgeschlagen");
    }
  // Antwort vom Server ausgeben
  while (client.connected()) {
    while (client.available()) {
      char c = client.read();
      Serial.print(c);
    }

    // Verbindung zum Server schließen
    client.stop();
    if (!client.connected())
      {
      Serial.println("Verbindung geschlossen");
      Serial.println();
      }
  }
}