Particle Photon Won't connect to WiFi after a Flashing Code


My particle photon connects to the network just fine, allowing me to flash my code to it through the web IDE. However, once my flash is complete, the particle attempts to connect (flashing green LED status) and then it eventually goes to offline mode( breathing white LED status). My firmware calls Particle.publish(), so I need the photon connected to the cloud (breathing cyan LED status). I am following the approach in the link to achieve functionality where my code will run while offline and attempt to reconnect every 5 minutes. The following is my setup() function:

void setup() {
    //setup serial output 
    //configure button
    if (!waitFor(Particle.connected, msRetryTime)){  //msRetryTime is 30000ms;                // no luck, no need for WiFi
        Serial.println("Not connected in setup loop");
        Serial.println("Connected in setup loop");
    // Initialize the gps and turn it on
	//Initialize the UV sensor
    // Handler for response from POSTing location to server
    //Particle.subscribe("hook-response/record", responseHandler, MY_DEVICES);
    Particle.subscribe("hook-response/thresh", threshHandler, MY_DEVICES);
    Particle.subscribe("hook-response/record", storeStatus, MY_DEVICES);

    //start setting executeStatemachine flage to true every 10ms

I am a newbie and was hoping to get some tips on how I may debug this problem.


Suggest you try adding #include “Particle.h”

at the start.
If you have not specified a SYSTEM_MODE(); then it defaults to AUTOMATIC and in which case Particle.connect(); in setup is not required, also it is not clear why you want to turn off the WiFi module. Just do a waitFor(Particle.connected, msRetryTime); and put any subscribes immediately after that.


It was a random error. I changed nothing and everything now works as expected.


theres a link to my current code if you are interested to see what I am doing


You can actually put Particle.subscribe() before Particle.connect() as it won’t need a valid connection in order to tell the device what should be registered with the cloud once the connection gets established.

@sh256-oss, in your code I can see that you have the sources for AdafruitVEML6070 and also the library Adafruit_VEML6070 imported. This will most likely produce loads of multiple definition errors.

Also, I’d not import the Arduino library. The Partilcle device OS repo freatures its own Arduino.h which will be much more compatible with the Particle ecosystem than any 3rd party library.
Especially given that this library is 4 years old and it doesn’t really define any of the macros a “proper” Arduino.h would need to define.


This was a very hacky solution to a really annoying problem when just trying to import Adafruit_VEML6070 through the web IDE. I can’t remember the specifics, but I do remember getting a lot of multiple definiton errors. The current code works without any problem.


It was a random error. I changed nothing and everything now works as expected.

That is a bit weird. Which version of device OS are you using?

Generally with SEMI_AUTOMATIC you have to connect and then it will reconnect automatically. So in setup WiFi.connect(); then waitFor(WiFi.ready, waitTime); then if (WiFi.ready) try Particle.connect();

@sh256-oss are you familiar with using vector and deque - I am curious whether these are required for these libraries VEML6070 etc.


I’m not sure what device OS I am using, but I’m fairly sure that the vector and deque libraries are not required by VEML6070. I am just using them because they help for dynamic storage elements and not having to allocate and delete memory etc.


So is ActivityLogger something you have written or are you trying to port into Particle?

If you look under the device with the star highlighted you can see the version of device OS targeted.
This should also be shown bottom right of the web IDE screen - device name and device OS.