WebIDE: compile error: could not compile. please review your code

Hey guys, I’ve been programming photons for the last 2 months, and today I got an strange error. When I try to compile any code that I have, even with example codes I get “Error: Could not compile. Please review your code.”.

I was searching in this forum and saw that sometimes the particle build server crushes or runs out of memory, but I don’t know if that’s what’s happening right now, any ideas?.

Thanks in advanced.

Pablo.

NOTE: It only happens with one of my photon, when I change the “device to be flashed” I’m able to compile. Does this mean that mi photon is broken? If that’s so…how can I reset to factory settings?.

Do you not get any error message?
What IDE are you using?

When you say

I'd suspect your target firmware version for the two devices is different. Using features that only got introduced later targeting an older version would fail.

Hey ScruffR,

I’m using windows Web IDE, the version 0.4.9. I typed trough a serial terminal “v” in setup mode to know the firmware of the board (Photon) and it says “system firmware version: 0.4.9”, so I guess everything’s fine about that.

Now I realize that the code, when is uploaded to a board it makes the IDE “crush”, actually I took a new board and the code compiled with no problems, but after the code was uploaded automatically the same error appeared, and now I have two boards that can’t compile anymore.

Here’s my code, maybe is bit to long, butI hope you can gave me a hand about this problem:

#include "math.h"

String tiempo = "0";
String mes_actual = "0";
String mes_anterior = "0";
String dia_actual = "0";

int ledboard = D7;      // señaliza operaciones
double corrienteF1 = A0;   // lectura de valor analógico
double corrienteF2 = A1;   //
double corrienteF3 = A2;
double I1 = 0;
double I2 = 0;
double I3 = 0;
double Pot = 0;
double Energy = 0;
double Energy_dia = 0;
double Energy_8bits = 0;    // Para energía guardada de meses
double Energy_7bits = 0;    // Para energía guardada de días

int addr_Jan = 1;
int addr_Feb = 2;
int addr_Mar = 3;
int addr_Apr = 4;
int addr_May = 5;
int addr_Jun = 6;
int addr_Jul = 7;
int addr_Aug = 8;
int addr_Sep = 9;
int addr_Oct = 10;
int addr_Nov = 11;
int addr_Dec = 12;

int addr_Mon = 14;
int addr_Tue = 15;
int addr_Wed = 16;
int addr_Thu = 17;
int addr_Fri = 18;
int addr_Sat = 19;
int addr_Sun = 20;

String I1_table = "0";
String I2_table = "0";
String I3_table = "0";
String Pot_table = "0";
String Energy_table = "0";
String Energy_table_dia = "0";

String Energy_Jan = "0";
String Energy_Feb = "0";
String Energy_Mar = "0";
String Energy_Apr = "0";
String Energy_May = "0";
String Energy_Jun = "0";
String Energy_Jul = "0";
String Energy_Aug = "0";
String Energy_Sep = "0";
String Energy_Oct = "0";
String Energy_Nov = "0";
String Energy_Dec = "0";

String Energy_Mon = "0";
String Energy_Tue = "0";
String Energy_Wed = "0";
String Energy_Thu = "0";
String Energy_Fri = "0";
String Energy_Sat = "0";
String Energy_Sun = "0";



unsigned long t1 =0;
unsigned long t2 =0;
unsigned long t3 =0;



