Blynk 2.0 - Getting no data from board

I have several Blynk projects in old Blynk that works, but now i want to convert to new Blynk.

I have installed Blink 1.0 beta 3 library and loaded Blynk Edgent 8266 (i use an Wemos D1 Mini).

Here is my code:

// Fill-in information from your Blynk Template here
#define BLYNK_TEMPLATE_ID "*****"
#define BLYNK_DEVICE_NAME "*****"

#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

#include "BlynkEdgent.h"

#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 14

OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

int relayPin = 15;
int onLED = 12;
int buttonState;


BlynkTimer timer_1;

void setup()
{
  Serial.begin(115200);
  delay(100);
  pinMode(relayPin, OUTPUT);
  pinMode(onLED, OUTPUT);
  timer_1.setInterval(1000L, temp);

  BlynkEdgent.begin();
}

BLYNK_CONNECTED() {
  Blynk.syncAll();
}

void emergencyOFF() {
  Blynk.virtualWrite(V1, LOW);
  digitalWrite(relayPin, LOW);
  digitalWrite(onLED, LOW);
  Blynk.virtualWrite(V3, "SJEKK TEMPERATUR!!");
  Blynk.notify("SJEKK TEMPERATUR!");
}

void temp() {
  sensors.requestTemperatures();
  Serial.print("Temperatur: ");
  Serial.println(sensors.getTempCByIndex(0));
  Blynk.virtualWrite(V2, sensors.getTempCByIndex(0));
  Blynk.virtualWrite(V5, sensors.getTempCByIndex(0));

  if (sensors.getTempCByIndex(0) > 60) {
    emergencyOFF();
  }
  else {
    Blynk.virtualWrite(V3, "  ");
  }
}

BLYNK_WRITE(V1) {
  buttonState = param.asInt();

  if (buttonState == 1) {
    digitalWrite(relayPin, HIGH);
    digitalWrite(onLED, HIGH);
  }
  else {
    digitalWrite(relayPin, LOW);
    digitalWrite(onLED, LOW);
  }
}

void loop() {
  BlynkEdgent.run();
  timer_1.run();
  Blynk.run();
}

Ii make datastream in Blynk Dashboard and refferes to V1 etc. But i just get random temperature readings in Blynk dashboard and the relay switch does not work at all. The temperature value in Blynk Dashboard changes when i reconnect the device.

I have connected my board to the app with success.

Install a non beta version of Blynk.
Remove blynk.run from the void loop.

What is the min and max value set in the data stream ?

So i just install ver. 1.0 (not beta)?

I tried first with just Blynk.edgent() in loop and that did not work either.

For the temperature i set the max min value to 1-100 (double)
For the switch i set 1-0 (integer)

I can se temperature displays, but just random values that changes only when i reconnect the device. The relay switch does not work at all.

Are you looking at the Template view, or the Device view in the web dashboard?
The Template view is designed to show some random data “to help visualise the widgets”, but it confuses the hell out of most people, including me.

A side issue, this code is very badly written. You rake 4 temperature readings every second, rather than taking just one and saving it to a local temporary variable, and using that variable in your serial print, Blynk.virtualWrite and if comparisons…

Pete.

1 Like

I’m in template view under device/Web Dashboard.

The code i have there works fine in old blynk…

That’s your problem, this is dummy random data. You need to be in Device view (the magnifying glass on the left hand side at the top)

I’m sure it does, but it’s still bad practice to take 4 different readings and do different things with them.
If the last one threw-out a -127 error value then you’d wonder why the if statement evaluated as false, yet the serial print data showed a reading that should make it evaluate as true.
Also, most sensors don’t like to be polled too frequently, and you’re polling this 4 times more often than you need to.

Pete.

Ahaa! I will try the device view later today :slight_smile: Thanks :slight_smile:

Ok, i will slow down the temperature reading with timer later today also. Thanks.

I will post an update later on this :slight_smile:

It’s not really about slowing-down the readings, its about taking one reading each time the function is called and using that reading for all the action you then take within that function.

Imagine that you were taking a time reading rather than a temperature reading. The time could change during the course of the execution of the function, so the values would be different at each point.

