Smartphone: device offline - serial output: Login timeout

Hello,
Particle Photon User with WiFi communication with blynk-lib v0.5.4 here, by using Blynk Server (no local one). Sketch running and works fine, but my iPhone/Android-App says “device offline”.
So I debugged with serial printout and got a lot of “Login timeouts”. I changed the auth-token and for the first seconds it works also on the smartphone, but I got “Login timeouts” again in the serial log.

Thx for review,
Ingo


// Ingo Lohs, Version 1.4 - 18.11.2018 - works with Particle Photon v0.7.0
// myled-mosefet-blynk-v2.ino
// https://www.hackster.io/ingo-lohs/mypir-sensor-activate-analog-rgb-stripe-controlled-by-photon-2e8240

#define BLYNK_DEBUG // Optional, this enables lots of prints
#define BLYNK_PRINT Serial

#include <blynk.h>
#include <Adafruit_TSL2561_U.h>

// Change von Version 1.1 > 1.2:
// Änderung der Default-RGB-Werte via zweites Zergba (zusätzliches Blynk-Widget) gebunden an V6, um dynamisch die Default-RGB-Werte abändern zu könnnen ohne erneut den Code flashen zu müssen
// Change von Version 1.2 > 1.3:
// Vorbelegung der Variablen red, green, blue mit der Zuweisung von jew. 255: so ist bei einem Restart der Default für das Licht als "weiss" vorbelegt
// Change von Version 1.3 > 1.4:
// Aufnahme des Lichtsensors TSL2561 inkl. seiner Adafruit-Library - Default-Address is: 0x39
// Firmware-Update von v0.6.3 > v0.7.0
// Änderung der PINs von Control-LED und PIR-Sensor, um SDA und SCL für den TSL2561 verfügbar zu haben
// Sensor overload kommt im Dunkeln und so ist der analogvalue = 1 gesetzt

// Erweiterung: * vorstellbar wäre eine while-Scheife, die solange LED on hat wie auch die PIR-Detektion anhält

// Quelle:  http://diotlabs.daraghbyrne.me/7-communicating-events/pir/
//          https://learn.adafruit.com/pir-passive-infrared-proximity-motion-sensor/using-a-pir
//          https://gist.github.com/zsup/9496462
//          http://community.garadget.com/t/instructions-for-home-grown-garadget-clone/69 --> Relay Belegung und Schaltung
//          https://learn.adafruit.com/rgb-led-strips


int inputPin = D4;              // choose the input pin (for PIR sensor)
int ledPin = D3;                // LED Pin
int pirState = LOW;             // we start, assuming no motion detected
int val = 0;                    // variable for reading the pin status
int boardLed = D7;              // photon onBoard LED
int calibrateTime = 2000;       // wait for the thingy to calibrate
int light_threshold = 100;      // brightness as analog value to decide its time for more light as analog value
int analogvalue;                // Here we are declaring the integer variable analogvalue, which we will use later to store the value of the photoresistor.
unsigned long lastmillis = 0;   // time for iteration the loop

int red = 255;
int green = 255;
int blue = 255;

#define REDPIN A5
#define GREENPIN WKP   
#define BLUEPIN A4

// #define FADESPEED 5          // make this higher to slow down - used in function ColorFade as Option
int delayColorFade = 15;        // presents the value in seconds

char auth[] = "xxx6d99"; // cap_cow_pir_led_flur_oben
//char auth[] = "<<your blync auth-code here>>"; 

Adafruit_TSL2561_Unified tsl = Adafruit_TSL2561_Unified(TSL2561_ADDR_FLOAT, 12345);

// *********   

BLYNK_WRITE(V6) // zeRGBa - Default
{ 
  // The param can contain multiple values, in such case:
  red = param[0].asInt();
  green = param[1].asInt();
  blue = param[2].asInt();
}

// *********    

BLYNK_WRITE(V4)     // Blynk app WRITES Slider widget  
{
    light_threshold = param.asInt();
    Serial.println("******************************");    
    Serial.print(light_threshold);    
    Serial.println(" analog value = new Threshold for Light");    
    Serial.println("******************************");    
}

// *********  

void update_light_threshold() 
{
    Blynk.virtualWrite(V3, light_threshold);
}

// *********    

BLYNK_WRITE(V2)     // Blynk app WRITES Slider widget  
{
    delayColorFade = param.asInt(); // macht aus den Blynk-Werten millisekunden
    Serial.println("******************************");    
    Serial.print(delayColorFade);    
    Serial.println(" milli-sec = new Delay for Function ColorFade");    
    Serial.println("******************************");    
}

// *********  

void update_delayColorFade() 
{
    Blynk.virtualWrite(V1, delayColorFade);
}

// *********    

BLYNK_WRITE(V0) // zeRGBa - Color
{ 
  // The param can contain multiple values, in such case:
  int red = param[0].asInt();
  int green = param[1].asInt();
  int blue = param[2].asInt();
  
  analogWrite(REDPIN, red); 
  analogWrite(GREENPIN, green);
  analogWrite(BLUEPIN, blue);
}

// ********* 

void setup() {
  Serial.begin(9600);

  pinMode(REDPIN, OUTPUT);
  pinMode(GREENPIN, OUTPUT);
  pinMode(BLUEPIN, OUTPUT);
  
  pinMode(boardLed,OUTPUT);     // on-board LED 
  pinMode(ledPin, OUTPUT);      // control PIR LED
  pinMode(inputPin, INPUT);     // declare sensor as input
  
  digitalWrite(boardLed,HIGH);  // Now flash the D7 LED on and off 
  Particle.publish("PIR-Motion", "PIR now online - 1/2", PRIVATE);  // informs user via Particle Cloud
  digitalWrite(boardLed,LOW);   
 
  // *** TSL2561 - Start
  Serial.println("Light Sensor Test"); Serial.println("");
  
  /* Initialise the sensor */
  if(!tsl.begin())
  {
    /* There was a problem detecting the ADXL345 ... check your connections */
    Serial.print("Ooops, no TSL2561 detected ... Check your wiring or I2C ADDR!");
    while(1);
  }
  
  /* Display some basic information on this sensor */
  displaySensorDetails();
  
  /* Setup the sensor gain and integration time */
  configureSensor();
  
  /* We're ready to go! */
  digitalWrite(boardLed,HIGH);  // Now flash the D7 LED on and off 
  Particle.publish("PIR-Motion", "TSL2561 now online - 2/2", PRIVATE);  // informs user via Particle Cloud
  digitalWrite(boardLed,LOW);   
  // *** TSL2561 - Ende

  Blynk.begin(auth);    // Start Blynk
  
}
 
// *********  

void loop() {
    
  Blynk.run();

  // if the sensor is calibrated
  if (calibrated())
  {
    if ((millis() - lastmillis) > 1000) {
        lastmillis = millis();
        readTSL();                // values from TSL2561
        reportTheData();          // motion detected?
        update_delayColorFade();  // Update Blynk-App Input
        update_light_threshold(); // Update Blynk-App Input
    }
  }
}

// *********

bool calibrated() {
  return millis() - calibrateTime > 0;
}

// *********

void reportTheData() {
  
  // check the PIR-Sensor
  val = digitalRead(inputPin);
  // if the sensor reads high
  
  // or there is now motion
  if (val == HIGH) {

    // the current state is no motion
    // i.e. it's just changed
    // announce this change by publishing an eent
    if (pirState == LOW) {
      // we have just turned on
      Particle.publish("PIR Motion", "Motion detected", PRIVATE);

      pirState = HIGH;
      setLED( pirState );

        if (analogvalue /*light*/ <= light_threshold) {
              Particle.publish("PIR Motion", String(analogvalue), PRIVATE);
              Particle.publish("PIR Motion", String(light_threshold), PRIVATE);
              Particle.publish("PIR Motion", "LED Streifen an", PRIVATE);
              
                ColorFade();
 
        } else {
            //Particle.publish("PIR Motion", String(analogvalue), PRIVATE);
        }
    }
  } else {
    if (pirState == HIGH) {
      // we have just turned of
      // Update the current state
      pirState = LOW;
      setLED( pirState );
    }
  }
}

// *********

void setLED( int state )
{
  digitalWrite(ledPin, state);
}

// *********
 
