Giter Club home page Giter Club logo

arduino_config_reader's Introduction

Arduino Config Reader

Reads a configuration text file form an SDcard (FAT) and stores the configuration values in a config struct that can be used throughout your program. It is useful to pass parameters to the running software without having to reflash or recompile code, simply by changing some parameters in a text file. Useful to

  • set device IDs on multiple devices running the same software
  • defining input pins to read sensors
  • definig servers address and ports to send data to
  • etc...

Uses the library SDFat from sparkfun shield https://github.com/greiman/SdFat Although any other library will do, as long as it can read characters from a text file

Allows to have preset values, in case there is some error reading the SDcard or if the SDCard is not present

How to change parameters:

1- change the struct Config (config.h) with the datatypes of your needs 2- change the text file that contains your configuration (configuration.txt) 3- change the function assignConfig (config.cpp) to assign the strings to each of the parameters you set in the structure (for instance to parse float, instead of int and strings). 4- add your paramteres to the function PrintConfig (config.cpp)

Usage

The parameters are defined in the struct Config in config.h

  • getDefaultConfig - returns a Config struct with the default values that are set inside that function (change them to your needs)
  • readSDConfig - receives a filepath and a Config struct and modifies it with the contents of the file
  • printConfig - receives a Config struct and prints out all its members
#include "config.h"

..... MAIN ....


Config CONFIG = getDefaultConfig();
readSDConfig("configuration.txt", CONFIG);

printConfig(CONFIG);

Config file strucure

The file is made of a parameter for each new line (either terminated with \r (winodws) or \n (unix) Each parameter is as follows:

Parameter1=value1
Parameter2=value2
  • The delimiter '=' can be set in the begining of config.cpp file in the DELIM define
  • No spaces can be used between the parameter name and the delimiter
  • All parameters should be stored in plain text without quotes and assigned in the function assignConfig (config.cpp) similar to how the parameter serverAddress in the example is set.
  • Boolean values should have a value of true or false or 1 or 0 (not case sensitive)
  • Allows for blank lines

Final notes

Can be adapted to other SDCard libraries that read single characters by changing the function readLine (config.cpp) Can be adapted to other file formats and the parsing of other values, such as bool or float in the function assignConfig (config.cpp)

Tested

Has been tested in the Particle Photon

arduino_config_reader's People

Contributors

miguel-ribeiro avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.