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: 61 + 91 = ? followed by the letter: G 



About Me
More Blogs
Main Site
Posts:
2024 (1)
     Drone drop mechanism
2023 (3)
     Circuit board holders
     DJI Firmware
     ADT System Retrofit
2019 (1)
     Electronic dividing head
2017 (3)
     Crawl Space Forklift
     Remote Control Snowblower
     Arduino RC motor control
2016 (6)
     Keyboard Emulation
     Arduino w/ win2k
     Arduino Snowblower chute control
     Attic Fan Remote Control
     Robotic Arm
     ATTiny Watchdog
2015 (7)
     ESP-LINK Huzzah
     Arduino Bugs
     Arduino INI library
     Arduino Yun
     long watchdog
     Arduino runtime config
     CNC Rotary table
2014 (1)
     Humidor AutoWater