Skip to content

Can not parse recursive #12

Description

@bcatalin

Hi Daniel,

I have an issue with the stream parser. I am trying to parse each line from a file in SPIFFS and is only working for the first line.

#include <FS.h> 
#include "JsonStreamingParser.h"
#include "JsonListener.h"
#include "ExampleParser.h"

JsonStreamingParser parser;
ExampleListener listener;
float temp_t1 = 33.45;
float temp_t2 = -127.00;

void setup() {
  Serial.begin(115200);
  Serial.println(String(ESP.getFreeHeap()));
  SPIFFS.begin();
  parser.setListener(&listener);
  /* //run this code once just have the file !!!!!!!!!!!!!!!!!!!
  File unsent = SPIFFS.open("/unsent.json", "a+");
  if (!unsent) {
    Serial.println("failed to open file for writing :-(");
    return; //==============>
  }

  for(int i =0; i< 10; i++)
  {
   char temp1[10];
   char temp2[10];
   sprintf(temp1,"%s", String(temp_t1).c_str());
   sprintf(temp2,"%s", String(temp_t2).c_str()); 
   Serial.printf("SIZE :%d\n", unsent.size());
   char strTemp[64];
   if(unsent.size() == 0)
     sprintf(strTemp,"{\"t1\":\"%s\",\"t2\":\"%s\"}\n",temp1, temp2);
   else
     sprintf(strTemp,"{\"t1\":\"%s\",\"t2\":\"%s\"}\n",temp1, temp2);
  
   Serial.println(strTemp);
   unsent.print(strTemp);
  }
  unsent.close();//new CC 
*/  


  if(SPIFFS.exists("/unsent.json"))
  {
    Serial.println(F("I have unsent data"));
    File unsentFile = SPIFFS.open("/unsent.json","r");
    if(unsentFile)
    {
      Serial.printf("unsent.json size:%d",unsentFile.size()); Serial.println("");
      while(unsentFile.available())
      {
        String line = unsentFile.readStringUntil('\n');
        Serial.println(line); 
        char parse_line[200];
        line.toCharArray(parse_line, 200);
        for (int i = 0; i < sizeof( parse_line ); i++) {          
          parser.parse(parse_line[i]); 
        }
      }
    }
  }

  Serial.println(String(ESP.getFreeHeap()));
}

void loop() {
  // put your main code here, to run repeatedly:

}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions