The Sensor data from the nodemcu is not updating to blynk

I have managed to get the first initial values updated to the dashboard, but after the first update the dashboard values seems not to update. Any reasons? Any suggested changes to the code?



// Fill-in information from your Blynk Template here
#define BLYNK_TEMPLATE_ID "TMPL3CkIZFISg"
#define BLYNK_TEMPLATE_NAME "AGUA"
#define BLYNK_FIRMWARE_VERSION        "0.1.0"

#define BLYNK_PRINT Serial
//#define BLYNK_DEBUG

#define APP_DEBUG

// Uncomment your board, or configure a custom board in Settings.h
//#define USE_SPARKFUN_BLYNK_BOARD
//#define USE_NODE_MCU_BOARD
//#define USE_WITTY_CLOUD_BOARD
//#define USE_WEMOS_D1_MINI

#include "BlynkEdgent.h"
#include "DHT.h"
#define DHTPIN 4 
#define DHTTYPE DHT11

DHT dht(DHTPIN, DHTTYPE);
int t, h, s;

BLYNK_WRITE(V0)
{
  if(param.asInt()==1){
    digitalWrite(2, HIGH);
  }
  else{
    digitalWrite(2, LOW);
  }
}

BLYNK_CONNECTED()
{
  Blynk.syncVirtual(V0);
  Blynk.virtualWrite(V3, s);  
  Blynk.virtualWrite(V1, h);
  Blynk.virtualWrite(V2, t);
}

void setup()
{
  pinMode(2, OUTPUT); // Initialise digital pin 2 as an output pin
  Serial.begin(115200);
  dht.begin();
  delay(2000);

  BlynkEdgent.begin();
}

void loop() {
  s= ( 100.00 - ( (analogRead(A0)/1023.00) * 100.00 ) );
  h = dht.readHumidity();
  t = dht.readTemperature(); 
  Serial.print("soil= ");
  Serial.println(s);
  Serial.println("temp= ");
  Serial.println(t);
  Serial.println("hum= ");
  Serial.println(h);
delay(2000);
  BlynkEdgent.run();
}

Two things…

  1. You’ve not un-commented a board type, so the default settings will be used. This may be conflicting with the pins you are using. You should check your Settings.h file.
    More info here…
  1. You have a cluttered void loop and are using delays instead of BlynkTimer.
    You should read this…

But note that when using Edgent you need just BlynkEdgent.run(); and timer.run(); in your void loop, not Blynk.run();

Pete.

1 Like

hay…, Thanks for looking into my problem Pete

Well after you mentioned it I tried to update the code
Updated code

// Fill-in information from your Blynk Template here

#define BLYNK_TEMPLATE_ID "TMPL3CkIZFISg"

#define BLYNK_TEMPLATE_NAME "AGUA"

#define BLYNK_FIRMWARE_VERSION        "0.1.0"

#define BLYNK_PRINT Serial

//#define BLYNK_DEBUG

#define APP_DEBUG

// Uncomment your board, or configure a custom board in Settings.h

//#define USE_SPARKFUN_BLYNK_BOARD

#define USE_NODE_MCU_BOARD

//#define USE_WITTY_CLOUD_BOARD

//#define USE_WEMOS_D1_MINI

#include "BlynkEdgent.h"

#include "DHT.h"

#define DHTPIN 4

#define DHTTYPE DHT11

DHT dht(DHTPIN, DHTTYPE);

int t, h, s;

BlynkTimer timer; // Announcing the timer

BLYNK_WRITE(V0)

{

 if(param.asInt()==1){

   digitalWrite(2, HIGH);

 }

 else{

   digitalWrite(2, LOW);

 }

}

void sendSensor()

{

 s= ( 100.00 - ( (analogRead(A0)/1023.00) * 100.00 ) );

 h = dht.readHumidity();

 t = dht.readTemperature();  

 Blynk.virtualWrite(V1, h);

 Blynk.virtualWrite(V2, t);

 Blynk.virtualWrite(V3, s);

}

BLYNK_CONNECTED()

{

 Blynk.syncVirtual(V0);

}

void setup()

{

 pinMode(2, OUTPUT); // Initialise digital pin 2 as an output pin

 Serial.begin(115200);

 dht.begin();

 delay(2000);

 BlynkEdgent.begin();

 timer.setInterval(1000L, sendSensor);

}

void loop()

{

 BlynkEdgent.run();

 timer.run(); // Initiates SimpleTimer

}

But now its flicking the relay connected to virtual pin 0 (v0),
Any Ideas please.

Thanks for your time.

Did you actually read the link I provided about Edgent provisioning?

And reading your DHT sensor once every second won’t produce the type results you’re looking for, these sensors are very slow.

Pete.