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

[SOLVED] Blynk and Esp8266 Ds18b20

Ещо вчера он работал а щас нет в чем может бить проблема

#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <OneWire.h>
#include <DallasTemperature.h>

#define ONE_WIRE_BUS 0
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature DS18B20(&oneWire);

float oldTemp;
char auth[] = "cb9e0b23ca35429882f6a6658713174e";
void setup()
{
Serial.begin(9600);
Blynk.begin(auth, "Tp-link", "Ms0606400");
while (Blynk.connect() == false) {
}
Blynk.notify("Device started !");
}
void loop()
{
float temp;
do
{
DS18B20.requestTemperatures();
temp = DS18B20.getTempCByIndex(0);
Serial.print("Temperature: ");
Serial.println(temp);
}
while (temp == 85.0 || temp == (-127.0));
Blynk.virtualWrite(1, temp);
Blynk.run();

}

Hello. It is not recommended to call virtualWrite within loop. Better use widget with frequency reading like this :

 BLYNK_READ(V1) {
      Blynk.virtualWrite(V1, temp);
 }

Or use timer

Here’s an example of mine:

#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <TimeLib.h>
#include <SimpleTimer.h>
#define ONE_WIRE_BUS 0

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

char auth[] = "fromBlynkApp";

SimpleTimer timer;

void setup()
{
  Serial.begin(9600);
  Blynk.begin(auth, "ssid", "password");

  sensors.begin();

  timer.setInterval(5000L, sendTemps); // Temperature sensor polling interval (5000L = 5 seconds)
}

void sendTemps()
{
  sensors.requestTemperatures(); // Polls the sensors

  float tempBabyRoom = sensors.getTempFByIndex(0); // Gets first probe on wire in lieu of by address

  Blynk.virtualWrite(4, tempBabyRoom);
}

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

// Temperature sensor polling interval (5000L = 5 seconds) - Ето интервал обновления Ds18b50? а уменшал интервал нице не меняется

Он заработал но я так понял фаренгей переделать на цельсий реально?

Google Translate is only helping me so much but if I understand…

This will give you the temperature in Celsius: float yourVariable = sensors.getTempCByIndex(0); Just replacing the F with a C.

спасибо помог работает

@Dmitriy,

So I get my code right, I assume the strategy for handling the logic in our program is to have a number of small functions, as short as possible, to handle different events in the program so that there are as many opportunities for Blynk functions to run in between our events as possible. If, instead, these logic functions are in loop(), Blynk is locked out and errors like timeouts etc. can occur.

If there are any other hints for ensuring constant Blink connectivity, please let me know. Thanks.

RD7

@Rom3oDelta7 yes AFAIK your assumptions are correct.

If you haven’t already done so you can also look at the Connection Management section of the online docs at http://docs.blynk.cc/#blynk-firmware-connection-management

There are some nice pointers regarding checking for connection and reconnecting etc. Most of it is automatic with Blynk.run() but some features can be tweaked.

Do you have Serial Monitor running with your device and if so what sort of issues does it highlight?

Thanks, @Costas. The error messages sent me off in the wrong direction. I took a step back and looked at the code flow again and I solved it this evening. Just about to write a post with my observations.

Cheers,
RD7

1 Like

при попытке скомпилировать и прошить вылазиет вот такой лог:
C:\xxx\libraries\Blynk\examples\BoardsAndShields\ESP8266_Standalone\ESP8266_Standalone.ino:6:21: fatal error: TimeLib.h: No such file or directory

#include <TimeLib.h>

                 ^

compilation terminated.

exit status 1
Ошибка компиляции для платы NodeMCU 0.9 (ESP-12 Module).
Помогите пожалуйста разобраться

You have to install the library according to the guide: https://github.com/blynkkk/blynk-library/releases/latest

The Blynk_v0.3.7.zip package contains several libraries.
You need to copy them manually to your libraries folder.

I did as you said …
but the same problem