void ColorFade() {

    // LED Streifen anschalten
  analogWrite(REDPIN, red); 
  analogWrite(GREENPIN, green);
  analogWrite(BLUEPIN, blue);
  
  delay(delayColorFade * 1000); // 15 Sekunden bleibt Licht per Default an bzw. solange, wie über den Blynk Slider eingestellt wurde
  
  /* Fading ist ausgeschaltet
  int r, g, b;
 
  // fade from blue to violet
  for (r = 0; r < 256; r++) {
    analogWrite(REDPIN, r);
    delay(FADESPEED);
  }
  // fade from violet to red
  for (b = 255; b > 0; b--) {
    analogWrite(BLUEPIN, b);
    delay(FADESPEED);
  }
  // fade from red to yellow
  for (g = 0; g < 256; g++) {
    analogWrite(GREENPIN, g);
    delay(FADESPEED);
  }
  // fade from yellow to green
  for (r = 255; r > 0; r--) {
    analogWrite(REDPIN, r);
    delay(FADESPEED);
  }
  // fade from green to teal
  for (b = 0; b < 256; b++) {
    analogWrite(BLUEPIN, b);
    delay(FADESPEED);
  }
  // fade from teal to blue
  for (g = 255; g > 0; g--) {
    analogWrite(GREENPIN, g);
    delay(FADESPEED);
  }
  */
  
  // LED Streifen ausschalten
  analogWrite(REDPIN, 0);
  analogWrite(BLUEPIN, 0);
  analogWrite(GREENPIN, 0);
  
}

// ********** Neuaufnahme von Funktionen für den TSL2561 - Start

void readTSL()
{ 

  /* Get a new sensor event */ 
  sensors_event_t event;
  tsl.getEvent(&event);
 
  /* Display the results (light is measured in lux) */
  if (event.light)
  {
    analogvalue = (event.light);
    Serial.print(analogvalue); Serial.println(" lux");
    Blynk.virtualWrite(V7, analogvalue);
    Particle.publish("PIR Motion", String(analogvalue), PRIVATE);
  }
  else
  {
    /* If event.light = 0 lux the sensor is probably saturated
       and no reliable data could be generated! */
    Serial.println("Sensor overload - 1 lux");
    analogvalue = 1; // Ersatz im Falle eines Problems
    //Blynk.virtualWrite(V7, analogvalue);
    //Particle.publish("PIR Motion", String(analogvalue), PRIVATE);
  }

}


/**************************************************************************/
/*
    Displays some basic information on this sensor from the unified
    sensor API sensor_t type (see Adafruit_Sensor for more information)
*/
/**************************************************************************/
void displaySensorDetails(void)
{
  sensor_t sensor;
  tsl.getSensor(&sensor);
  Serial.println("------------------------------------");
  Serial.print  ("Sensor:       "); Serial.println(sensor.name);
  Serial.print  ("Driver Ver:   "); Serial.println(sensor.version);
  Serial.print  ("Unique ID:    "); Serial.println(sensor.sensor_id);
  Serial.print  ("Max Value:    "); Serial.print(sensor.max_value); Serial.println(" lux");
  Serial.print  ("Min Value:    "); Serial.print(sensor.min_value); Serial.println(" lux");
  Serial.print  ("Resolution:   "); Serial.print(sensor.resolution); Serial.println(" lux");  
  Serial.println("------------------------------------");
  Serial.println("");

}

/**************************************************************************/
/*
    Configures the gain and integration time for the TSL2561
*/
/**************************************************************************/
void configureSensor(void)
{
  /* You can also manually set the gain or enable auto-gain support */
  // tsl.setGain(TSL2561_GAIN_1X);      /* No gain ... use in bright light to avoid sensor saturation */
  //tsl.setGain(TSL2561_GAIN_16X);     /* 16x gain ... use in low light to boost sensitivity */
  tsl.enableAutoRange(true);            /* Auto-gain ... switches automatically between 1x and 16x */
  
  /* Changing the integration time gives you better sensor resolution (402ms = 16-bit data) */
  tsl.setIntegrationTime(TSL2561_INTEGRATIONTIME_13MS);      /* fast but low resolution */
  //tsl.setIntegrationTime(TSL2561_INTEGRATIONTIME_101MS);  /* medium resolution and speed   */
  //tsl.setIntegrationTime(TSL2561_INTEGRATIONTIME_402MS);  /* 16-bit data but slowest conversions */

  /* Update these values depending on what you've set above! */  
  Serial.println("------------------------------------");
  Serial.print  ("Gain:         "); Serial.println("auto");
  Serial.print  ("Timing:       "); Serial.println("13 ms");
  Serial.println("------------------------------------");
}

// ********** Neuaufnahme von Funktionen für den TSL2561 - Ende

Your loop is a congested… every second each of those functions is trying to run at the same time.

Use BlynkTimer and stagger the separate functions.

http://help.blynk.cc/getting-started-library-auth-token-code-examples/blynk-basics/keep-your-void-loop-clean

Thx, @Gunner, I am on the right way? I follow your article: pls have an eye to this code-update:

// Ingo Lohs, Version 1.4 - 18.11.2018 - works with Particle Photon v0.7.0
// myled-mosefet-blynk-v2.ino
// https://www.hackster.io/ingo-lohs/mypir-sensor-activate-analog-rgb-stripe-controlled-by-photon-2e8240

// https://github.com/blynkkk/blynk-library/blob/master/examples/GettingStarted/PushData/PushData.ino#L30
// BlynkTimer zur Aufsplittung der Funktionen erwünscht

#define BLYNK_DEBUG // Optional, this enables lots of prints
#define BLYNK_PRINT Serial

#include <blynk.h>
#include <Adafruit_TSL2561_U.h>

// Change von Version 1.1 > 1.2:
// Änderung der Default-RGB-Werte via zweites Zergba (zusätzliches Blynk-Widget) gebunden an V6, um dynamisch die Default-RGB-Werte abändern zu könnnen ohne erneut den Code flashen zu müssen
// Change von Version 1.2 > 1.3:
// Vorbelegung der Variablen red, green, blue mit der Zuweisung von jew. 255: so ist bei einem Restart der Default für das Licht als "weiss" vorbelegt
// Change von Version 1.3 > 1.4:
// Aufnahme des Lichtsensors TSL2561 inkl. seiner Adafruit-Library - Default-Address is: 0x39
// Firmware-Update von v0.6.3 > v0.7.0
// Änderung der PINs von Control-LED und PIR-Sensor, um SDA und SCL für den TSL2561 verfügbar zu haben
// Sensor overload kommt im Dunkeln und so ist der analogvalue = 1 gesetzt

// Erweiterung: * vorstellbar wäre eine while-Scheife, die solange LED on hat wie auch die PIR-Detektion anhält

// Quelle:  http://diotlabs.daraghbyrne.me/7-communicating-events/pir/
//          https://learn.adafruit.com/pir-passive-infrared-proximity-motion-sensor/using-a-pir
//          https://gist.github.com/zsup/9496462
//          http://community.garadget.com/t/instructions-for-home-grown-garadget-clone/69 --> Relay Belegung und Schaltung
//          https://learn.adafruit.com/rgb-led-strips


int inputPin = D4;              // choose the input pin (for PIR sensor)
int ledPin = D3;                // LED Pin
int pirState = LOW;             // we start, assuming no motion detected
int val = 0;                    // variable for reading the pin status
int boardLed = D7;              // photon onBoard LED
int calibrateTime = 10000;      // wait for the thingy to calibrate
int light_threshold = 100;      // brightness as analog value to decide its time for more light as analog value
int analogvalue;                // Here we are declaring the integer variable analogvalue, which we will use later to store the value of the photoresistor.
unsigned long lastmillis = 0;   // time for iteration the loop

int red = 255;
int green = 255;
int blue = 255;

#define REDPIN A5
#define GREENPIN WKP   
#define BLUEPIN A4

// #define FADESPEED 5          // make this higher to slow down - used in function ColorFade as Option
int delayColorFade = 15;        // presents the value in seconds

char auth[] = "xxxxx6d99"; // cap_cow_pir_led_flur_oben
//char auth[] = "<<your blync auth-code here>>"; 

Adafruit_TSL2561_Unified tsl = Adafruit_TSL2561_Unified(TSL2561_ADDR_FLOAT, 12345);

BlynkTimer timer; // Create a Timer object called "timer"! > readTSL and update AppValues
// https://community.blynk.cc/t/c-blynk-code-examples-for-basic-tasks-work-in-progress/22596/23

// *********   

BLYNK_WRITE(V6) // zeRGBa - Default
{ 
  // The param can contain multiple values, in such case:
  red = param[0].asInt();
  green = param[1].asInt();
  blue = param[2].asInt();
}

// *********    

