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: 40 + 31 = ? followed by the letter: N 




About Me
More Blogs
Main Site
Posts:
Thoughts on next RC blower
Crawl Space Forklift
Remote Control Snowblower
Servo control for linear actuator
Arduino RC motor control
Keyboard Emulation
Arduino w/ win2k
Arduino Snowblower chute control
Attic Fan Remote Control
Robotic Arm
ATTiny Watchdog
ESP-LINK Huzzah
IoT Humidor v2
Arduino Bugs
Arduino INI library
Arduino Yun
long watchdog
Arduino runtime config
CNC Rotary table
AutoWater humidifier
Humidor AutoWater
KeyPad Bruteforcer