Error when compiling: Could not compile. Please review your code

Some years back when Spark Core came out i made LCD temperature display that shows outside temperature.
Now i need to make some changes to code (trying to compile with 0.6.2 to spark core) and i get: “could not compile error” when i uncomment some code that is currently commented out. What causes that?
Code: https://go.particle.io/shared_apps/5a9a7e3c15004cd73c001224

-edit-

It seems that atof causes not to compile.

if(response.status == 200){
        String web = response.body;
       // Serial.println(response.body);

        String aeg2 = web.substring(32,38);
        String aeg1 = web.substring(30,32);
       // int gmt = atof(aeg1.c_str());
       // int tund = gmt + 3; 
       int tund = 3;
        timeStr = "";
        if(tund<10){timeStr += " ";}
        timeStr += tund;
        timeStr += aeg2;
        timeStr += "";
        int last = web.lastIndexOf('"');
        int previous = web.lastIndexOf('"', last - 1 );
        String result = web.substring(previous+1, last); 
        //hetkeTemp = atof(result.c_str());
        
        update = 1;
    }

It worked few years ago, has smth changed?

The atof() function returns a float. Since you’re saving the value as an int, you should use atoi:

int gmt = atoi(aeg1.c_str());

Or, since you already have a String object:

int gmt = aeg1.toInt();

It takes care of compiling when i change both instances to atoi.
But as i did last programming years ago and i was novice then at best i can’t make any sense out of those strings i’m trying to read.

Here’s what i want to do:
I want to read 2 values from Thingspeak site where i upload my outside temperature data.

  1. time of last update
  2. temperature value from field1:

http://api.thingspeak.com/channels/24877/fields/1/last.json?key=GOKBGDF6332V45P3

When everything is correct LCD should display time and temp like this:


Upper temp is current temp, in middle are daily min and max with timestamp. Bottom is time of last update.
Why it stopped working in first place is that thingspeak rearranged order few days ago. Field1 value used to be last and created_at was first if i recall correctly.
Can someone help me make changes that are needed so i can see what outside temperature is again? :slight_smile:

You may want to look at a JSON parser library to rid yourself from the problem of absolute position.

When refering to the JSON fields by name it doesn’t matter where it is in the string.

Have a look at the linked sample and try to understand what it does and how/why it works.

1 Like

One thing that i forgot to mention is that i’m running out of flash space. Current code is 98,1% used space.
Therefore i can’t really import any more library’s.

Judging by the code snippet you provided above, I’d suspect some potential for streamlining the code to reduce flash utilisation.
And if you want to do yourself something good, treat yourself to a Photon which does away with that problem without any alteration to the code :wink:

If you wish, You can do what you asked for without JSON by using the txt endpoints of the ThingSpeak API.

For instance
Last Entry Field 1
Updated X Seconds Ago

I use the Txt endpoints to drive all sorts of Javascript gauges on webpages.

However, when using JSON or XML, the ThingSpeak API can perform a good bit of data analysis and return “almost any” results you want. READ API Parameters

With @ScruffR 's suggestion of the JSON Library, you could reduce your CODE to a few lines by letting ThingSpeak’s API perform the workload.