Blynk - Photon is offline

I find no explanation for this situation: my circuit with the photon is running and displays the curve using the light sensor (TSL2561) on the Blynk app. The used Blynk and Particle timers also work - so far so good.
Nevertheless, the Blynk app indicates that my "photon is offline"! The auth-code is correct - in the Serial.Log from Blynk I find timeouts. Even the replacement of the photon did not succeed.

https://go.particle.io/shared_apps/5bf9dc704b3b1e270e000605

I’ve posted this thread in the Blynk forum and now have timers in use, as the loop loop to overload.
Someone Blynkers an idea?

Are you able to stay connected to Particle Cloud when you disconnect from Blynk?

Hi @k0d3x,
yep, Particle Cloud works - in the console I see the fired events “PIR Motion” from function reportTheData (). What is your guess?

I had problems with the Blynk timers. To get reliable connections I had to use millis timers.

hey @Postler

I originally thought that you were connected to the Internet but, not connected to the Particle Cloud. This happened to me with Blynk. I can not test right now, but you can try moving blynk_timer.setInterval(5011L, readTSL) out of the if statement that calibrates the sensor. Place it in the setup function. I think that the Blynk timer is only working if the sensor is calibrated.

I have implemented your hints, but it is the same as before. The status of the device has changed to white and gray, but is not constantly online.

The mystery lies in the fact that the light sensor delivers values for the graph every 5 seconds (after the change in millis <1 sec), although the photon seems to be offline. In any case, changes to the two sliders within the app are not updated because “Device offline”.

@Postler, you invited me to this thread, so here are my first impressions

You are calling some functions that use delay() from within a timer callback. This is no good practice and may have unwanted side effects.

  1.011s Software Timer -> reportTheData() -> ColorFade() -> delay(delayColorFade * 1000)

When using timers, the timer callbacks mustnot use any delays anywhere near the timer periode.

Some unrelated hints:
If you use meaningful variable names you can avoid the need for comments like this

        if (analogvalue /*light*/ <= light_threshold) {

When using lightValue or ambientBrightness instead of analogvalue the meaning of the condition becomes clear without the need for the inline comment.
Similarly the use of val and pirState actually obscure their relation. If you use pirNewState and pirState the relation becomes obvious and also helps figuring out that the following code could be streamlined since it actually only should be executed when pirNewState != pirState.

void reportTheData() {
  int pirNewState = digitalRead(inputPin);

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

  setLed(pirState);
  if (pirState) {
    // send events and start color fading
  }
}

Also try to stick with one kind of variable naming scheme (e.g. analogvalue vs. light_threshold vs. calibrateTime …).

Instead of publishing four events in sequence (which may also result in a rate limit violation when timers get called back to back) like here

    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(); 
    }

Try to incorporate all data into only one event.

  char data[128];
  ...
  snprintf(data, sizeof[data]
          , "Motion detected (%d <= %d -> LED Streifen %s)"
          , lightValue, lightThreshold, (lightValue <= lightThreshold) ? "an" : "aus");
  Particle.publish("PIR Motion", data, PRIVATE); 

Also function names like reportTheData() appear to be meaningful, but “the data” doesn’t really give away what kind of data will be reported.

3 Likes

Thank you for the effort with the listing of the individual points. I’ve done that today and implemented.

Actually, the query of the PIR and the switching on of the LED strip works,
but I still have my problems with Blynk (= offline, disconnected, sometimes online).
Like to verify the code again?
https://go.particle.io/shared_apps/5c255169c28e307815000897

The time for the activation of the LED strip in ColorFade() I have implemented
instead of a delay with a for-counter. I also tried a timer without success.

This might be a question for the Blynk community and their support.
They should know best how they determine the online/offline state.

1 Like

After reviewing the Blynk forum with the same login timeout issues, I came across an explanation of the log: the heartbeat process fails when the timer runs for> 15 seconds. I would only have asked this every minute and now every 10 seconds. Is working.
Happy and grateful I am also for the use of this forum! Thank you and happy new year.

Details to Blynk-Heartbeats here:
http://docs.blynk.cc/#blynk-main-operations-devices-online-status

1 Like