BLYNK_WRITE(V4)     // Blynk app WRITES Slider widget  
{
    light_threshold = param.asInt();
    Serial.println("******************************");    
    Serial.print(light_threshold);    
    Serial.println(" analog value = new Threshold for Light");    
    Serial.println("******************************");    
}

// *********  

void update_light_threshold() 
{
    Blynk.virtualWrite(V3, light_threshold);
}

// *********    

BLYNK_WRITE(V2)     // Blynk app WRITES Slider widget  
{
    delayColorFade = param.asInt(); // macht aus den Blynk-Werten millisekunden
    Serial.println("******************************");    
    Serial.print(delayColorFade);    
    Serial.println(" milli-sec = new Delay for Function ColorFade");    
    Serial.println("******************************");    
}

// *********  

void update_delayColorFade() 
{
    Blynk.virtualWrite(V1, delayColorFade);
}

// *********    

BLYNK_WRITE(V0) // zeRGBa - Color
{ 
  // The param can contain multiple values, in such case:
  int red = param[0].asInt();
  int green = param[1].asInt();
  int blue = param[2].asInt();
  
  analogWrite(REDPIN, red); 
  analogWrite(GREENPIN, green);
  analogWrite(BLUEPIN, blue);
}

// ********* 

void setup() {
  Serial.begin(9600);

  pinMode(REDPIN, OUTPUT);
  pinMode(GREENPIN, OUTPUT);
  pinMode(BLUEPIN, OUTPUT);
  
  pinMode(boardLed,OUTPUT);     // on-board LED 
  pinMode(ledPin, OUTPUT);      // control PIR LED
  pinMode(inputPin, INPUT);     // declare sensor as input
  
  digitalWrite(boardLed,HIGH);  // Now flash the D7 LED on and off 
  Particle.publish("PIR-Motion", "PIR now online - 1/2", PRIVATE);  // informs user via Particle Cloud
  digitalWrite(boardLed,LOW);   
 
  // *** TSL2561 - Start
  Serial.println("Light Sensor Test"); Serial.println("");
  
  /* Initialise the sensor */
  if(!tsl.begin())
  {
    /* There was a problem detecting the ADXL345 ... check your connections */
    Serial.print("Ooops, no TSL2561 detected ... Check your wiring or I2C ADDR!");
    while(1);
  }
  
  /* Display some basic information on this sensor */
  displaySensorDetails();
  
  /* Setup the sensor gain and integration time */
  configureSensor();
  
  /* We're ready to go! */
  digitalWrite(boardLed,HIGH);  // Now flash the D7 LED on and off 
  Particle.publish("PIR-Motion", "TSL2561 now online - 2/2", PRIVATE);  // informs user via Particle Cloud
  digitalWrite(boardLed,LOW);   
  // *** TSL2561 - Ende

  Blynk.begin(auth);    // Start Blynk
  timer.setInterval(1000L, readTSL); //  Here you set interval (1sec) and which function to call
  timer.setInterval(2000L, update_delayColorFade); //  Here you set interval (1sec) and which function to call
  timer.setInterval(2000L, update_light_threshold); //  Here you set interval (1sec) and which function to call 
  
}
 
// *********  

void loop() {
    
  Blynk.run();
  timer.run(); // BlynkTimer is working... > readTSL and update AppValues
  

  // if the sensor is calibrated
  if (calibrated())
  {
    if ((millis() - lastmillis) > 1000) {
        lastmillis = millis();
        //readTSL();                // values from TSL2561
        reportTheData();          // motion detected?
        //update_delayColorFade();  // Update Blynk-App Input
        //update_light_threshold(); // Update Blynk-App Input
    }
  }
}

// *********

bool calibrated() {
  return millis() - calibrateTime > 0;
}

// *********

void reportTheData() {
  
  // check the PIR-Sensor
  val = digitalRead(inputPin);
  // if the sensor reads high
  
  // or there is now motion
  if (val == HIGH) {

    // the current state is no motion
    // i.e. it's just changed
    // announce this change by publishing an eent
    if (pirState == LOW) {
      // we have just turned on
      Particle.publish("PIR Motion", "Motion detected", PRIVATE);

      pirState = HIGH;
      setLED( pirState );

        if (analogvalue /*light*/ <= light_threshold) {
              Particle.publish("PIR Motion", String(analogvalue), PRIVATE);
              Particle.publish("PIR Motion", String(light_threshold), PRIVATE);
              Particle.publish("PIR Motion", "LED Streifen an", PRIVATE);
              
                ColorFade();
 
        } else {
            //Particle.publish("PIR Motion", String(analogvalue), PRIVATE);
        }
    }
  } else {
    if (pirState == HIGH) {
      // we have just turned of
      // Update the current state
      pirState = LOW;
      setLED( pirState );
    }
  }
}

// *********

void setLED( int state )
{
  digitalWrite(ledPin, state);
}

// *********
 
void ColorFade() {

    // LED Streifen anschalten
  analogWrite(REDPIN, red); 
  analogWrite(GREENPIN, green);
  analogWrite(BLUEPIN, blue);
  
  delay(delayColorFade * 1000); // 15 Sekunden bleibt Licht per Default an bzw. solange, wie über den Blynk Slider eingestellt wurde
  
  /* Fading ist ausgeschaltet
  int r, g, b;
 
  // fade from blue to violet
  for (r = 0; r < 256; r++) {
    analogWrite(REDPIN, r);
    delay(FADESPEED);
  }
  // fade from violet to red
  for (b = 255; b > 0; b--) {
    analogWrite(BLUEPIN, b);
    delay(FADESPEED);
  }
  // fade from red to yellow
  for (g = 0; g < 256; g++) {
    analogWrite(GREENPIN, g);
    delay(FADESPEED);
  }
  // fade from yellow to green
  for (r = 255; r > 0; r--) {
    analogWrite(REDPIN, r);
    delay(FADESPEED);
  }
  // fade from green to teal
  for (b = 0; b < 256; b++) {
    analogWrite(BLUEPIN, b);
    delay(FADESPEED);
  }
  // fade from teal to blue
  for (g = 255; g > 0; g--) {
    analogWrite(GREENPIN, g);
    delay(FADESPEED);
  }
  */
  
  // LED Streifen ausschalten
  analogWrite(REDPIN, 0);
  analogWrite(BLUEPIN, 0);
  analogWrite(GREENPIN, 0);
  
}

// ********** Neuaufnahme von Funktionen für den TSL2561 - Start

void readTSL()
{ 

  /* Get a new sensor event */ 
  sensors_event_t event;
  tsl.getEvent(&event);
 
  /* Display the results (light is measured in lux) */
  if (event.light)
  {
    analogvalue = (event.light);
    Serial.print(analogvalue); Serial.println(" lux");
    Blynk.virtualWrite(V7, analogvalue);
    Particle.publish("PIR Motion", String(analogvalue), PRIVATE);
  }
  else
  {
    /* If event.light = 0 lux the sensor is probably saturated
       and no reliable data could be generated! */
    Serial.println("Sensor overload - 1 lux");
    analogvalue = 1; // Ersatz im Falle eines Problems
    //Blynk.virtualWrite(V7, analogvalue);
    //Particle.publish("PIR Motion", String(analogvalue), PRIVATE);
  }
  
}


/**************************************************************************/
/*
    Displays some basic information on this sensor from the unified
    sensor API sensor_t type (see Adafruit_Sensor for more information)
*/
/**************************************************************************/
void displaySensorDetails(void)
{
  sensor_t sensor;
  tsl.getSensor(&sensor);
  Serial.println("------------------------------------");
  Serial.print  ("Sensor:       "); Serial.println(sensor.name);
  Serial.print  ("Driver Ver:   "); Serial.println(sensor.version);
  Serial.print  ("Unique ID:    "); Serial.println(sensor.sensor_id);
  Serial.print  ("Max Value:    "); Serial.print(sensor.max_value); Serial.println(" lux");
  Serial.print  ("Min Value:    "); Serial.print(sensor.min_value); Serial.println(" lux");
  Serial.print  ("Resolution:   "); Serial.print(sensor.resolution); Serial.println(" lux");  
  Serial.println("------------------------------------");
  Serial.println("");

}

