Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding class "aJsonFileStream" inherited from aJsonStream in order to backward- compatibility with HTTPClient library #86

Open
wants to merge 31 commits into
base: master
Choose a base branch
from

Conversation

anklimov
Copy link

@anklimov anklimov commented Oct 5, 2016

adding class "aJsonFileStream" inherited from aJsonStream in order to backward- compatibility with HTTPClient library
Now is possible to operate directly with *FILE like streams, returned by HttpClient library and avoid intermediate buffering

Code example:


int getConfig()
{
    FILE* result;
    int returnCode ;

    HTTPClient hclient("192.168.88.2",hserver,80);
    result = hclient.getURI( FEED_URI);
    returnCode = hclient.getLastReturnCode();

    if (result!=NULL) {
      if (returnCode==200) {

          Serial.println("got Config :"); 
             aJsonFileStream as=aJsonFileStream(result);  
          root = aJson.parse(&as);

     hclient.closeStream(result);  // this is very important -- be sure to close the STREAM

        if (!root)
          {
            Serial.println("parseObject() failed");
           return -11;
            } else   

          {

            char * outstr=aJson.print(root);
            Serial.println(outstr);
             items = aJson.getObjectItem(root,"items");            
          }

            } 
    else {
      Serial.print("ERROR: Server returned ");
      Serial.println(returnCode);
      return -11;

    }

    } 
    else {
      Serial.println("failed to connect");
      Serial.println(" try again in 5 seconds");
      return -11;
                }



  return 2;
}

@anklimov
Copy link
Author

anklimov commented Oct 5, 2016

That is my first attempt to contribute some changes at Github
Please, let me know if something done @Not a best way ))

anklimov and others added 27 commits October 7, 2016 21:40
void loadConfig (char* tokens)
{
          Serial.println("loading Config"); 
          aJsonEEPROMStream as=aJsonEEPROMStream(0);  
          aJson.deleteItem(root);
          root = aJson.parse(&as);
          Serial.println();
          if (!root)
          { 
            Serial.println("load failed");
            return;
            } 
            Serial.println("Loaded");
             items = aJson.getObjectItem(root,"items"); 
             dmxArr= aJson.getObjectItem(root, "dmxin");      
}

void saveConfig(char* tokens)
{ 
  aJsonEEPROMStream es=aJsonEEPROMStream(0);  
  Serial.println("Saving config..");
  aJson.print(root,&es);
  es.putEOF();
  Serial.println("Saved");
  
}
Float precession decreased to conserve string memory usage
fix compilation error on STM32F1 arch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants