IniFile library

The EtherTen combines an Uno-equivalent Arduino-compatible board and Wiznet-based Ethernet support, along with a microSD card slot and Power-over-Ethernet support. [Product page]
Post Reply
jebz
Posts: 33
Joined: Sun Feb 12, 2012 10:58 pm

IniFile library

Post by jebz » Sun Feb 12, 2012 11:20 pm

I have a project with an EtherTen and LCD, keypad shield.

I've found a library to process an INI file with functions that extract the network variables. But I have a small problem it doesn't open the file in the example. I've tried a number of things and it still doesn't work. I compiled another program to just open the file and send it to the serial console. It works with this program so the file is there and OK.

https://github.com/stevemarple/IniFile
You need to save the net.ini file to the SD card in the Arduino for the example.

I've also compiled and run a small project that gets the network going with DHCP. This gets the time from a NTP server and prints the network address obtailed by DHCP and time on the LCD shield. This tests the hardware I've assembled. I'd just like to have the network settings read from the SD card rather than hard coded in the project.

jebz
Posts: 33
Joined: Sun Feb 12, 2012 10:58 pm

Re: IniFile library

Post by jebz » Tue Feb 14, 2012 12:38 pm

A few findings.
This bit of code in the example won't open the file so we don't get far -

Code: Select all

  const char *filename = "/net.ini";
  Serial.begin(9600);
  IniFile ini(filename);
  if (ini.isOpen()) {
    Serial.println("Ini file exists");
We need to change it to -

Code: Select all

const char *filename = "/net.ini";
  Serial.begin(9600);
  SD.begin(4);
  IniFile ini(filename);
  if (ini.open()) {
    Serial.println("Ini file exists");
Then the response to the mac is -

Code: Select all

network section has an entry mac with value mac = 01:23:45:67
or other incorrect result. Has someone used this library code with success?
.

marks
Posts: 31
Joined: Wed Jan 04, 2012 8:13 pm

Re: IniFile library

Post by marks » Sat Feb 18, 2012 9:57 pm

Hi Jebz,

It's not a conflict on pin D4 by any chance? As explained here for the USBDroid and LCD Shield

viewtopic.php?f=8&t=152

Cheers,

Mark S.

marks
Posts: 31
Joined: Wed Jan 04, 2012 8:13 pm

Re: IniFile library

Post by marks » Sat Feb 18, 2012 9:57 pm

Sorry here is the full link:

viewtopic.php?f=4&t=209&p=751#p751

jebz
Posts: 33
Joined: Sun Feb 12, 2012 10:58 pm

Re: IniFile library

Post by jebz » Sat Feb 18, 2012 10:58 pm

marks wrote: It's not a conflict on pin D4 by any chance? As explained here for the USBDroid and LCD Shield
I'm not using the USBDroid so I don't have the USB interface.
I can run the SD example sketch "readwrite" without any issues. I can add this code to the IniFile sketch and the imported example read code works.

marks
Posts: 31
Joined: Wed Jan 04, 2012 8:13 pm

Re: IniFile library

Post by marks » Sat Feb 18, 2012 11:46 pm

Pin D4 is used by the LCD shield as well as the SD card on the USBDroid so the USB part doesn't come into it in this case.

The EtherTen seems to be the same from my quick look. I had "weird" things happening on the USBDroid until I realized. Sometimes files would get read or written, other times they wouldn't. It was all dependent if I was using the the LCD shield and buttons at the same time.

jebz
Posts: 33
Joined: Sun Feb 12, 2012 10:58 pm

Re: IniFile library

Post by jebz » Mon Feb 20, 2012 11:32 am

Another issue with the example sketch is the parameters passed to the getValue are in the wrong order.

Code: Select all

(ini.getValue("mac", "network", mac, macLen))
Should be -

Code: Select all

(ini.getValue("network", "mac", mac, macLen))
Now the function buffer used to read the line is the same length as the buffer used to pass the result back. This means the result gets truncated.

Post Reply