/**************************************************************************/
/*
    Configures the gain and integration time for the TSL2561
*/
/**************************************************************************/
void configureSensor(void)
{
  /* You can also manually set the gain or enable auto-gain support */
  // tsl.setGain(TSL2561_GAIN_1X);      /* No gain ... use in bright light to avoid sensor saturation */
  //tsl.setGain(TSL2561_GAIN_16X);     /* 16x gain ... use in low light to boost sensitivity */
  tsl.enableAutoRange(true);            /* Auto-gain ... switches automatically between 1x and 16x */
  
  /* Changing the integration time gives you better sensor resolution (402ms = 16-bit data) */
  tsl.setIntegrationTime(TSL2561_INTEGRATIONTIME_13MS);      /* fast but low resolution */
  //tsl.setIntegrationTime(TSL2561_INTEGRATIONTIME_101MS);  /* medium resolution and speed   */
  //tsl.setIntegrationTime(TSL2561_INTEGRATIONTIME_402MS);  /* 16-bit data but slowest conversions */

  /* Update these values depending on what you've set above! */  
  Serial.println("------------------------------------");
  Serial.print  ("Gain:         "); Serial.println("auto");
  Serial.print  ("Timing:       "); Serial.println("13 ms");
  Serial.println("------------------------------------");
}

// ********** Neuaufnahme von Funktionen für den TSL2561 - Ende

Better… but move ALL called functions out of the void loop(). you can still have the calibrate flag control in each separate function if needed.

Also try to stagger timers for non-intersecting runs… remember that they all start counting down at the exact same time in the setup loop()

Eg. a 1 second timer will intersect with a 2 second timer every 2nd iteration and so on. And you have two timers already trying to run at the same time every 2 seconds.

Unless the relatively precise timing is essential, I usually add or subtract a few ms… but with random odd numbering… 1017 (1 second), giving 17ms distance between intersecting a with 2000 (2 second) timer, which will not intersect with a 60028 (1 minute) timer, and so on.

ok,@Gunner, here my next try with a log-output:

    // Ingo Lohs, Version 1.4 - 18.11.2018 - works with Particle Photon v0.7.0
    // myled-mosefet-blynk-v2.ino
    // https://www.hackster.io/ingo-lohs/mypir-sensor-activate-analog-rgb-stripe-controlled-by-photon-2e8240

    // https://github.com/blynkkk/blynk-library/blob/master/examples/GettingStarted/PushData/PushData.ino#L30
    // BlynkTimer zur Aufsplittung der Funktionen erwünscht

    #define BLYNK_DEBUG // Optional, this enables lots of prints
    #define BLYNK_PRINT Serial

    #include <blynk.h>
    #include <Adafruit_TSL2561_U.h>

    // Change von Version 1.1 > 1.2:
    // Änderung der Default-RGB-Werte via zweites Zergba (zusätzliches Blynk-Widget) gebunden an V6, um dynamisch die Default-RGB-Werte abändern zu könnnen ohne erneut den Code flashen zu müssen
    // Change von Version 1.2 > 1.3:
    // Vorbelegung der Variablen red, green, blue mit der Zuweisung von jew. 255: so ist bei einem Restart der Default für das Licht als "weiss" vorbelegt
    // Change von Version 1.3 > 1.4:
    // Aufnahme des Lichtsensors TSL2561 inkl. seiner Adafruit-Library - Default-Address is: 0x39
    // Firmware-Update von v0.6.3 > v0.7.0
    // Änderung der PINs von Control-LED und PIR-Sensor, um SDA und SCL für den TSL2561 verfügbar zu haben
    // Sensor overload kommt im Dunkeln und so ist der analogvalue = 1 gesetzt

    // Erweiterung: * vorstellbar wäre eine while-Scheife, die solange LED on hat wie auch die PIR-Detektion anhält

    // Quelle:  http://diotlabs.daraghbyrne.me/7-communicating-events/pir/
    //          https://learn.adafruit.com/pir-passive-infrared-proximity-motion-sensor/using-a-pir
    //          https://gist.github.com/zsup/9496462
    //          http://community.garadget.com/t/instructions-for-home-grown-garadget-clone/69 --> Relay Belegung und Schaltung
    //          https://learn.adafruit.com/rgb-led-strips


    int inputPin = D4;              // choose the input pin (for PIR sensor)
    int ledPin = D3;                // LED Pin
    int pirState = LOW;             // we start, assuming no motion detected
    int val = 0;                    // variable for reading the pin status
    int boardLed = D7;              // photon onBoard LED
    int calibrateTime = 5000;       // wait for the thingy to calibrate
    int light_threshold = 100;      // brightness as analog value to decide its time for more light as analog value
    int analogvalue;                // Here we are declaring the integer variable analogvalue, which we will use later to store the value of the photoresistor.
    unsigned long lastmillis = 0;   // time for iteration the loop

    int red = 255;
    int green = 255;
    int blue = 255;

    #define REDPIN A5
    #define GREENPIN WKP   
    #define BLUEPIN A4

    // #define FADESPEED 5          // make this higher to slow down - used in function ColorFade as Option
    int delayColorFade = 15;        // presents the value in seconds

    char auth[] = "xxxxx6d99"; // cap_cow_pir_led_flur_oben
    //char auth[] = "<<your blync auth-code here>>"; 

    Adafruit_TSL2561_Unified tsl = Adafruit_TSL2561_Unified(TSL2561_ADDR_FLOAT, 12345);

    BlynkTimer blynk_timer; // Create a Timer object called "timer"! > readTSL and update AppValues
    // https://community.blynk.cc/t/c-blynk-code-examples-for-basic-tasks-work-in-progress/22596/23
    Timer particle_timer(1011, reportTheData);
    // https://docs.particle.io/reference/device-os/firmware/photon/#software-timers


    // *********   

    BLYNK_WRITE(V6) // zeRGBa - Default
    { 
      // The param can contain multiple values, in such case:
      red = param[0].asInt();
      green = param[1].asInt();
      blue = param[2].asInt();
    }

    // *********    

    BLYNK_WRITE(V4)     // Blynk app WRITES Slider widget  
    {
        light_threshold = param.asInt();
        Serial.println("******************************");    
        Serial.print(light_threshold);    
        Serial.println(" analog value = new Threshold for Light");    
        Serial.println("******************************");    
    }

    // *********  

    void update_light_threshold() 
    {
        Blynk.virtualWrite(V3, light_threshold);
    }

    // *********    

    BLYNK_WRITE(V2)     // Blynk app WRITES Slider widget  
    {
        delayColorFade = param.asInt(); // macht aus den Blynk-Werten millisekunden
        Serial.println("******************************");    
        Serial.print(delayColorFade);    
        Serial.println(" milli-sec = new Delay for Function ColorFade");    
        Serial.println("******************************");    
    }

    // *********  

    void update_delayColorFade() 
    {
        Blynk.virtualWrite(V1, delayColorFade);
    }

    // *********    

    BLYNK_WRITE(V0) // zeRGBa - Color
    { 
      // The param can contain multiple values, in such case:
      int red = param[0].asInt();
      int green = param[1].asInt();
      int blue = param[2].asInt();
      
      analogWrite(REDPIN, red); 
      analogWrite(GREENPIN, green);
      analogWrite(BLUEPIN, blue);
    }

    // ********* 

    void setup() {

      Serial.begin(9600);

      // if the sensor is calibrated
      if (calibrated())
      {  

      pinMode(REDPIN, OUTPUT);
      pinMode(GREENPIN, OUTPUT);
      pinMode(BLUEPIN, OUTPUT);
      
      pinMode(boardLed,OUTPUT);     // on-board LED 
      pinMode(ledPin, OUTPUT);      // control PIR LED
      pinMode(inputPin, INPUT);     // declare sensor as input
      
      digitalWrite(boardLed,HIGH);  // Now flash the D7 LED on and off 
      Particle.publish("PIR-Motion", "PIR now online - 1/2", PRIVATE);  // informs user via Particle Cloud
      digitalWrite(boardLed,LOW);   
     
      // *** TSL2561 - Start
      Serial.println("Light Sensor Test"); Serial.println("");
      
      /* Initialise the sensor */
      if(!tsl.begin())
      {
        /* There was a problem detecting the ADXL345 ... check your connections */
        Serial.print("Ooops, no TSL2561 detected ... Check your wiring or I2C ADDR!");
        while(1);
      }
      
      /* Display some basic information on this sensor */
      displaySensorDetails();
      
      /* Setup the sensor gain and integration time */
      configureSensor();
      
      /* We're ready to go! */
      digitalWrite(boardLed,HIGH);  // Now flash the D7 LED on and off 
      Particle.publish("PIR-Motion", "TSL2561 now online - 2/2", PRIVATE);  // informs user via Particle Cloud
      digitalWrite(boardLed,LOW);   
      // *** TSL2561 - Ende

      // Blynk magic
      Blynk.begin(auth);    // Start Blynk
      
      blynk_timer.setInterval(60101L, readTSL); //  Here you set interval (1sec) and which function to call
      particle_timer.start(); //blynk_timer.setInterval(1011L, reportTheData); 
      blynk_timer.setInterval(1111L, update_delayColorFade); //  Here you set interval (1sec) and which function to call
      blynk_timer.setInterval(1255L, update_light_threshold); //  Here you set interval (1sec) and which function to call 

      }
    }
     
    // *********  

    void loop() {
        
      Blynk.run();
      blynk_timer.run(); // BlynkTimer is working... > readTSL and update AppValues
      
    /*
        if ((millis() - lastmillis) > 1000) {
            lastmillis = millis();
            //readTSL();                // values from TSL2561
            reportTheData();          // motion detected?
            update_delayColorFade();  // Update Blynk-App Input
            update_light_threshold(); // Update Blynk-App Input
        }
    */
    }

    // *********

    bool calibrated() {
      return millis() - calibrateTime > 0;
    }

    // *********

    void reportTheData() {
      
      // check the PIR-Sensor
      val = digitalRead(inputPin);
      // if the sensor reads high
      
      // or there is now motion
      if (val == HIGH) {

        // the current state is no motion
        // i.e. it's just changed
        // announce this change by publishing an eent
        if (pirState == LOW) {
          // we have just turned on
          Particle.publish("PIR Motion", "Motion detected", PRIVATE);

          pirState = HIGH;
          setLED( pirState );

            if (analogvalue /*light*/ <= light_threshold) {
                  Particle.publish("PIR Motion", String(analogvalue), PRIVATE);
                  Particle.publish("PIR Motion", String(light_threshold), PRIVATE);
                  Particle.publish("PIR Motion", "LED Streifen an", PRIVATE);
                  
                    ColorFade();
     
            } else {
                //Particle.publish("PIR Motion", String(analogvalue), PRIVATE);
            }
        }
      } else {
        if (pirState == HIGH) {
          // we have just turned of
          // Update the current state
          pirState = LOW;
          setLED( pirState );
        }
      }
    }

    // *********

    void setLED( int state )
    {
      digitalWrite(ledPin, state);
    }

    // *********
     
    void ColorFade() {

        // LED Streifen anschalten
      analogWrite(REDPIN, red); 
      analogWrite(GREENPIN, green);
      analogWrite(BLUEPIN, blue);
      
      delay(delayColorFade * 1000); // 15 Sekunden bleibt Licht per Default an bzw. solange, wie über den Blynk Slider eingestellt wurde
      
      /* Fading ist ausgeschaltet
      int r, g, b;
     
      // fade from blue to violet
      for (r = 0; r < 256; r++) {
        analogWrite(REDPIN, r);
        delay(FADESPEED);
      }
      // fade from violet to red
      for (b = 255; b > 0; b--) {
        analogWrite(BLUEPIN, b);
        delay(FADESPEED);
      }
      // fade from red to yellow
      for (g = 0; g < 256; g++) {
        analogWrite(GREENPIN, g);
        delay(FADESPEED);
      }
      // fade from yellow to green
      for (r = 255; r > 0; r--) {
        analogWrite(REDPIN, r);
        delay(FADESPEED);
      }
      // fade from green to teal
      for (b = 0; b < 256; b++) {
        analogWrite(BLUEPIN, b);
        delay(FADESPEED);
      }
      // fade from teal to blue
      for (g = 255; g > 0; g--) {
        analogWrite(GREENPIN, g);
        delay(FADESPEED);
      }
      */
      
      // LED Streifen ausschalten
      analogWrite(REDPIN, 0);
      analogWrite(BLUEPIN, 0);
      analogWrite(GREENPIN, 0);
      
    }

    // ********** Neuaufnahme von Funktionen für den TSL2561 - Start

    void readTSL()
    { 

      /* Get a new sensor event */ 
      sensors_event_t event;
      tsl.getEvent(&event);
     
      /* Display the results (light is measured in lux) */
      if (event.light)
      {
        analogvalue = (event.light);
        Serial.print(analogvalue); Serial.println(" lux");
        Blynk.virtualWrite(V7, analogvalue);
        Particle.publish("PIR Motion", String(analogvalue), PRIVATE);
      }
      else
      {
        /* If event.light = 0 lux the sensor is probably saturated
           and no reliable data could be generated! */
        Serial.println("Sensor overload - 1 lux");
        analogvalue = 1; // Ersatz im Falle eines Problems
        //Blynk.virtualWrite(V7, analogvalue);
        //Particle.publish("PIR Motion", String(analogvalue), PRIVATE);
      }
      
    }


    /**************************************************************************/
    /*
        Displays some basic information on this sensor from the unified
        sensor API sensor_t type (see Adafruit_Sensor for more information)
    */
    /**************************************************************************/
    void displaySensorDetails(void)
    {
      sensor_t sensor;
      tsl.getSensor(&sensor);
      Serial.println("------------------------------------");
      Serial.print  ("Sensor:       "); Serial.println(sensor.name);
      Serial.print  ("Driver Ver:   "); Serial.println(sensor.version);
      Serial.print  ("Unique ID:    "); Serial.println(sensor.sensor_id);
      Serial.print  ("Max Value:    "); Serial.print(sensor.max_value); Serial.println(" lux");
      Serial.print  ("Min Value:    "); Serial.print(sensor.min_value); Serial.println(" lux");
      Serial.print  ("Resolution:   "); Serial.print(sensor.resolution); Serial.println(" lux");  
      Serial.println("------------------------------------");
      Serial.println("");

    }

    /**************************************************************************/
    /*
        Configures the gain and integration time for the TSL2561
    */
    /**************************************************************************/
    void configureSensor(void)
    {
      /* You can also manually set the gain or enable auto-gain support */
      // tsl.setGain(TSL2561_GAIN_1X);      /* No gain ... use in bright light to avoid sensor saturation */
      //tsl.setGain(TSL2561_GAIN_16X);     /* 16x gain ... use in low light to boost sensitivity */
      tsl.enableAutoRange(true);            /* Auto-gain ... switches automatically between 1x and 16x */
      
      /* Changing the integration time gives you better sensor resolution (402ms = 16-bit data) */
      tsl.setIntegrationTime(TSL2561_INTEGRATIONTIME_13MS);      /* fast but low resolution */
      //tsl.setIntegrationTime(TSL2561_INTEGRATIONTIME_101MS);  /* medium resolution and speed   */
      //tsl.setIntegrationTime(TSL2561_INTEGRATIONTIME_402MS);  /* 16-bit data but slowest conversions */

      /* Update these values depending on what you've set above! */  
      Serial.println("------------------------------------");
      Serial.print  ("Gain:         "); Serial.println("auto");
      Serial.print  ("Timing:       "); Serial.println("13 ms");
      Serial.println("------------------------------------");
    }

    // ********** Neuaufnahme von Funktionen für den TSL2561 - Ende