void setup() {

    pinMode(ledboard,OUTPUT);
    pinMode(corrienteF1,INPUT);
    pinMode(corrienteF2,INPUT);
    pinMode(corrienteF3,INPUT);

    digitalWrite(ledboard,HIGH); // Prende LED como inicio de SETUP
    
    Particle.variable("I1", &I1, DOUBLE);
    Particle.variable("I2", &I2, DOUBLE);
    Particle.variable("I3", &I3, DOUBLE);
    Particle.variable("Pot", &Pot, DOUBLE);
    Particle.variable("Energy", &Energy, DOUBLE);
    Particle.variable("Energy_dia", &Energy, DOUBLE);

    Particle.variable("I1_table", &I1_table, STRING);
    Particle.variable("I2_table", &I2_table, STRING);
    Particle.variable("I3_table", &I3_table, STRING);
    Particle.variable("Pot_table", &Pot_table, STRING);
    Particle.variable("Energy_table", &Energy_table, STRING);
    Particle.variable("mes_actual", &mes_actual, STRING);
    Particle.variable("Energy_table_dia", &Energy_table_dia, STRING);
    
    Particle.variable("Energy_Jan", &Energy_Jan, STRING);
    Particle.variable("Energy_Feb", &Energy_Feb, STRING);
    Particle.variable("Energy_Mar", &Energy_Mar, STRING);
    Particle.variable("Energy_Apr", &Energy_Apr, STRING);
    Particle.variable("Energy_May", &Energy_May, STRING);
    Particle.variable("Energy_Jun", &Energy_Jun, STRING);
    Particle.variable("Energy_Jul", &Energy_Jul, STRING);
    Particle.variable("Energy_Aug", &Energy_Aug, STRING);
    Particle.variable("Energy_Sep", &Energy_Sep, STRING);
    Particle.variable("Energy_Oct", &Energy_Oct, STRING);
    Particle.variable("Energy_Nov", &Energy_Nov, STRING);
    Particle.variable("Energy_Dec", &Energy_Dec, STRING);
    
    Particle.variable("Energy_Mon", &Energy_Mon, STRING);
    Particle.variable("Energy_Tue", &Energy_Tue, STRING);
    Particle.variable("Energy_Wed", &Energy_Wed, STRING);
    Particle.variable("Energy_Thu", &Energy_Thu, STRING);
    Particle.variable("Energy_Fri", &Energy_Fri, STRING);
    Particle.variable("Energy_Sat", &Energy_Sat, STRING);
    Particle.variable("Energy_Sun", &Energy_Sun, STRING);
   
    Energy_Jan = EEPROM.read(addr_Jan);
    Energy_Feb = EEPROM.read(addr_Feb);
    Energy_Mar = EEPROM.read(addr_Mar);
    Energy_Apr = EEPROM.read(addr_Apr);
    Energy_May = EEPROM.read(addr_May);
    Energy_Jun = EEPROM.read(addr_Jun);
    Energy_Jul = EEPROM.read(addr_Jul);
    Energy_Aug = EEPROM.read(addr_Aug);
    Energy_Sep = EEPROM.read(addr_Sep);
    Energy_Oct = EEPROM.read(addr_Oct);
    Energy_Nov = EEPROM.read(addr_Nov);
    Energy_Dec = EEPROM.read(addr_Dec);
    
    Energy_Mon = EEPROM.read(addr_Mon);
    Energy_Tue = EEPROM.read(addr_Tue);
    Energy_Wed = EEPROM.read(addr_Wed);
    Energy_Thu = EEPROM.read(addr_Thu);
    Energy_Fri = EEPROM.read(addr_Fri);
    Energy_Sat = EEPROM.read(addr_Sat);
    Energy_Sun = EEPROM.read(addr_Sun);
    
// Flasheo de memoria EEPROM para comenzar todo en cero (no volver a ocupar jamás)

EEPROM.write(addr_Jan,0);
EEPROM.write(addr_Feb,0);
EEPROM.write(addr_Mar,0);
EEPROM.write(addr_Apr,0);
EEPROM.write(addr_May,0);
EEPROM.write(addr_Jun,0);
EEPROM.write(addr_Jul,0);
EEPROM.write(addr_Aug,0);
EEPROM.write(addr_Sep,0);
EEPROM.write(addr_Oct,0);
EEPROM.write(addr_Nov,0);
EEPROM.write(addr_Dec,0);

EEPROM.write(addr_Mon,0);
EEPROM.write(addr_Tue,0);
EEPROM.write(addr_Wed,0);
EEPROM.write(addr_Thu,0);
EEPROM.write(addr_Fri,0);
EEPROM.write(addr_Sat,0);
EEPROM.write(addr_Sun,0);



tiempo = String(Time.timeStr());
dia_actual = tiempo.substring(0,3);
mes_actual = tiempo.substring(4, 7);
mes_anterior = mes_actual;

if(mes_actual == "Jan")
{
    Energy_8bits = EEPROM.read(addr_Jan);
    Energy = Energy_8bits * 750;
}
if(mes_actual == "Feb")
{
    Energy_8bits = EEPROM.read(addr_Feb);
    Energy = Energy_8bits * 750;
}
if(mes_actual == "Mar")
{
    Energy_8bits = EEPROM.read(addr_Mar);
    Energy = Energy_8bits * 750;
}
if(mes_actual == "Apr")
{
    Energy_8bits = EEPROM.read(addr_Apr);
    Energy = Energy_8bits * 750;
}
if(mes_actual == "May")
{
    Energy_8bits = EEPROM.read(addr_May);
    Energy = Energy_8bits * 750;
}
if(mes_actual == "Jun")
{
    Energy_8bits = EEPROM.read(addr_Jun);
    Energy = Energy_8bits * 750;
}
if(mes_actual == "Jul")
{
    Energy_8bits = EEPROM.read(addr_Jul);
    Energy = Energy_8bits * 750;
}
if(mes_actual == "Aug")
{
    Energy_8bits = EEPROM.read(addr_Aug);
    Energy = Energy_8bits * 750;
}
if(mes_actual == "Sep")
{
    Energy_8bits = EEPROM.read(addr_Sep);
    Energy = Energy_8bits * 750;
}
if(mes_actual == "Oct")
{
    Energy_8bits = EEPROM.read(addr_Oct);
    Energy = Energy_8bits * 750;
}
if(mes_actual == "Nov")
{
    Energy_8bits = EEPROM.read(addr_Nov);
    Energy = Energy_8bits * 750;
}
if(mes_actual == "Dec")
{
    Energy_8bits = EEPROM.read(addr_Dec);
    Energy = Energy_8bits * 750;
}
//-------------------------------------ESCRITURA DE ENERGIA DIAS DESDE EEPROM-----------------------------

if(dia_actual == "Mon")
{
    Energy_dia = EEPROM.read(addr_Mon)*100;
}
if(dia_actual == "Tue")
{
    Energy_dia = EEPROM.read(addr_Tue)*100;
}
if(dia_actual == "Wed")
{
    Energy_dia = EEPROM.read(addr_Wed)*100;
}
if(dia_actual == "Thu")
{
    Energy_dia = EEPROM.read(addr_Thu)*100;
}
if(dia_actual == "Fri")
{
    Energy_dia = EEPROM.read(addr_Fri)*100;
}
if(dia_actual == "Sat")
{
    Energy_dia = EEPROM.read(addr_Sat)*100;
}
if(dia_actual == "Sun")
{
    Energy_dia = EEPROM.read(addr_Sun)*100;
}




    digitalWrite(ledboard,LOW); //destello de 100 msec, indicando termino de setup
    delay(100);
    digitalWrite(ledboard,HIGH);
    delay(100);
    digitalWrite(ledboard,LOW);
    Serial.begin(9600); 
}

