"Your Particle Photon is not in network" - try shorter delay

I was having lots of issues with Blynk, getting mostly “Your Particle Photon is not in network” messages. I think I stumbled on something that (so far) seems to help. Maybe this will help someone else, or at least anyone new to this like I am.

I was positive the Photon was working properly and was connected to my network (I’m not sure what network the warning refers to), I had the most current Blynk software from Particle in my sketch and from the Play Store on my phone, I tried logging off/on, I removed/reloaded the Blynk app on my phone, and I regenerated Blynk auth tokens and ensured I was using the new one in my sketch. Nada.

Trying to figure things out, I made a very simple program with one parameter; temperature readings from a TMP36 sensor. My troubleshooting sketch is below. The problem seemed to be in having too long of a delay in my code. I sped up the delay in my code from 60s to 5s and then set my Blynk “Reading Frequency” to match. It seems to have solved the problem. I hope this helps someone else avoid the frustration I was having.

#include “blynk/blynk.h”
char auth[] = “d75cbwouldntyouliketoknow5a68aa61”;
const int pipePin = A1;
int pipef;
void setup()
{
Blynk.begin(auth);
pinMode(A1, INPUT);
}
void loop()
{
Blynk.run();
pipef = ((((((analogRead(pipePin) * (3.3/4095)) 1000.0) - 500)/10)(9.0/5.0)) + 32.0);//convert it to F
Blynk.virtualWrite(V1, pipef);
delay (5000);//was originally set to 60000
}

NO DELAYS in loop!

Use Particles equivalent of SimpleTimer to call functions at intervals.

NO DELAYS ANYWHERE with ESP’s.

Thanks, @Costas. I’ll do a little research to see what you’re talking about. As I said, all this is new to me.

This seems to work - matching my serial monitor perfectly - although I’m sure someone with experience could do better.

#include “blynk/blynk.h”
char auth[] = “d75cbuseyourowndamncode8aa61”;
const int pipePin = A1;
int pipef;
unsigned long old_time = 0;
void setup()
{
Blynk.begin(auth);
pinMode(A1, INPUT);
}
void loop()
{
Blynk.run();
if(millis() - old_time >= 5000){
pipef = ((((((analogRead(pipePin) * (3.3/4095)) 1000.0) - 500)/10)(9.0/5.0)) + 32.0);//convert it to F
Blynk.virtualWrite(V1, pipef);
old_time = millis();
}
}

In the PushData example for Blynk there is a library called SimpleTimer. This library can run timed functions for you. It will solve everything and make it work nice and stable. I’m not sure it’ll run on the Particle since they have their own timer thing for that I believe, but I’ve seen it mentioned on the forum here.

The key to a stable Blynk solution is to only run Blynk and some timer thing on the loop and nothing else. Move all the logic in to separate functions.

Thanks, @Lichtsignaal. I’ll have to dig a little deeper when time permits. So far my revised code is working flawlessly. And with the historical graphing feature in Blynk I’ve been able to eliminate phant posts. With a simple device and the help of Blynk I can tell when a toilet flushes in a house! That’s not the primary purpose of my device but it shows the power of this stuff. Having fun…

2 Likes

Well, I certainly haven’t seen it being used for such a “shitty” job :smiley: I love it.

4 Likes

:joy:

1 Like

Although I have used it on other devices, I have not had much luck using SimpleTimer on a Particle Photon - maybe libraries not updated or some such black magic? I have gone back to using the millis() functions and a simple check like in the code above and all is working well.

But as was said above - do not put any delays into the loop subroutine.

1 Like