___ __ __
/___/ v0.5.4 on Particle Photon

[13351] Connecting to blynk-cloud.com:80

[13355] &lt;[02|00|01|00] xxxxx6d99

[16357] Login timeout

[18357] Connecting to blynk-cloud.com:80

[18396] &lt;[02|00|01|00] xxxxx6d99

[21399] Login timeout

[23398] Connecting to blynk-cloud.com:80

[23415] &lt;[02|00|01|00] xxxxx6d99

[23431] &gt;[00|00|01|00|C8]

[23431] Ready (ping: 15ms).

[23498] &lt;[11|00|02|00]Pver[00]0.5.4[00]h-beat[00]10[00]buff-in[00]1024[00]dev[00]Particle Photon[00]build[00]Nov 19 2018 23:34:24[00]

[23516] &gt;[00|00|02|00|C8]

[24353] &gt;[14|1E]b[00|04]

[24353] &gt;vr[00]3

[24614] &lt;[14|00|03|00|07]vw[00]1[00]15

[29618] Connecting to blynk-cloud.com:80

[29646] &lt;[02|00|01|00] xxxxx6d99

[29672] &gt;[00|00|01|00|C8]

[29672] Ready (ping: 26ms).

[29740] &lt;[11|00|02|00]Pver[00]0.5.4[00]h-beat[00]10[00]buff-in[00]1024[00]dev[00]Particle Photon[00]build[00]Nov 19 2018 23:34:24[00]

[29768] &gt;[00|00|02|00|C8]

[29835] &lt;[14|00|03|00|08]vw[00]3[00]100

[30170] &lt;[14|00|04|00|07]vw[00]1[00]15

