Arduino INI library


Author: Dave
Date: 12.17.15 - 1:29pm



I was playing around a bit with a couple ini libraries for arduino.

The inih library by Ben Hoyt looks like the winner.

Its very clean and lite weight. Elegant even. The ini file is only parsed once, and it uses a call back to notify you of each setting found. This allows you to just do a simple strdup on the value instead of having to allocate a static buffer of size X. It also processes lines longer than the line buffer length without error. To use it with teh SD card library from Ardunio all you have to do is define your own fgets implementation and you can use it without modification.

Example below:

File file = SD.open("private.ini");

if (ini_parse_stream((ini_reader)my_fgets, &file, myini_handler, 0) < 0) {
   Serial.println("Ini parse failed");
   while(1);
}

file.close();


char* my_fgets(char* buf, int len, File* stream){ if(stream->available()){ int i = stream->readBytesUntil('\n',buf,len); if(buf[i-1] == '\r') buf[i-1] = 0; return buf; } else return 0; } static int myini_handler(void* user, const char* section, const char* name, const char* value) { Serial.print("["); Serial.print(section); Serial.print("] "); Serial.print(name); Serial.print(" = "); Serial.println(value); return 1; }





Comments: (0)

 
Leave Comment:
Name:
Email: (not shown)
Message: (Required)
Math Question: 63 + 44 = ? followed by the letter: O 



About Me
More Blogs
Main Site
Posts:
2019 (1)
     Electronic dividing head
2018 (1)
     Thoughts on next RC blower
2017 (4)
     Crawl Space Forklift
     Remote Control Snowblower
     Servo control for linear actuator
     Arduino RC motor control
2016 (6)
     Keyboard Emulation
     Arduino w/ win2k
     Arduino Snowblower chute control
     Attic Fan Remote Control
     Robotic Arm
     ATTiny Watchdog
2015 (9)
     ESP-LINK Huzzah
     IoT Humidor v2
     Arduino Bugs
     Arduino INI library
     Arduino Yun
     long watchdog
     Arduino runtime config
     CNC Rotary table
     AutoWater humidifier
2014 (1)
     Humidor AutoWater
2013 (1)
     KeyPad Bruteforcer