Can't compile with my #include <SparkJson.h>

I’ve included the library with my project, I get fatal error: SparkJson.h: No such file or directory
I need it to parse some JSON data from Firebase. Any ideas on how I can fix this?

You need to import the library, not just add the include statement.

I did go through that process. I searched it in libraries and added it to my project. It shows up in my “my libraries”` list as “Included Libraries” - SPARKJSON (0.0.2) but still won’t compile… says it can’t find it.

Can you post a screenshot of your Web IDE with top section of your project and the code drawer <> open?

sure, here’s the shot with the error

hmmm, spent this morning copying my code over to a new project name… then I included the SparkJson library and it compiles now. I made NO other changes. this has me a bit concerned about corruption in my app files. Is there anyway to have someone look at my project files at Particle to see how they got corrupted? I’m moving on in the new app name but would like to see if my example could help stop this from happening to someone else.

I’m getting the same problem. Is there a fix yet, or should I be using a different library name?

Sean

Have you tried any of the library examples?

Try changing #include "SparkJson.h" to #include <SparkJson.h> (don’t ask ;-))

You may also move #include "Particle.h" before the lib include.

Thanks for the quick reply. Tried <> not “” and changed the order of the includes, but does not seem to make a difference.

Any more thoughts?

Sean

Can you post your code?
What system version are you targeting?
Try 0.6.0.

I’m on 0.6.1 on the device. Are you suggesting that I downgrade the firmware?

Sean

This is my WIP code:

/*********************************/
/* Flown 2 Small - 2 (Table Top) */
/*********************************/

#include "Particle.h"
//#include "SparkJson.h"
#include "neopixel.h"
#include "Adafruit_DHT.h"

SYSTEM_MODE(AUTOMATIC);

// DHT
#define DHTPIN 5
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);

int light_sensor_pin = A0;
int temperature,humidity,light;
int previous_temperature,previous_humidity,previous_light;
int i,j,r,g,b;

int counter = 0;
int sensorcounter = 0;
int sensorfrequency = 100;
bool sense,h,t,l;

// Neopixel
#define PIXEL_PIN D2
#define PIXEL_COUNT 50
#define PIXEL_TYPE WS2812B
Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);

int nodeCount = 10;
int pixelsPerNode = 5;
int pixelStep = 1;
int framedelay = 80;

// Nodes
int red[PIXEL_COUNT];
int green[PIXEL_COUNT];
int blue[PIXEL_COUNT];

// Increments and Colour Values
int incr=2;
int incg=3;
int incb=7;
int high = 250;
int low = 150;
int shigh = 250;
int slow = 0;

void setup() {
    Serial.begin(9600);
    Serial.print("Flown 2 Small - 2 (Table Top)");
    Particle.subscribe("hook-response/colourpostflownsmall2/0", myHandler, MY_DEVICES);

    dht.begin();
    strip.begin();
    strip.show();

    r = low; g = low; b = low;
    sense = true; t = false; h = false; l = false;

    for(i=0; i<nodeCount; i++) {
        red[i] = 0;
        green[i] = 0;
        blue[i] = 0;
    }
}

void loop() {
    // Get Data From Sensors
    if (sense) {
        temperature = dht.getTempCelcius();
        humidity = dht.getHumidity();
        float light_measurement = analogRead(light_sensor_pin);
        light = (int)(light_measurement/4096*100);

        // Red = Temperature
        if (temperature > 0) {
            if (temperature != previous_temperature) {
                //Spark.publish("Temperature", String(temperature)+"°C");
                t = true;
            }
            // Green = Humidity
            if (humidity != previous_humidity) {
                //Spark.publish("Humidity", String(humidity)+"%");
                h = true;
            }
        }
        // Blue = Light
        if (light != previous_light) {
            //Spark.publish("Light", String(light)+"%");
            l = true;
        }

        if (t || h || l) {
            char data[12];
            sprintf(data,"%d,%d,%d",temperature,humidity,light);
            Serial.print("Sending: ");
            Serial.println(data);
            Particle.publish("colourpostflownsmall2", data, PRIVATE);
        }
        previous_temperature = temperature;
        previous_humidity = humidity;
        previous_light = light;

        sense = false;
    }
    sensorcounter++;
    if (sensorcounter == sensorfrequency) {
        sense = true;
        sensorcounter = 0;
    }

    // Slide
    for(i=0; i<(nodeCount-1); i++) {
        red[i] = red[i+1];
        green[i] = green[i+1];
        blue[i] = blue[i+1];
    }

    // Fade
    r = r+incr;
    if (r < low) {
        r = low; incr = 2;
    }
    if (r > high) {
        r = high; incr = -2;
    }
    g = g+incg;
    if (g < low) {
        g = low; incg = 3;
    }
    if (g > high) {
        g = high; incg = -3;
    }
    b = b+incb;
    if (b < low) {
        b = low; incb = 7;
    }
    if (b > high) {
        b = high; incb = -7;
    }

    red[nodeCount-1] = r;
    green[nodeCount-1] = g;
    blue[nodeCount-1] = b;

    // Sensor Response
    if (t || h || l) {
        red[nodeCount-1] = slow;
        green[nodeCount-1] = slow;
        blue[nodeCount-1] = slow;
        if (t) {
            red[nodeCount-1] = shigh; t = false;
        }
        if (h) {
            green[nodeCount-1] = shigh; h = false;
        }
        if (l) {
            blue[nodeCount-1] = shigh; l = false;
        }
    }
    else {
        red[nodeCount-1] = r;
        green[nodeCount-1] = g;
        blue[nodeCount-1] = b;
    }

    // Display Frame
    for(i=0; i<nodeCount; i++) {
        for(j=0; j<pixelsPerNode; j+=pixelStep) {
            strip.setPixelColor((i*pixelsPerNode)+j,green[i],red[i],blue[i]);
        }
    }
    strip.show();

    // Delay
    delay(framedelay);
}

void myHandler(const char *event, const char *data) {
    // Parse JSON
    Particle.publish("Data",data);
/*  StaticJsonBuffer<1024> jsonBuffer;
  char jsonString[512];
  strncpy(jsonString, data, 512);
  JsonObject& root = jsonBuffer.parseObject(jsonString);

  // Extract HSL values
  h = atoi(root["results"][0]["h"].asString());
  s = atoi(root["results"][0]["s"].asString());
  l = atoi(root["results"][0]["l"].asString());

  Serial.print("Received: ");
  Serial.print(h);
  Serial.print(",");
  Serial.print(s);
  Serial.print(",");
  Serial.println(l);
*/
}

Obviously I’ve commented out the JSON processing for now in order to get the project to build.

Sean

For me that builds for 0.6.1.
Excuse the stupid question, but have you imported the library into your project?
Can you show a screenshot with the code drawer <> open?

Here you go:

Very odd.
This is how things look for me

So, I copied the code, deleted the app, recreated it, added libraries and paste the code back in and now it’s working!

Thanks for your help,

Sean

1 Like

Exactly what I did to solve this. But would like to get to the bottom of it since my project is several files and thousands of lines of code now… it was the same lib include of SparkJson.h that corrupted my project. So maybe it’s isolated to this lib add and could be recreated? I’ll try it tonight and report back

I did a little testing… I have a project out there that compiles fine when "SparkJson.h is commented out, but if you un-comment, it gives a fatal error saying it can’t find the file, but it’s in the code drawer . I tried to fix it but nothing I tried worked… placement of the include, removing the include, adding it back and then deleting the library from the “Included Libraries” list in the code drawer and adding it back…nothing worked. only remedy is to copy all your code into a new App. I’ll offer it up if anyone at Particle would like to take a look at my project on the back-end (if possible) and see if the bug can be identified? the corrupted APP is PELLETPIRATE in my account.

As described by others: I added the SparkJson libary to my project and recompiled. The compilation failed because SparkJson.h file could not be found. Compilation was successful after I deleted my project, recreated it, and then added the SparkJson library.