[30364] &gt;[14|1E]b[00|04]

[30364] &gt;vr[00]3

[31033] &lt;[14|00|05|00|08]vw[00]3[00]100

[36037] Connecting to blynk-cloud.com:80

[36065] &lt;[02|00|01|00] xxxxx6d99

[36092] &gt;[00|00|01|00|C8]

[36092] Ready (ping: 26ms).

[36160] &lt;[11|00|02|00]Pver[00]0.5.4[00]h-beat[00]10[00]buff-in[00]1024[00]dev[00]Particle Photon[00]build[00]Nov 19 2018 23:34:24[00]

[36186] &gt;[00|00|02|00|C8]

[36381] &gt;[14|1E]b[00|04]

[36381] &gt;vr[00]3

[36835] &lt;[14|00|03|00|07]vw[00]1[00]15

[37308] &lt;[14|00|04|00|08]vw[00]3[00]100

[42312] Connecting to blynk-cloud.com:80

[42316] &lt;[02|00|01|00] xxxxx6d99

[45318] Login timeout

For me its enough if the lux-value from TLS2561 every 1 minute get an update or later.
I´m using also an particle timer, because the PIR-Sensor don’t need to use Blynk-services.
My problem is the same as before: its works, but my Smartphone App says “Device is offline”.
The auth-code is double-checked.

I don’t have any Particle boards… so am unsure of any other peculiarities that they might have.

Have you tried any other simpler sketches to confirm that your board can at least connect and stay connected?

Eg.

https://examples.blynk.cc/?board=Particle%20Photon&shield=Particle%20WiFi&example=GettingStarted%2FGetData

Dear Gunner,
Thank you for your patience with me: I simplified the code with the help of the particle community as much as possible and waived any “delay”. I ask you to check the code, because this works in itself, but the Blynk app sometimes “online” and often also “disconnected” displays.
The device is in close proximity to the WiFi router, the signal is excellent and I am also online in the Particle Cloud.
Logging out and logging into the smartphone app does not change anything.

    #include <blynk.h>
    #include <Adafruit_TSL2561_U.h>

    // Quelle:  http://diotlabs.daraghbyrne.me/7-communicating-events/pir/
    //          https://learn.adafruit.com/pir-passive-infrared-proximity-motion-sensor/using-a-pir
    //          https://gist.github.com/zsup/9496462
    //          http://community.garadget.com/t/instructions-for-home-grown-garadget-clone/69 --> Relay Belegung und Schaltung
    //          https://learn.adafruit.com/rgb-led-strips


    int inputPIR = D4;              // choose the input pin (for PIR sensor)
    int ledPin = D3;                // LED Pin
    int pirState = LOW;             // we start, assuming no motion detected
    int boardLed = D7;              // photon onBoard LED
    int calibrateTime = 5000;       // wait for the thingy to calibrate
    int lightThreshold = 100;       // brightness as analog value to decide its time for more light as analog value
    int ambientBrightness;          // Here we are declaring the integer variable ambientBrightness, which we will use later to store the value of the photoresistor.
    int i = 0;                      // delay-Ersatz für colorFade - for-Schleife

    int red   = 255;
    int green = 255;
    int blue  = 255;

    #define REDPIN A5
    #define GREENPIN WKP   
    #define BLUEPIN A4

    int delayColorFade = 15;   // presents the delay for the colorFade

    char auth[] = "123"; // cap_cow_pir_led_flur_oben
    //char auth[] = "<<your blync auth-code here>>"; 

    // Object
    Adafruit_TSL2561_Unified tsl = Adafruit_TSL2561_Unified(TSL2561_ADDR_FLOAT, 12345);

    BlynkTimer blynk_timer; // Create a Timer object called "timer"! > readTSL 
        // https://community.blynk.cc/t/c-blynk-code-examples-for-basic-tasks-work-in-progress/22596/23
    Timer particle_timer(1000, reportPIRStatus);

    // *********   

    BLYNK_WRITE(V6) // zeRGBa - Default
    { 
      // The param can contain multiple values, in such case:
      red = param[0].asInt();
      green = param[1].asInt();
      blue = param[2].asInt();
    }

    // *********    

    BLYNK_WRITE(V4) // Blynk app WRITES Slider widget  
    {
        lightThreshold = param.asInt();
        Serial.println("******************************");    
        Serial.print(lightThreshold);    
        Serial.println(" analog value = new Threshold for Light");    
        Serial.println("******************************");    
        Blynk.virtualWrite(V3, lightThreshold);
    }

    // *********  

    BLYNK_WRITE(V2) // Blynk app WRITES Slider widget  
    {
        delayColorFade = param.asInt(); // macht aus den Blynk-Werten millisekunden
        Serial.println("******************************");    
        Serial.print(delayColorFade);    
        Serial.println(" milli-sec = new Delay for Function ColorFade");    
        Serial.println("******************************");    
        Blynk.virtualWrite(V1, delayColorFade);
    }

    // *********    

    BLYNK_WRITE(V0) // zeRGBa - Color
    { 
      // The param can contain multiple values, in such case:
      int red = param[0].asInt();
      int green = param[1].asInt();
      int blue = param[2].asInt();
      
      analogWrite(REDPIN, red); 
      analogWrite(GREENPIN, green);
      analogWrite(BLUEPIN, blue);
    }

    // ********* 

    void setup() {

      Serial.begin(9600);
      digitalWrite(boardLed,HIGH);  // Now flash the D7 LED on and off 
           // Blynk magic
      Blynk.begin(auth);    // Start Blynk

      // if the sensor is calibrated
      if (calibrated())
      {  

          pinMode(REDPIN, OUTPUT);
          pinMode(GREENPIN, OUTPUT);
          pinMode(BLUEPIN, OUTPUT);
          
          pinMode(boardLed,OUTPUT);     // on-board LED 
          pinMode(ledPin, OUTPUT);      // control PIR LED
          pinMode(inputPIR, INPUT);     // declare sensor as input
          
          digitalWrite(boardLed,HIGH);  // Now flash the D7 LED on and off 
          Particle.publish("PIR-Motion", "PIR now online - 1/2", PRIVATE);  // informs user via Particle Cloud
          digitalWrite(boardLed,LOW);   
         
          // *** TSL2561 - Start
          Serial.println("Light Sensor Test"); Serial.println("");
          
          /* Initialise the sensor */
          if(!tsl.begin())
          {
            /* There was a problem detecting the ADXL345 ... check your connections */
            Serial.print("Ooops, no TSL2561 detected ... Check your wiring or I2C ADDR!");
            while(1);
          }
          
          /* Display some basic information on this sensor */
          displaySensorDetails();
          
          /* Setup the sensor gain and integration time */
          configureSensor();
          
          /* We're ready to go! */
          Particle.publish("PIR-Motion", "TSL2561 now online - 2/2", PRIVATE);  // informs user via Particle Cloud
          // *** TSL2561 - Ende
      }
      
      blynk_timer.setInterval(10000L, readTSL); //  Here you set interval (1sec) and which function to call - 10 sec
      particle_timer.start();
      digitalWrite(boardLed,LOW);   
      
    }
     
    // *********  

    void loop() {
        Blynk.run();
        blynk_timer.run(); // BlynkTimer is working... > readTSL
    }

    // *********

    bool calibrated() {
      return millis() - calibrateTime > 0;
    }

    // ********

    void reportPIRStatus() {
      // check the PIR-Sensor : all 1 sec
      int pirNewState = digitalRead(inputPIR);

      if (pirNewState == pirState) return; // no further action required
      pirState = pirNewState; 

      setLED(pirState);
      
      if (pirState) {
        // send events and start color fading
             if (ambientBrightness <= lightThreshold) {
                Particle.publish("PIR Motion", "LED Streifen an", PRIVATE);
                ColorFade();
             }
      }
    }

    // *********

    void setLED( int state )
    {
      digitalWrite(ledPin, state);
    }

    // *********

    void ColorFade() {

        // LED Streifen anschalten
      analogWrite(REDPIN, red); 
      analogWrite(GREENPIN, green);
      analogWrite(BLUEPIN, blue);
      
      // circa! 15 Sekunden bleibt Licht per Default an bzw. solange, wie über den Blynk Slider eingestellt wurde
      for (i = 1; i <= (delayColorFade * 100000); i++)
      
      // LED Streifen ausschalten
      analogWrite(REDPIN, 0);
      analogWrite(BLUEPIN, 0);
      analogWrite(GREENPIN, 0);
      
    }

    // ********** Neuaufnahme von Funktionen für den TSL2561 - Start

    void readTSL()
    { 

      /* Get a new sensor event */ 
      sensors_event_t event;
      tsl.getEvent(&event);
     
      /* Display the results (light is measured in lux) */
      if (event.light)
      {
        ambientBrightness = (event.light);
        Serial.print(ambientBrightness); Serial.println(" lux");
      }
      else
      {
        /* If event.light = 0 lux the sensor is probably saturated
           and no reliable data could be generated! */
        Serial.println("Sensor overload - 1 lux");
        ambientBrightness = 1; // Ersatz im Falle eines Problems
      }
        // writes the light-value from TSL2561 to V7 from Blynk-App - every timeframe the timer calls this function
        Blynk.virtualWrite(V7, ambientBrightness);
    }

    /**************************************************************************/
    /*
        Displays some basic information on this sensor from the unified
        sensor API sensor_t type (see Adafruit_Sensor for more information)
    */
    /**************************************************************************/
    void displaySensorDetails(void)
    {
      sensor_t sensor;
      tsl.getSensor(&sensor);
      Serial.println("------------------------------------");
      Serial.print  ("Sensor:       "); Serial.println(sensor.name);
      Serial.print  ("Driver Ver:   "); Serial.println(sensor.version);
      Serial.print  ("Unique ID:    "); Serial.println(sensor.sensor_id);
      Serial.print  ("Max Value:    "); Serial.print(sensor.max_value); Serial.println(" lux");
      Serial.print  ("Min Value:    "); Serial.print(sensor.min_value); Serial.println(" lux");
      Serial.print  ("Resolution:   "); Serial.print(sensor.resolution); Serial.println(" lux");  
      Serial.println("------------------------------------");
      Serial.println("");

    }

    /**************************************************************************/
    /*
        Configures the gain and integration time for the TSL2561
    */
    /**************************************************************************/
    void configureSensor(void)
    {
      /* You can also manually set the gain or enable auto-gain support */
      // tsl.setGain(TSL2561_GAIN_1X);      /* No gain ... use in bright light to avoid sensor saturation */
      //tsl.setGain(TSL2561_GAIN_16X);     /* 16x gain ... use in low light to boost sensitivity */
      tsl.enableAutoRange(true);            /* Auto-gain ... switches automatically between 1x and 16x */
      
      /* Changing the integration time gives you better sensor resolution (402ms = 16-bit data) */
      tsl.setIntegrationTime(TSL2561_INTEGRATIONTIME_13MS);      /* fast but low resolution */
      //tsl.setIntegrationTime(TSL2561_INTEGRATIONTIME_101MS);  /* medium resolution and speed   */
      //tsl.setIntegrationTime(TSL2561_INTEGRATIONTIME_402MS);  /* 16-bit data but slowest conversions */

      /* Update these values depending on what you've set above! */  
      Serial.println("------------------------------------");
      Serial.print  ("Gain:         "); Serial.println("auto");
      Serial.print  ("Timing:       "); Serial.println("13 ms");
      Serial.println("------------------------------------");
    }

