BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

ESP8266 with LCD, ESP8266 with DHT

Hi i using two ESP8266. One for show data from DHT sensor on LCD and another ESP8266 with DHT sensor.

But i need includ to my sketch sending data to Blynk… But i dont know how:( This sketch no sending data to Blynk…

THanks.

#define BLYNK_DEBUG
#define BLYNK_PRINT Serial    

#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <WiFiUDP.h>

#include <SPI.h>
#include <Wire.h>


#include <BlynkSimpleEsp8266.h> // blynk
#include <SimpleTimer.h> // blynk

#include <DHT.h>
#include <EEPROM.h>
#include <WifiConfig.h>
#include <interval.h>
#include <espnbns.h>

#define DHTTYPE DHT22
#define DHTPIN  2//pin D5
#define FORCE_CONFIG_BUTTON_PIN 3 // pin pro tlacitko na vynucenou rekonfiguraci (RXD)





char auth[] = "75a3e91cbdf1457eea63e9c1";

SimpleTimer timer;
// Definice obsazeni EEPROM
#define elementSize(type, element) sizeof(((type *)0)->element)
typedef struct
{
  wificonfigarea_t wc; // oblast, vyhrazena pro konfiguraci WiFi
  char apiKey[33]; // retezec, obsahujici APIKEY pro ThingSpeak
  char server[65]; // retezec, obsahujici adresu Thingspeak serveru
  char field[65]; // jmeno datapointu, do ktereho je ukladana teplota
  char periode[32]; // perioda ukladani dat [s]
}eepromdata;

WifiConfig wifi; // konfigurace ESP modulu
NBNS nbns;

ESP8266WebServer wwwserver(80); // webovy server
 
// Initialize DHT sensor 
DHT dht(DHTPIN, DHTTYPE, 11); // posledni parametr je k nicemu (uz se nepouziva) - Adafruit upravil knihovnu na autokalibraci rychlosti
 
float humidity, temp_f;  // Values read from sensor

Interval measurement; // interval mezi jednotlivymi merenimi
String nbnsname;
WiFiUDP udp;
// Multicast declarations
IPAddress ipMulti(255, 255, 255, 255);
unsigned int portMulti = 5566;      // local port to listen on

void wcb(wificonfigstate_t state)
{
  switch (state)
  {
  case WCS_CONNECTSTART:
    Serial.println("Starting connect...");
  break;
  
  case WCS_CONNECTING:
  break;
  
  case WCS_CONFIGSTART:
    Serial.println("Starting config...");
  break;
  
  case WCS_CONFIGWAIT:
  break;
  }
}

void setup(void)
{

Serial.begin(9600); // See the connection status in Serial Monitor // blynk
   Blynk.begin(auth, "ASUS", "Jersin72"); //insert here your SSID and password
 
  // Setup a function to be called every second
  timer.setInterval(20000L, sendUptime);



 

  EEPROM.begin(512); // zahajujeme praci s EEPROM
  pinMode(FORCE_CONFIG_BUTTON_PIN, INPUT_PULLUP); // RXD slouzi jako vstup tlacitka
  delay(10);
  int force = digitalRead(FORCE_CONFIG_BUTTON_PIN);
  Serial.begin(9600);
  wifi.begin(offsetof(eepromdata, wc), force, wcb); // startujeme pripojeni 

  Serial.println(getOurIP());
  
  dht.begin(); // inicializujeme senzor

  while (! udp.begin(portMulti))
  {
    Serial.print("+");
    yield();
  }
 
  nbnsname = getEEPROMString(offsetof(wificonfigarea_t, devname), elementSize(wificonfigarea_t, devname));
  if (nbnsname.length() > 0)
  {
    nbns.begin(nbnsname.c_str());
  } 
}
 
void loop(void)
{


  nbns.poll();
  gettemperature();

  Blynk.run();
  timer.run();
} 
 
void gettemperature()
{

  if (measurement.expired())
  {
//    udp.flush();
    // Reading temperature for humidity takes about 250 milliseconds!
    // Sensor readings may also be up to 2 seconds 'old' (it's a very slow sensor)
    for (int i=0; i < 5; i++)
    {
      yield();
      humidity = dht.readHumidity();          // Read humidity (percent)
      if (!isnan(humidity))
        break;
    }
//    humidity = dht.readHumidity();          // Read humidity (percent)
    for (int i=0; i < 5; i++)
    {
      yield();
      temp_f = dht.readTemperature(false);
      if (!isnan(temp_f))
        break;
    }
//    temp_f = dht.readTemperature(false);     // Read temperature as Celsius
    // Check if any reads failed and exit early (to try again).
    if (isnan(humidity) || isnan(temp_f))
    {
      if (isnan(humidity))
        Serial.println("Failed to read humidity from DHT sensor!");
      if (isnan(temp_f))
        Serial.println("Failed to read temperature from DHT sensor!");
    }
	  else
	  {
		  String result;
		  result = ":7777;";
		  result += temp_f;
		  result += ";";
		  result += humidity;
		  result += ";";
		  udp.beginPacketMulticast(ipMulti, portMulti, getOurIP());
		  udp.print(result);
		  udp.endPacket();
      Serial.println("Data sent...");
	  }
    measurement.set(6000); // nastavime novy interval mereni
//    measurement.set(2 * dht.getMinimumSamplingPeriod()); // nastavime novy interval mereni
  }
}
// EOF



void sendUptime()   // blynk
{



  float h = dht.readHumidity();
  float t = dht.readTemperature();
  
  Blynk.virtualWrite(4, t); // virtual pin 
  Blynk.virtualWrite(5, h); // virtual pin 


  
}



@Jiri_Bam what is nbns.poll() and why is it in the loop()?

Most Blynk sketches should have 2 lines of code in the loop() as detailed at Blynk for Beginners and help with your project and elsewhere.

I dnot know. This sketch did my friend. I think it is something for sending data to two ESP…

Do you really need 2 ESP’s, surely most ESP’s (except the limited 01) has enough pins for an LCD and a DHT?

Sketch looks to be more complicated than it needs to be unless I am missing something.

I need it if i want have ESP with DHT in other room than ESP with LCD…

Here is all sketch: https://ulozto.cz/!3qtxv0CHvLlg/2-esp-info-panel-dht-sensor-rar

nbns.poll () Secure Call service NBNS services.

what is the issue? what is serial log says? i had issue with dht11 too maybe its similiar

A post was split to a new topic: Need help programming air pollution sensor