The same goes for the temperature readings, the sensor may not give the same result each time, so better to read it once at the start of the function the use that same reading elsewhere in the function.

Pete.

I understand.

Can you give me an example how a code like that looks like?

void temp()
 {
  sensors.requestTemperatures();
  float reading =sensors.getTempCByIndex(0);

  Serial.print("Temperatur: ");
  Serial.println(reading );
  Blynk.virtualWrite(V2, reading); 
  Blynk.virtualWrite(V5, reading); 

  if (reading  > 60)
 {
    emergencyOFF();
  }
  else {
    Blynk.virtualWrite(V3, "  ");
  }

[/quote]

Pete.

You had right Pete :slight_smile:

The temp sensor works now.

But the relay does not react when i try to turn it on/off from dashboard… Any ideas?

I tried the code you postet and the temperature reacts now and is right, but i get an “0” sometimes between readings. I changed the temp interval to 2 seconds.

Relay does not work…

How is your V1 datastream configured?

Is your dashboard On/Off switch attached to V1?

Have you tried adding serial print statements to your BLYNK_WRITE(V1) function to see if it is being triggered by the button?

Pete.

On/off switch is set to A1 (integer) with values 1-0.

I have not tried that with serial. Can take a look on it later to day. Thanks :slight_smile:

I assume that means “V1” not A1?

If your minimum is 1 and your maximum is 0 in the datastream then I’d try swapping those around, as logically it doesn’t make sense.

Pete.

I ment V1 yes :slight_smile:

Here is a screenshot.

Here is datastream screenshot.

I also want to know why temperature shows me an “0” sometimes between readings? The temperature is correct though.

All worked fine with old blynk and have worked fine for almost 5 mounts. Suddenly my code is all messed up…?

Have you set-up data invalidation in the advanced datastream settings?

Pete.

I have not anything that says “data invalidation” in advanced settings.


I have now changed to Blynk 1.0 library (Not beta) and deleted other Blynk librarys i had from library folder. No success.

This is the problem i have now:

  1. It shows the right temperature, but i get an “0” from time to time between readings.

  2. The relay does not work at all. But the LED that lights up when relay is on works fine. It’s just the relay. The relay is soldered to pin D8 on my Wemos D1 Mini. (Pin 15 in code)
    PS! Nothing shows up in serial monitor when i turn relay on/off either.

So a non working relay and a temperature that shows “0” between readings is the two problems i have now.

Here is my last code:

// Fill-in information from your Blynk Template here
#define BLYNK_TEMPLATE_ID "*****"
#define BLYNK_DEVICE_NAME "*****"

#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

#include "BlynkEdgent.h"

#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 14

OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

int relayPin = 15;
int onLED = 12;
int buttonState;


BlynkTimer timer_1;

void setup()
{
  Serial.begin(115200);
  delay(100);
  pinMode(relayPin, OUTPUT);
  pinMode(onLED, OUTPUT);
  timer_1.setInterval(2000L, temp);

  BlynkEdgent.begin();
}

BLYNK_CONNECTED() {
  Blynk.syncAll();
}

void emergencyOFF() {
  Blynk.virtualWrite(V1, LOW);
  digitalWrite(relayPin, LOW);
  digitalWrite(onLED, LOW);
}

void temp()
 {
  sensors.requestTemperatures();
  float reading =sensors.getTempCByIndex(0);

  Serial.print("Temperatur: ");
  Serial.println(reading );
  Blynk.virtualWrite(V2, reading);  

  if (reading  > 60)
 {
    emergencyOFF();
  }
  else {
    Blynk.virtualWrite(V3, "  ");
  }
 }

BLYNK_WRITE(V1) {
  buttonState = param.asInt();

  if (buttonState == 1) {
    digitalWrite(relayPin, HIGH);
    digitalWrite(onLED, HIGH);
    Serial.println("Relay OFF");
  }
  else {
    digitalWrite(relayPin, LOW);
    digitalWrite(onLED, LOW);
    Serial.println("Relay ON");
  }
}

void loop() {
  BlynkEdgent.run();
  timer_1.run();
}