Here the serial output:

/ _ )/ /_ _____ / /__

/ _ / / // / _ \/ '_/

/____/_/\_, /_//_/_/\_\

/___/ v0.5.4 on Particle Photon

[13487] Connecting to blynk-cloud.com:80

[13493] &lt;[02|00|01|00] d841b643b8fe4d45b91797928e31221d

[16495] Login timeout

[18494] Connecting to blynk-cloud.com:80

[18509] &lt;[02|00|01|00] d841b643b8fe4d45b91797928e31221d

[21511] Login timeout

[23510] Connecting to blynk-cloud.com:80

[23514] &lt;[02|00|01|00] d841b643b8fe4d45b91797928e31221d

[26516] Login timeout

[28515] Connecting to blynk-cloud.com:80

[28519] &lt;[02|00|01|00] d841b643b8fe4d45b91797928e31221d

[33520] Connecting to blynk-cloud.com:80

[33524] &lt;[02|00|01|00] d841b643b8fe4d45b91797928e31221d

When I keep the void loop() clean (without a blynk timer) I get this serial output:

[13462] Connecting to blynk-cloud.com:80

[13479] &lt;[02|00|01|00] d841b643b8fe4d45b91797928e31221d

[13494] &gt;[00|00|01|00|C8]

[13494] Ready (ping: 15ms).

[13562] &lt;[11|00|02|00]Pver[00]0.5.4[00]h-beat[00]10[00]buff-in[00]1024[00]dev[00]Particle Photon[00]build[00]Dec 28 2018 14:51:00[00]

Light Sensor Test

------------------------------------

Sensor: TSL2561

Driver Ver: 1

Unique ID: 12345

Max Value: 17000.00 lux

Min Value: 0.00 lux

Resolution: 1.00 lux

------------------------------------

------------------------------------

Gain: auto

Timing: 13 ms

------------------------------------
[13591] &gt;[00|00|02|00|C8]

[14281] &gt;[14|1E]b[00|04]

[14281] &gt;vr[00]3

[15283] &gt;[14|1E]b[00|04]

[15283] &gt;vr[00]3

[16283] &gt;[14|1E]b[00|04]

[16284] &gt;vr[00]3

[17292] &gt;[14|1E]b[00|04]

[17292] &gt;vr[00]3

[18285] &gt;[14|1E]b[00|04]

[18285] &gt;vr[00]3

[19281] &gt;[14|1E]b[00|04]

[19281] &gt;vr[00]3

[20284] &gt;[14|1E]b[00|04]

[20284] &gt;vr[00]3

[21289] &gt;[14|1E]b[00|04]

[21289] &gt;vr[00]3

[22286] &gt;[14|1E]b[00|04]

[22286] &gt;vr[00]3

[27363] Connecting to blynk-cloud.com:80

[27387] &lt;[02|00|01|00] d841b643b8fe4d45b91797928e31221d

[27405] &gt;[00|00|01|00|C8]

[27405] Ready (ping: 17ms).

[27473] &lt;[11|00|02|00]Pver[00]0.5.4[00]h-beat[00]10[00]buff-in[00]1024[00]dev[00]Particle Photon[00]build[00]Dec 28 2018 14:51:00[00]

[27489] &gt;[00|00|02|00|C8]

[28281] &gt;[14|1E]b[00|04]

[28281] &gt;vr[00]3

[29285] &gt;[14|1E]b[00|04]

[29285] &gt;vr[00]3

[30281] &gt;[14|1E]b[00|04]

[30281] &gt;vr[00]3

[35346] Connecting to blynk-cloud.com:80

[35352] &lt;[02|00|01|00] d841b643b8fe4d45b91797928e31221d

[38356] Login timeout

[40354] Connecting to blynk-cloud.com:80

[40373] &lt;[02|00|01|00] d841b643b8fe4d45b91797928e31221d

[40391] &gt;[00|00|01|00|C8]

[40391] Ready (ping: 17ms).

[40459] &lt;[11|00|02|00]Pver[00]0.5.4[00]h-beat[00]10[00]buff-in[00]1024[00]dev[00]Particle Photon[00]build[00]Dec 28 2018 14:51:00[00]

[40475] &gt;[00|00|02|00|C8]

[41285] &gt;[14|1E]b[00|04]

[41285] &gt;vr[00]3

[46319] Connecting to blynk-cloud.com:80

[46341] &lt;[02|00|01|00] d841b643b8fe4d45b91797928e31221d

[46358] &gt;[00|00|01|00|C8]

[46358] Ready (ping: 17ms).

[46426] &lt;[11|00|02|00]Pver[00]0.5.4[00]h-beat[00]10[00]buff-in[00]1024[00]dev[00]Particle Photon[00]build[00]Dec 28 2018 14:51:00[00]

[46443] &gt;[00|00|02|00|C8]

[47280] &gt;[14|1E]b[00|04]

[47280] &gt;vr[00]3

[48282] &gt;[14|1E]b[00|04]

[48282] &gt;vr[00]3

Who can interpret this?

Update 29.12.2018: The log entry are explained here:
http://docs.blynk.cc/#blynk-main-operations-devices-online-status
Reduce the time for Timer-Period to max 15 sec: read the chapter with HEARTBEAT if you have the same trouble.

Thread solved myself, Moderator can close this thread.

After a short time, the error of the “login timeout” reappeared so that I changed the light sensor: currently, an analog light sensor ALSPT19 from Adafruit records the ambient light values.

Even so, I get “login timeouts” displayed in the serialLog.
Yet it works sometimes and often not. The constant crashes annoying:

