Photon keeps flashing lights and having to reconnect since Blynk

Hi,

Since I put the Blynk code in my app the Photon keeps going into this series of fast blinking lights.
It almost appears to happen when I turn on the Android client side. It blinks fast white, then fast green and finally fast cyan and then settles down to the pulse (breathing).
Is this normal behavior or do I have a coding problem?

No, this shouldn’t happen. Please post your code!

I am using a delay(12000) to avoid overruns, should I use a timer instead?

/* This function is called once at start up ----------------------------------*/
void setup()
{
Particle.function(“controlRelay”, triggerRelay);
Serial.begin(9600);
// delay(5000);

Blynk.begin(auth);
while (Blynk.connect() == false) {

// Wait until connected
}
sensor.begin();
relayController.setAddress(0,0,0);
// To change resolution of the sensor use
// sensor.changeResolution(int i) where i=[0-3],
//sensor.changeResolution(0);
Spark.variable(“number”, &number, INT);
}

/* This function loops forever --------------------------------------------*/
void loop()
{

Blynk.run();  // Run Blynk for Android interface
delay(12000);

/* Added temp coding below -------------------------------------*/
if(curtemp = tempController.temperatureF()){

  Serial.print("F Temp: ");  //  Tempurature
  Serial.println(curtemp);  //  Tempurature test

// Blynk.virtualWrite(V1, curtemp);

   if (curtemp < 78.0){
    relayController.turnOnRelay(1);
    relayController.turnOffRelay(3);

// Blynk.virtualWrite(D6, HIGH);
// led1.setValue(249);
// led2.setValue(0);
led1.on();
led2.off();
}else{
relayController.turnOnRelay(3);
relayController.turnOffRelay(1);
// led1.setValue(0);
// led2.setValue(249);
led1.off();
led2.on();
}
}
Serial.println(“before”);
Blynk.virtualWrite(V1, curtemp);
Serial.println(“after”);

@RPM99 delay(12000) is a sure fire way to kill your Blynk connection. Blynk has a 5 to 10 second timeout depending which version you are using. You need to use timer and your loop should look like this when you have fixed your code.

void loop()
{
  Blynk.run();
  timer.run();
}
I downloaded SimpleTimer.cpp,SimpleTimer.h and led.ino from gethub (jfturcot/SimpleTimer).

They also required WProgram.h , I wonder if I have the correct one?
It has the following includes which I do not have on my machine, I am using Particle dev on my PC

#include <stdint.h>
#include <stdlib.h>
#include <string.h>

These programs do not compile and simpletimer.cpp is not so simple.
Generates 8 errors that I am not able to fix, hope you can help?

This accounts for 7 of the 8 errors:
‘enabled’ was not declared in this scope SimpleTimer.cpp 39:9
Lines 27 thru 46:
#include “SimpleTimer.h”

// Select time function:
//static inline unsigned long elapsed() { return micros(); }
static inline unsigned long elapsed() { return millis(); }

SimpleTimer::SimpleTimer() {
    unsigned long current_millis = elapsed();

    for (int i = 0; i < MAX_TIMERS; i++) {
        enabled[i] = false;
        callbacks[i] = 0;                   // if the callback pointer is zero, the slot is free, i.e. doesn't "contain" any timer
        prev_millis[i] = current_millis;
        numRuns[i] = 0;
    }

@RPM99 Blynk provide SimpleTimer on their Github. Download the full zip of the latest (none beta) of Blynk at https://github.com/blynkkk/blynk-library/releases/download/v0.3.1/Blynk_v0.3.1.zip

Unzip and one folder is SimpleTimer.
Not sure how the Photon uses libraries but for Arduino 1.6.5 it is:

  1. Additional libraries are in the libraries directory of your sketchbook directory. Sketchbook directory is found from File, Preferences in the IDE.

  2. Close the IDE.

  3. Paste the library into your libraries directory and reopen the IDE.

Maybe if you can do similar for the Photon and then let us know if you still have error messages.

Hello,
I get the same results.
The 2 files in the simpletimer directory are the same as the one I downloaded.

SimpleTimer.h file has an #include “WProgram.h”
This file is not in the blynk download, I had to use the one I found on github.

Simpletimer.h has the following line that creates error.

lines 70-71:

  // returns true if the specified timer is enabled
    boolean isEnabled(int numTimer);

Returns error:
boolean does not return a type

simpletimer.cpp has the folowing line that generates an error:
Lines 35-46:
SimpleTimer::SimpleTimer() {
    unsigned long current_millis = elapsed();

    for (int i = 0; i < MAX_TIMERS; i++) {
        enabled[i] = false;
        callbacks[i] = 0;                   // if the callback pointer is zero, the slot is free, i.e. doesn't "contain" any timer
        prev_millis[i] = current_millis;
        numRuns[i] = 0;
    }

    numTimers = 0;
}

Generates error:
'Enabled" was not declared in this scope

Thanks,
Steve

@RPM99 I did a file comparison and you appear to have the correct SimpleTimer. The WProgram.h and the associated Arduino.h is a throwback to changes in the Arduino IDE (I forget the version details but that’s not important).

Photon’s are different to Arduinos and the boolean issue should be fixed by using application.h with the Photon. Maybe take a look at this post https://community.particle.io/t/moving-from-arduino-to-photon-where-are-the-differences-called-out/12045/4

Any timer will do and I believe Photon’s have their own interrupt timers. Maybe look at this one https://github.com/pkourany/SparkIntervalTimer if you can’t fix SimpleTimer for the Photon.

Hi. I thing you need to to switch to SparkCorePolledTimer library on the Core/Photon.

Added a comment in https://github.com/vshymanskyy/blynk-library-spark/blob/master/firmware/examples/01_Particle/01_Particle.ino

BTW, this topic is related: