Giter Club home page Giter Club logo

flash-config's Introduction

flash-config

Configuration of headless devices by flash disk (or any mountable disk) with Network-Manager support.

This library allows UI-less devices (usually a Raspberry Pi, Orange Pi etc...) to be easily configured just by inserting USB flash disk or SD card to port. The library watches device mounts and when it finds the desired configuration file, a user code is called.

To give user a feedback about operation result, the library either:

  • renames configuration file by inserting done- prefix if operation succeeded.
  • creates new file with failed- prefix if the user callback thrown an exception. The file contains error message of that exception.

The generic configuration API is very simple:

const flashConfig = require("flash-config").flashConfig();

flashConfig.watch({
    name: "config.json",
    format: flashConfig.json,
    callback: async config => {
        console.info("I got my configuration:", config);
    }
}).start();

Because most common task is to configure WiFi connection, there is a built-in support to configure Network-Manager.

const flashConfig = require("flash-config").flashConfig();
const networkManager = require("flash-config").networkManager();

flashConfig.watch({
    name: "wifi.txt",
    format: flashConfig.text,
    callback: async config => {
        await networkManager.configure(config, "TEST");
        console.info(`BINGO, connection to ${config.ssid} configured!`);
    }
}).start();

Check example.js for complete code.

Note the format property of watch parameter. This is a reference to converter function, which takes file content as string and returns a js value. There are two built-in converters:

json which is just JSON.parse

text which consumes key-value map with # comments, e.g.:

wifi.txt:

# this is an example of WiFi configuration
ssid MySweetHome
password abcd1234

# ip and gw is optional, if missing we use DHCP
ip 10.1.0.15
gw 10.1.0.2

The library uses debug module for logging. To get full log, set environment variable DEBUG=*.

Command line usage

You can use the library directly from command line to configure WiFi:

npx flash-config

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.