I have problems understanding the synching mechanism

Hello,

I need to write a value from my app to a Node MCU on startup. I am using blynk.syncVirtual as described in the manual. I also tried blynk.syncAll, but to no avail. I am most likely doing something wrong…

#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#define MINUTE 60
#include <ESP8266WiFi.h>
#include <max6675.h>
#include <SimpleTimer.h>

#include <BlynkSimpleEsp8266.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] ="xxxxxxxx";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "xxxxxxxxx";
char pass[] = "xxxxxxxxx";

int ktcSO = 12;
int ktcCS = 13;
int ktcCLK = 14;

int NumberOfMinutes;
 
MAX6675 ktc(ktcCLK, ktcCS, ktcSO);

//SimpleTimer TempTimer;

BLYNK_CONNECTED() {
  // Request Blynk server to re-send latest values for all pins
  Blynk.syncVirtual(V1);

  Serial.println("In sync routine");
}

BLYNK_WRITE(V1)
{
  NumberOfMinutes = param.asInt(); // assigning incoming value from pin V1 to a variable

  Serial.print("V1 Slider value is: ");
  Serial.println(NumberOfMinutes);
}

void StuurTemperatuur()
{
  float DC = ktc.readCelsius();
  Blynk.virtualWrite(V5,DC);
}

void StuurBatterijLevel()
{
  int vcc = ESP.getVcc();
  Blynk.virtualWrite(V6, vcc);
  
  Serial.print("Battery level...: ");
  Serial.println(vcc);
  Serial.print("Sleeptime...: ");
  Serial.println(NumberOfMinutes);
  delay(100);
   ESP.deepSleep(MINUTE * 1000000);
}

void setup()
{
  Serial.begin(9600);
 
  Blynk.begin(auth, ssid, pass);
  while (Blynk.connect() == false) {
     //wait until connected
  }
  
  StuurTemperatuur(); // send temperature
  StuurBatterijLevel(); // send battery level

  
}

void loop()
{
  Blynk.run();

}

When I start the serial monitor, I see following, hence concluding that the value from the value from the virtual pin is not copied. The other thing I noticed is that apparently the Blynk_connected routine is called twice.

[17365] Connecting to Sitecom0E4486
[18867] Connected to WiFi
[18867] IP: 192.168.1.113
[18868] 
    ___  __          __
   / _ )/ /_ _____  / /__
  / _  / / // / _ \/  '_/
 /____/_/\_, /_//_/_/\_\
        /___/ v0.4.6 on NodeMCU

[18941] Connecting to blynk-cloud.com:8442
[19257] Ready (ping: 2ms).
In sync routine
[24258] Connecting to blynk-cloud.com:8442
[24327] Ready (ping: 3ms).
In sync routine
Battery level...: 65535
Sleeptime...: 0

Some additional information:

  • iOS app
  • Arduini 1.8.2

Any suggestions would be greatly appreciated. Thanks.
PS: Battery level is not exctly working either, but that’s not my main issue.

Solved: upgrading to the newest Blynk library did the trick

1 Like

Make sure to mark as solved :slight_smile:

Thanks for the reminder, I was looking for this option…

No worries, I did it for you.