void loop() {

    t1 = millis();
        if (t1 > t2) // lee cada 1 segundo 
        { 
        t2 =t1+1000;

        tiempo = String(Time.timeStr());
        dia_actual = tiempo.substring(0,3);
        mes_actual = tiempo.substring(4,7);
        
        if (mes_actual == mes_anterior)
        {
            I1 = analogRead(corrienteF1);
            I2 = analogRead(corrienteF2);
            I3 = analogRead(corrienteF3);
            I1_table = String((I1)/4095*3.3/1000*5000);  //Calibración TC-1 - 12 bits de resolución, 3,3 V, 1000(ohms divisor voltaje), 5000 (razón TC).
            I2_table = String((I2)/4095*3.3/1000*5000);  //Calibración TC-2
            I3_table = String((I3)/4095*3.3/1000*5000);  //Calibración TC-3
            
            Pot = (I1+I2+I3)/248/3*380*0.9*sqrt(3)/1000*30; //Cálculo potencia trifásica en kW, asumiendo FP:0,9 y razón de transformación de 30 (150/5) de TC primarios. (248 es +/- la calibración de cada TC)
            Pot_table = String(Pot);
            
            Energy = (Pot/3600)*3 + Energy;
            Energy_8bits = Energy/750;
            Energy_table = String(Energy);
            
            Energy_dia = (Pot/3600)*3 + Energy_dia;
            Energy_7bits = Energy_dia/100;
            Energy_table_dia = String(Energy_dia);
            

            //---------------------DÍAS---------------------------
            
            if (dia_actual == "Mon")
            {
                Energy_Mon = String(Energy_dia);
                EEPROM.write(addr_Mon,Energy_7bits);
            }
            if (dia_actual == "Tue")
            {
                Energy_Tue = String(Energy_dia);
                EEPROM.write(addr_Tue,Energy_7bits);
            }
            if (dia_actual == "Wed")
            {
                Energy_Wed = String(Energy_dia);
                EEPROM.write(addr_Wed,Energy_7bits);
            }
            if (dia_actual == "Thu")
            {
                Energy_Thu = String(Energy_dia);
                EEPROM.write(addr_Thu,Energy_7bits);
            }
            if (dia_actual == "Fri")
            {
                Energy_Fri = String(Energy_dia);
                EEPROM.write(addr_Fri,Energy_7bits);
            }
            if (dia_actual == "Sat")
            {
                Energy_Sat = String(Energy_dia);
                EEPROM.write(addr_Sat,Energy_7bits);
            }
            if (dia_actual == "Sun")
            {
                Energy_Sun = String(Energy_dia);
                EEPROM.write(addr_Sun,Energy_7bits);
            }
            
            //---------------------MESES---------------------------   
            
            if (mes_actual == "Jan")
            {
                Energy_Jan = String(Energy);
                EEPROM.write(addr_Jan,Energy_8bits);
            }
            if (mes_actual == "Feb")
            {
                Energy_Feb = String(Energy);
                EEPROM.write(addr_Feb,Energy_8bits);
            }
            if (mes_actual == "Mar")
            {
                Energy_Mar = String(Energy);
                EEPROM.write(addr_Mar,Energy_8bits);
            }
            if (mes_actual == "Apr")
            {
                Energy_Apr = String(Energy);
                EEPROM.write(addr_Apr,Energy_8bits);
            }
            if (mes_actual == "May")
            {
                Energy_May = String(Energy);
                EEPROM.write(addr_May,Energy_8bits);
            }
            if (mes_actual == "Jun")
            {
                Energy_Jun = String(Energy);
                EEPROM.write(addr_Jun,Energy_8bits);
            }
            if (mes_actual == "Jul")
            {
                Energy_Jul = String(Energy);
                EEPROM.write(addr_Jul,Energy_8bits);
            }
            if (mes_actual == "Aug")
            {
                Energy_Aug = String(Energy);
                EEPROM.write(addr_Aug,Energy_8bits);
            }
            if (mes_actual == "Sep")
            {
                Energy_Sep = String(Energy);
                EEPROM.write(addr_Sep,Energy_8bits);
            }
            if (mes_actual == "Oct")
            {
                Energy_Oct = String(Energy);
                EEPROM.write(addr_Oct,Energy_8bits);
            }
            if (mes_actual == "Nov")
            {
                Energy_Nov = String(Energy);
                EEPROM.write(addr_Nov,Energy_8bits);
            }
            if (mes_actual == "Dec")
            {
                Energy_Dec = String(Energy);
                EEPROM.write(addr_Dec,Energy_8bits);
            }
            
        }
        else
        {
            mes_anterior = mes_actual;
            Energy = 0;
            Energy_8bits = 0;
            Energy_table = "0";
            Serial.print(tiempo);
        }
        
            
        }
}

