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

NodeMcu Problem with Blynk.syncAll();

#1

Hi, I have problems with nodemcu, as soon as I enter the Blynk.syncAll () command; the device disconnects and reconnects from the blynk server, but all this does not happen on me always with an identical code, I have tried more than one nodemcu but I always have the same problem someone has had the same problem? Thank you.

Smartphone Android
• Blynk Library version [v0.6.1]
`

#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <DHT.h>
char auth[] = “”;
char ssid[] = “”;
char pass[] = “”;

// Keep this flag not to re-sync on every reconnection
bool isFirstConnect = true;

// This function will run every time Blynk connection is established
BLYNK_CONNECTED() {
if (isFirstConnect) {
// Request Blynk server to re-send latest values for all pins
Blynk.syncAll();}}

#define DHTPIN 0
#define DHTTYPE DHT11 // DHT 11
DHT dht(DHTPIN, DHTTYPE);
BlynkTimer timer;
void sendSensor()
{ float h = dht.readHumidity();
float t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit
if (isnan(h) || isnan(t)) {
Serial.println(“Failed to read from DHT sensor!”);
return;}
Blynk.virtualWrite(V5, h);
Blynk.virtualWrite(V6, t);
}

WidgetLED ledingresso(V1);

#define D0 16
#define D1 5 // I2C Bus SCL (clock)
#define D2 4 // I2C Bus SDA (data)
#define D3 0
#define D4 2 // Same as “LED_BUILTIN”, but inverted logic
#define D5 14 // SPI Bus SCK (clock)
#define D6 12 // SPI Bus MISO
#define D7 13 // SPI Bus MOSI
#define D8 15 // SPI Bus SS (CS)
#define D9 3 // RX0 (Serial console)
#define D10 1 // TX0

void setup()
{
Serial.begin(9600);
digitalWrite (D1,LOW);
digitalWrite (D2,LOW);
digitalWrite (D5,LOW);

Blynk.begin(auth, ssid, pass);
dht.begin();
timer.setInterval(1000L, sendSensor);

}

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

0 Likes

#2

Why are you callingBlnk.syncAll?

Pete.

0 Likes

#3

Hi Pete , to synchronize the state of the buttons and widget between app blynk and nodemcu in case of reset or lack of connection

0 Likes

#5

how many widgets do you sync ?

0 Likes

#6

I understand what the command does, I’m just unclear about your motives for calling it.
If you’re doing direct pin manipulation of digital pins by your widgets then it’s not possible to tell from your code what you have set-up in your app and you haven’t shared that info.
You’ve done a mapping of NodeMCU pin numbers to GPIOs (which isn’t necessary by the way) but you haven’t added any comments to this to indicate what you have connected to these digital pins.
You are doing some digitalWrites in your void setup for three digital pins, but then if you’re setting these low, what’s this if you’re then going to sync them?

Maybe you can explain what widgets you have set-up and why you’re wanting to sync the old values back to the NodeMCU at startup?

Pete.

0 Likes