# Web IDE will not flash latest code to Photon

**URL:** <https://community.particle.io/t/web-ide-will-not-flash-latest-code-to-photon/23514>\
**Category:** Troubleshooting\
**Created:** [June 6, 2016, 9:56pm UTC](https://community.particle.io/t/web-ide-will-not-flash-latest-code-to-photon/23514 "2016-06-06T21:56:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ashiundar](https://avatars.discourse-cdn.com/v4/letter/a/8c91f0/32.png) [@ashiundar](https://community.particle.io/u/ashiundar)\
**Post date:** [June 6, 2016, 9:56pm UTC](https://community.particle.io/t/web-ide-will-not-flash-latest-code-to-photon/23514/1 "2016-06-06T21:56:02Z")

</div>

Hi guys,

I’m trying to flash some new firmware to my Photon, but the newest code will not flash. I’m making small iterative changes to the code each time, but it seems like a crap shoot whether the new firmware (which I have saved a compiled) will actually flash.

Here’s my code. The relevant section is all the way at the bottom, in particular the final if statement. Apologize for the messiness, it’s still a work in progress:

```cpp
    #include <math.h>
    #include <Particle.h>
    
    // int's in C++ cannot have numbers in their name. Hence the bizarre nomenclature. 
    int XAccel; // x acceleration from the ADXL335
    int YAccel; // y acceleration from the ADXL335
    int ZAccel; // z acceleration from the ADXL335
    int VOut; // voltage output of the ADXL335
    //
    double thermistorAnalog; // contains raw analog data from thermistor circuit VOut
    double thermistorResistance; // converts analog reading to resistance
    double temperature; // converts thermistor resistance to temperature, according to Amphenol datasheet 
    int EKG; // analog reading of EKG
    String tempData = "0"; // stores temperature data as a large block
    
    void setup()
    {
    
     // Let's register some Particle variables to the Particle cloud.
     // This means when we "ask" the Particle cloud for the string in quotes, we will get
     // the value after the comma. Note: The published variable name in quotes AND the
     // actual variable name MUST be 12 characters or less. Otherwise, the cloud will
     // ignore the variable and you won't be able to see it when you make a request.
    
     Particle.variable("XAccel", XAccel);
     Particle.variable("YAccel", YAccel);
     Particle.variable("ZAccel", ZAccel);
     Particle.variable("VOut", VOut);
     Particle.variable("EKG", EKG);
     Particle.variable("temp", temperature); // temp in Celsius
    }
    
    void loop()
    {
     // read the raw ADXL335 acceleration using analogRead().
     XAccel = analogRead(A2);
     YAccel = analogRead(A1);
     ZAccel = analogRead(A0);
     
     // determine the reference voltage by querying VOut on A3
     VOut = analogRead(A3);
     
     // read the raw thermistor analog data
     thermistorAnalog = analogRead(A5);
     thermistorResistance = (10000*thermistorAnalog/4096)/(1-thermistorAnalog/4096);
     // calculated temperature by plotting a line of best fit using linear algebra and MATLAB. Error was found to be 3.7998*10^-4 Kelvins using Igor Pro. 
     temperature = pow((1.1106*.001 + 2.3724*.0001*log(thermistorResistance) + 7.4738*.00000001*pow(log(thermistorResistance), 3)), -1) - 273.15;
     
     tempData += ",";
     tempData += String(temperature);
     delay(250);
     
     if (tempData.length() > 5) // Once the chunk reaches a certain size, send it. 
     {
        Particle.publish("Temps1", String(tempData));
        tempData = "";
     }
     // read the EKG, connected to A4 of the Photon. 
     EKG = analogRead(A4);
    }

```

In a nutshell - I’m gathering some data from sensors and publishing them to the cloud. Initially I was doing this using Particle.variable(), but now I’d like to experiment with publishing in bulk using Particle.publish().

The reason I know that my new code is not being uploaded, is when I subscribe to the datastream, the title of my publish variable is “Temps”, and not “Temps1” as indicated in the code. This means that the Photon is running my old code (which had a variable called “Temps”), but not the newest code.

Here are the steps I’m taking when flashing the Photon.

1. Press Cmd+S to save the firmware.
2. After seeing confirmation that firmware was saved, click Verify.
3. After seeing confirmation that firmware successfully compiled, click Flash.
4. Photon flashes Magenta for a few seconds, then Green, then breathes Cyan (not Blue). After about 10 seconds, the Photon will suddenly flash Blue for about a second, then return to breathing Blue. Web IDE console says “Ready” with no triangular exclamation marks.

---

<div class="post-metadata">

**Author:** ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)\
**Post date:** [June 7, 2016, 11:46am UTC](https://community.particle.io/t/web-ide-will-not-flash-latest-code-to-photon/23514/2 "2016-06-07T11:46:40Z")

</div>

One thing that pops to mind is that you seem to violate the rate limit for `Particle.publish()`

[https://docs.particle.io/reference/firmware/photon/#particle-publish-](https://docs.particle.io/reference/firmware/photon/#particle-publish-)

> [@](#):
>
> NOTE: Currently, a device can publish at rate of about 1 event/sec, with bursts of up to 4 allowed in 1 second. Back to back burst of 4 messages will take 4 seconds to recover.

Try to increase your `delay(250)` to `delay(1000)` and see if that helps.

Also try to put your device into Safe Mode before you do your flashing, to ensure that your previous code doesn't interfere with the flashing process.

* * *

Some coding hints:

```cpp
     temperature = pow((1.1106*.001 + 2.3724*.0001*log(thermistorResistance) + 7.4738*.00000001*pow(log(thermistorResistance), 3)), -1) - 273.15;

```

In this term you'll add extra rounding errors due to the multiple multiplications. Each of your number literals will have an error due to the binary representation of floating point numbers and with each multiplication you'll add to that, so rather try this.

```cpp
    temperature = pow((0.0011106 + 0.00023724*log(thermistorResistance) + 0.000000074738*pow(log(thermistorResistance), 3)), -1) - 273.15;
    // or even better/shorter
    temperature = pow((1.1106E-3 + 2.3724E-4 * log(thermistorResistance) + 7.4738E-8 * pow(log(thermistorResistance), 3)), -1) - 273.15;

```

And for the sake of nit picking: The mathematical correcter calculation would be

```cpp
   thermistorResistance = (10000*thermistorAnalog/4095.0)/(1-thermistorAnalog/4095.0);

```

but in this case the divisor would need to be kept `!= 0` to avoid a zero-div exception (SOS Usage Fault)

* * *

BTW: We are used to call the color you see when the device is connected _cyan_ to distinguish it from _blue_ as it would be in Listening Mode.

---

<div class="post-metadata">

**Author:** ![ashiundar](https://avatars.discourse-cdn.com/v4/letter/a/8c91f0/32.png) [@ashiundar](https://community.particle.io/u/ashiundar)\
**Post date:** [June 8, 2016, 9:05pm UTC](https://community.particle.io/t/web-ide-will-not-flash-latest-code-to-photon/23514/3 "2016-06-08T21:05:25Z")

</div>

Thanks for the reply, lots of good stuff in your post.

> [@ScruffR](#):
>
> One thing that pops to mind is that you seem to violate the rate limit for `Particle.publish()`
> 
> Try to increase your `delay(250)` to `delay(1000)` and see if that helps.

I changed the delay so I don't violate the max publish rate.

> [@](#):
>
> Also try to put your device into Safe Mode before you do your flashing, to ensure that your previous code doesn't interfere with the flashing process.

I'll give this a try and see if it helps.

> [@](#):
>
> * * *
> 
> Some coding hints:

```cpp
     temperature = pow((1.1106*.001 + 2.3724*.0001*log(thermistorResistance) + 7.4738*.00000001*pow(log(thermistorResistance), 3)), -1) - 273.15;

```

> [@](#):
>
> In this term you'll add extra rounding errors due to the multiple multiplications. Each of your number literals will have an error due to the binary representation of floating point numbers and with each multiplication you'll add to that, so rather try this.

```cpp
    temperature = pow((0.0011106 + 0.00023724*log(thermistorResistance) + 0.000000074738*pow(log(thermistorResistance), 3)), -1) - 273.15;
    // or even better/shorter
    temperature = pow((1.1106E-3 + 2.3724E-4 * log(thermistorResistance) + 7.4738E-8 * pow(log(thermistorResistance), 3)), -1) - 273.15;

```

Good point, in the back of my mind I was uncomfortable with having so many operations. Your explanation makes sense.

> [@](#):
>
> And for the sake of nit picking: The mathematical correcter calculation would be

```cpp
   thermistorResistance = (10000*thermistorAnalog/4095.0)/(1-thermistorAnalog/4095.0);

```

> [@](#):
>
> but in this case the divisor would need to be kept `!= 0` to avoid a zero-div exception (SOS Usage Fault)

The denominator should never go to zero, since thermistorAnalog won't ever actually touch 4095. For that to happen, either the thermistor has to have zero resistance (which cannot happen due to the nature of resistors/wires) or there is a short in the thermistor circuit. I suppose the second case actually might be plausible, so I'll place this segment into a tiny if statement to protect it from bad math.

> [@](#):
>
> BTW: We are used to call the color you see when the device is connected _cyan_ to distinguish it from _blue_ as it would be in Listening Mode.

Lol I was trying to remember the name of that light bluish color, and just went with blue. I'm a guy, I have like a total of four colors in my color repertoire lol