The hardware as such has no impact on the build at all.
The build does even work with the devices offline.
Also the firmware on the boards is secondary for the build, only the target setting in Web IDE is of interest for the build.

You are creating too many Particle.variables() with some names too long (see docs for current limits)
Don’t use the three parameter version of Particle.variable() for String objects (only for C strings), consider using arrays rather than individual variables in conjunction with loops and indexing and - as personal advice - avoid excessive use of String, rather go for C string (char[]).

tiempo = Time.timeStr(); // is just as good as "String(Time.timeStr());" - or even better

Time.month() does already give you the months number, so no need for extra constants - same goes for Time.weekday()

Thanks for your advice, I’ll follow them to make my code more efficient. I didn’t though about the limitations of particle.variables.

On the other hand, after a photon is compiled and flashed with this inefficient code (too many particle.variable) I can’t compile (and flash obviously) any more code targeting that photon (even example codes with out particle.variable’s.

How can I fix this?, any ideas?, I’ve tried to make a factory reset but it seems is not working for me.

EDIT: I’ve even tried removing the device and seting it up all over again, but it doesn’t work either.

If it’s a Photon, there is no factory reset, but you can use Safe Mode.

But I have to say again: “Compiling/building is independent of your actual device - even if you smash it with a hammer, the building process will work as if it was well and healthy”.

Flashing success on the other hand is of course closely tied to the health of the device.

There is no factory reset on a photon, have a look at how to get to safe mode, that makes the photon run just the system firmware and allows you to reflash even with firmware that would normally crash

1 Like

Ok, got it.

But following your argument, there is no relationship between the build of the code with the board, until flashing. So…the problem is that I can’t compile any code when I have targeted this board in “devices” of the WEB IDE.
That has nothing to do with the board as you mentioned, so, what could be the problem?.

I keep getting “Error: Could not compile. Please review your code.”, even with example codes. This happened after I flashed the device with the inefficient code posted before.

So what could I do?, I’ll try to get to safe mode and flash an example code as you said.

EDIT: Problem SOLVED, entering safe mode let me compile again, thank you very much for your advice and patience :smiley:

next to the device there is a arrow, click it and it should tell you what version you are building against. it may be set for an older or newer version than the other you can build against.

does the error give you any info? which line or anything?

As said before

and

1 Like