What are simple steps to update firmware on Particle Photon?

Could someone guide me with simple steps to update firmware on Particle Photon? My current version is 0.6.2. The reason for update - the board loses connectivity quite often and does not regain it automatically.
I will appreciate any help!

@markiz, almost 100% of the time, the issue you are having is related to user code. Perhaps posting your code is the place to start.

2 Likes

Sorry if I wasn’t clear with my question. I will try again:

What are steps to upgrade firmware from ver 0.6.2 to 0.7.0-rc3?

Thank you!

What @Peekay123 is trying to tell you is that the firmware upgrade will not fix your problem because of the 0.6.2 firmware does not have issues that cause frequent wifi connectivity loss.

So instead of hoping the new firmware fixes your problem he’s suggesting you post your code if you really want to solve your problem assuming it’s not caused by being too far away from your Wifi router.

And to update your firmware on a Photon you simply select what version of the firmware you want to load on the Photon via the drop down list as shown below when using the Particle Build Online IDE:

Got it - thank you!
My router is not far at all. The signal by the board is as strong as it can be. I tried different router with the same results.
Here is my code:

//Instantiate a servo object
Servo myServo;
//Declare pin variable
int myServoPin;
//Declare current position variable
int myServoCurrPos;

void setup()
{
    //Assign pin
    myServoPin = D0;
    
    //Register Particle functions
    Particle.function("blockSun", blockSun);
    Particle.function("closeBlinds", closeBlinds);
    Particle.function("openBlinds", openBlinds);
}

void loop()
{
}

void moveServoTo(int position)
{
    myServo.attach(myServoPin);
    
    myServo.write(position);
    
    //Waiting for servo to move to position
    delay(9000);
    
    //save current position
    myServoCurrPos = position;
    
    myServo.detach();
}

int blockSun(String command)
{
    moveServoTo(0);
    return 1;
}

int closeBlinds(String command)
{   //to set run range between closeBlinds and blockSun 
    moveServoTo(110);
    return 1;
}

int openBlinds(String command)
{
    if (myServoCurrPos == 0) 
    {   //to set run range between blockSun and openBlinds - to be adjusted along with line 58
        moveServoTo(55);
    }
    else if(myServoCurrPos == 110) //fully closed
    {   //to set run range between closeBlinds and openBlinds - to be adjusted along with line 54
        moveServoTo(25);
    }
    return 1;
}

One thing I can think of is the fact that you shouldn’t block a function for too long and should try to have it return as quickly as possible.
Try moving the logic to the loop and only set ‘flags’ in the functions.

I am not sure I understand the comment. Could you elaborate?

The way to handle functions that need to return quickly, like function handlers, ISRs, etc., is to have a flag (just a global variable of some sort) that you set in the handler, then check in loop to decide what to do. In your case, I would use a single Particle.function (3 is fine if that’s what you prefer) to which I send the command of 1, 2, or 3 to distinguish among the three actions you want. The flag would be an Int variable (blindsCommand in my example) so you could use a switch statement in loop to decide what action to take. Something like this,

Int blindsCommand;

void loop() {
	switch (blindsCommand) {
		case 1:
			moveServoTo(0);
			break;
		case 2:
			moveServoTo(110);
			break;
		case 3:
			if (myServoCurrPos == 0) {
	        	moveServoTo(55);
				break;
	    	} else if(myServoCurrPos == 110) {
	        	moveServoTo(25);
				break;
	    	}
	}
}

void moveServoTo(int position) {
	blindsCommand = 0; // reset to 0 so no further action occurs in loop until a new valid command is received
    myServo.attach(myServoPin);
    myServo.write(position);
    delay(9000);
    myServoCurrPos = position;
    myServo.detach();
}

int moveBlinds(String cmd) { // cmd=1 for blockSun, cmd=2 for closeBlinds, cmd=3 for openBlinds
	blindsCommand = cmd.toInt();
	if (blindsCommand > 0 && blindsCommand < 4) { // make sure we received a 1,2, or 3
		return 1;
	}
	return -1;
}

To make your code more readable, you could add an enum so that you could use names rather than 1,2, or 3 in the switch statement.

enum commands {doNothing, blockSun, closeBlinds, openBlinds};

void loop() {
	switch (blindsCommand) {
		case blockSun:
			moveServoTo(0);
			break;
		case closeBlinds:
			moveServoTo(110);
			break;
		case openBlinds:
			if (myServoCurrPos == 0) {
	        	moveServoTo(55);
				break;
	    	} else if(myServoCurrPos == 110) {
	        	moveServoTo(25);
				break;
	    	}
	}
}
2 Likes

Thank you so much Ric! New code is flashed in. Let see what happens…

1 Like

It is still happening - it is still randomly loses connectivity

If you’re using my code, there shouldn’t be anything in there to cause disconnects. You could try adding a SYSTEM_THREAD(ENABLED) , but I’m not confident that it will help. Are you still getting similar times and frequencies of disconnects?

Did you try to do what Moors7 suggested?
Specifically when he states “One thing I can think of is the fact that you shouldn’t block a function for too long and should try to have it return as quickly as possible.”

your delay(9000); is most likely the culprit here. You need to implement a different way to implement that delay.

1 Like

Your code works perfectly. Yes, I am getting similar frequencies of disconnects