[215508] >[00|00|01|00|C8]

[215508] Ready (ping: 15ms).

[215576] <[11|00|02|00]Pver[00]0.5.4[00]h-beat[00]10[00]buff-in[00]1024[00]dev[00]Particle Photon[00]build[00]Jan 7 2019 12:47:12[00]

[215592] >[00|00|02|00|C8]

[222347] <[14|00|03|00|09]vw[00]9[00]1221

[225280] >[14]_[B5|00|09]

[225280] >vw[00]4[00]1232


1232 analog value = new Threshold for Light


[225347] <[14]_[B5|00|09]vw[00]3[00]1232

[231347] <[14|00|04|00|09]vw[00]9[00]1211

[236350] Connecting to blynk-cloud.com:80

[236367] <[02|00|01|00] 0bb22654fd0e4a3a91e24baa08aa9970

[236383] >[00|00|01|00|C8]

[236383] Ready (ping: 15ms).

[236451] <[11|00|02|00]Pver[00]0.5.4[00]h-beat[00]10[00]buff-in[00]1024[00]dev[00]Particle Photon[00]build[00]Jan 7 2019 12:47:12[00]

[236467] >[00|00|02|00|C8]

[240346] <[14|00|03|00|09]vw[00]9[00]1228

[245351] Connecting to blynk-cloud.com:80

[245355] <[02|00|01|00] 0bb22654fd0e4a3a91e24baa08aa9970

[248357] Login timeout

[250357] Connecting to blynk-cloud.com:80

[250360] <[02|00|01|00] 0bb22654fd0e4a3a91e24baa08aa9970

[253363] Login timeout

[255361] Connecting to blynk-cloud.com:80

[255365] <[02|00|01|00] 0bb22654fd0e4a3a91e24baa08aa9970

[258369] Login timeout

The code contains no delays and works otherwise.

#define BLYNK_DEBUG // Optional, this enables lots of prints
#define BLYNK_PRINT Serial

#include <blynk.h>


// Quelle:  http://diotlabs.daraghbyrne.me/7-communicating-events/pir/
//          https://learn.adafruit.com/pir-passive-infrared-proximity-motion-sensor/using-a-pir
//          https://gist.github.com/zsup/9496462
//          http://community.garadget.com/t/instructions-for-home-grown-garadget-clone/69 --> Relay Belegung und Schaltung
//          https://learn.adafruit.com/rgb-led-strips


int inputBrightness = A0;       // choose the input pin (for ALSPT19 Light - adafru.it/2748) > measure the analog voltage on the OUT pin. The voltage will increase when sensor detects more light.
int inputPIR = D4;              // choose the input pin (for PIR sensor)
int ledPin = D3;                // LED Pin
int pirState = LOW;             // we start, assuming no motion detected
int boardLed = D7;              // photon onBoard LED
int calibrateTime = 5000;       // wait for the thingy to calibrate
int lightThreshold = 100;       // brightness as analog value to decide its time for more light as analog value
int ambientBrightness;          // Here we are declaring the integer variable ambientBrightness, which we will use later to store the value of the photoresistor.
int i = 0;                      // delay-Ersatz für colorFade - for-Schleife

int red   = 255;
int green = 255;
int blue  = 255;

#define REDPIN A5
#define GREENPIN WKP   
#define BLUEPIN A4

int delayColorFade = 15;   // presents the delay for the colorFade

char auth[] = "xxx"; // cap_cow_pir_led_flur_oben
//char auth[] = "<<your blync auth-code here>>"; 

BlynkTimer blynk_timer; // Create a Timer object called "timer"! > readTSL 
    // https://community.blynk.cc/t/c-blynk-code-examples-for-basic-tasks-work-in-progress/22596/23
Timer particle_timer(1000, reportPIRStatus);

// *********    

BLYNK_WRITE(V4) // Blynk app WRITES Slider widget  
{
    lightThreshold = param.asInt();
    Serial.println("******************************");    
    Serial.print(lightThreshold);    
    Serial.println(" analog value = new Threshold for Light");    
    Serial.println("******************************");    
    Blynk.virtualWrite(V3, lightThreshold);
}

// *********  

BLYNK_WRITE(V2) // Blynk app WRITES Slider widget  
{
    delayColorFade = param.asInt(); // macht aus den Blynk-Werten millisekunden
    Serial.println("******************************");    
    Serial.print(delayColorFade);    
    Serial.println(" milli-sec = new Delay for Function ColorFade");    
    Serial.println("******************************");    
    Blynk.virtualWrite(V1, delayColorFade);
}

// *********    

BLYNK_WRITE(V0) // zeRGBa - Color
{ 
  // The param can contain multiple values, in such case:
  int red = param[0].asInt();
  int green = param[1].asInt();
  int blue = param[2].asInt();
  
  analogWrite(REDPIN, red); 
  analogWrite(GREENPIN, green);
  analogWrite(BLUEPIN, blue);
}

// ********* 

void setup() {

  Serial.begin(9600);
  digitalWrite(boardLed,HIGH);  // Now flash the D7 LED on and off 
       // Blynk magic
  Blynk.begin(auth);    // Start Blynk
  
  // if the sensor is calibrated
  if (calibrated())
  {  

      pinMode(REDPIN, OUTPUT);
      pinMode(GREENPIN, OUTPUT);
      pinMode(BLUEPIN, OUTPUT);
      
      pinMode(boardLed,OUTPUT);         // on-board LED 
      pinMode(ledPin, OUTPUT);          // control PIR LED
      pinMode(inputPIR, INPUT);         // declare sensor as input
      pinMode(inputBrightness, INPUT);  // declare sensor as input
      
      digitalWrite(boardLed,HIGH);  // Now flash the D7 LED on and off 
      Particle.publish("PIR-Motion", "PIR now online - Flur oben", PRIVATE);  // informs user via Particle Cloud
      digitalWrite(boardLed,LOW);   
     
  }
  // why use L, l, u, UL? https://www.arduino.cc/reference/en/language/variables/constants/integerconstants/
  // Heartbeat: max. 15 sec - http://docs.blynk.cc/#blynk-main-operations-devices-online-status
  blynk_timer.setInterval(9000L, readBrightness); //  Here you set interval to call the function - 9 sec
  particle_timer.start();
  digitalWrite(boardLed,LOW);   
  
}
 
// *********  

void loop() {
    Blynk.run();
    blynk_timer.run(); // BlynkTimer is working... > readBrightness
}

// *********

bool calibrated() {
  return millis() - calibrateTime > 0;
}

// ********

void reportPIRStatus() {
  // check the PIR-Sensor : all 1 sec
  int pirNewState = digitalRead(inputPIR);

  if (pirNewState == pirState) return; // no further action required
  pirState = pirNewState; 

  setLED(pirState);
  
  if (pirState) {
    // send events and start color fading
         if (ambientBrightness <= lightThreshold) {
            Particle.publish("PIR Motion", "LED Streifen an", PRIVATE);
            ColorFade();
         }
  }
}

// *********

void setLED( int state )
{
  digitalWrite(ledPin, state);
}

// *********

void ColorFade() {

    // LED Streifen anschalten
  analogWrite(REDPIN, red); 
  analogWrite(GREENPIN, green);
  analogWrite(BLUEPIN, blue);
  
  // circa! 15 Sekunden bleibt Licht per Default an bzw. solange, wie über den Blynk Slider eingestellt wurde
  for (i = 1; i <= (delayColorFade * 100000); i++)
  
  // LED Streifen ausschalten
  analogWrite(REDPIN, 0);
  analogWrite(BLUEPIN, 0);
  analogWrite(GREENPIN, 0);
  
}

// ********** Neuaufnahme von Funktionen für den TSL2561 - Start

void readBrightness()
{ 
 // read the input on analog pin A1:
 // 0-3.3V input and 0-4095 range
 // https://docs.particle.io/reference/device-os/firmware/photon/#analogread-adc-
  int ambientBrightness = analogRead(inputBrightness);
  
  if (ambientBrightness)
  {
  // print out the value you read:
    //Serial.println(ambientBrightness);  
    // writes the light-value from ALSPT19 to V9 from Blynk-App - every timeframe the timer calls this function
    Blynk.virtualWrite(V9, ambientBrightness);
  }
  else
  {
    Serial.println("Sensor ALSPT19 Light - reading error");
  }
    
}

I do not know what to do - ask for help.
Bump this thread: can anyone interpret the log?

Update 17.01.19: My workaround at this point to solve my issues: I used an older Blynk-Lib version (0.4.7 instead 0.5.4).