Getting nulls in between value

Hi ,
I am using the Edgent example and modified it step by step.
I am beyond the stage where I use the LED On/Off and a Voltage reading in an analog Input, with success.
The current function, ultrasonic range finder, worked on the the ESP standalone. The combination with the Blynk.virtualWrite(V3,distance) causes to read 3 values at the same time (loop), twice nulls and one correct value, right after the Cloud procedure. Before the registration it seems that the loops are correct handled.
I even played with the “timer.setInterval(500L,SensorValue);” values.

Any ideas are much appreciated

Before the registration,
17:01:41.717 → duration is the ECHO high :1180
17:01:41.717 → Centimeter calculated:20
17:01:41.717 → This loop: 2
17:01:42.219 → duration is the ECHO high :1181
17:01:42.219 → Centimeter calculated:20
17:01:42.219 → This loop: 3
17:01:42.736 → duration is the ECHO high :1179
17:01:42.736 → Centimeter calculated:20
17:01:42.736 → This loop: 4

After the registration
17:02:12.019 → [32315] Connecting to blynk.cloud:443
17:02:14.380 → duration is the ECHO high :102522
17:02:14.380 → Centimeter calculated:1742
17:02:14.380 → This loop: 30
17:02:14.380 → [34694] Ready (ping: 249ms).
17:02:15.281 → duration is the ECHO high :101336
17:02:15.281 → Centimeter calculated:1722
17:02:15.281 → This loop: 31
17:02:15.281 → [35592] CONNECTING_CLOUD => RUNNING
17:02:15.685 → duration is the ECHO high :1181
17:02:15.685 → Centimeter calculated:20
17:02:15.685 → This loop: 32
17:02:15.933 → duration is the ECHO high :1207
17:02:15.986 → Centimeter calculated:20
17:02:15.986 → This loop: 33
17:02:17.443 → duration is the ECHO high :0
17:02:17.443 → Centimeter calculated:0
17:02:17.443 → This loop: 34
17:02:18.641 → duration is the ECHO high :0
17:02:18.641 → Centimeter calculated:0
17:02:18.641 → This loop: 35
17:02:19.879 → duration is the ECHO high :0
17:02:19.879 → Centimeter calculated:0
17:02:19.879 → This loop: 36
17:02:20.238 → duration is the ECHO high :122600
17:02:20.238 → Centimeter calculated:2084
17:02:20.238 → This loop: 37

//--------------- The Code ---------------------------------------------------
// Mostly wripped of from Example

// Fill-in information from your Blynk Template here
#define BLYNK_TEMPLATE_ID "TMPLRwKDdSO8"
#define BLYNK_DEVICE_NAME "FromYoutube"
#define BLYNK_FIRMWARE_VERSION        "0.1.0"
#define BLYNK_PRINT Serial
//#define BLYNK_DEBUG
#define APP_DEBUG
#define USE_NODE_MCU_BOARD
#include "BlynkEdgent.h"

// Editors Code inputs
#define TRIGGER 13 // NodeMCU Pin D7
#define ECHO    14 // NodeMCU Pin D5

int CounterIn = 0;
int CounterOut = 0;

// below from https://docs.blynk.io/en/getting-started/using-virtual-pins-to-control-physical-devices
BLYNK_WRITE(V0) // Executes when the value of virtual pin 0 changes
{
  if(param.asInt() == 1)
  {
    // execute this code if the switch widget is now ON
    digitalWrite(4,HIGH);  // Set digital pin 2 HIGH
    Serial.println("Set digital pin D2 HIGH");
  }
  else
  {
    // execute this code if the switch widget is now OFF
    digitalWrite(4,LOW);  // Set digital pin 2 LOW
    Serial.println("Set digital pin D2 LOW");    
  }
}

// Function that does the Sensing
void SensorValue(){
  long duration;
  int distance;
  
  digitalWrite(TRIGGER, LOW);  
  delayMicroseconds(5); 

  // Trigger the sensor by setting the trigPin high for 10 microseconds:
  digitalWrite(TRIGGER, HIGH);
  delayMicroseconds(10); 
  digitalWrite(TRIGGER, LOW);
  
  // Read the echoPin. pulseIn() returns the duration (length of the pulse) in microseconds:
   duration = pulseIn(ECHO, HIGH);
  
  // Calculate the distance:
  distance = duration*0.034/2;
  //distance = (duration/2) / 29.1;

  Blynk.virtualWrite(V3,distance); // sends the "distance" value to virtualPin V3

  // Print the distance on the Serial Monitor (Ctrl+Shift+M):
 
  Serial.print("duration is the ECHO high :");
  Serial.println(duration);
  
  Serial.print("Centimeter calculated:");
  Serial.println(distance);
  
  Serial.print("This loop: ");
  Serial.println(CounterIn);
  CounterIn=CounterIn+1;
  
}

void setup()
{
  Serial.print("CounterOut ");
  Serial.println(CounterOut);
  CounterOut=CounterOut+1;
  pinMode(TRIGGER, OUTPUT);
  pinMode(ECHO, INPUT);

  pinMode(4,OUTPUT);  // Led Output switch
  Serial.begin(115200);
  BlynkEdgent.begin();
  timer.setInterval(500L,SensorValue); // Call function <void SensorValue> every 1000 milliseconds SensorValue
  
}


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





  
-----------

Hi ,
I got the feeling that it has something to do with the timer.setInterval() and the inner delay() of each function called. Has someone the right figure of this two weights?
appreciate any hints
Y3G

The minimum needed for this sensor is 1000