Code Monkey home page Code Monkey logo

neteeprom's Introduction

NetEEPROM

Arduino library that reads stores network settings to EEPROM. This is useful to associate a network configuration with a specific Arduino board which can then be read by many sketches without having to be set in each sketch.

This library stores to EEPROM:

  • the MAC address of the interface
  • whether DHCP should be used to configure IP settings
  • if DHCP is not used, then the manual IP settings for the interface

The library also contains a function to configure the Ethernet adapter from the configuration stored in EEPROM. If network configuration has not been stored in EEPROM then the following configuration will apply:

  • A random MAC address in the form DE:AD:BE:EF:xx:xx (where xx is a random number between 0 and 255) will be generated and stored in EEPROM.
  • The IP address will be configured using DHCP, and this configuration will be stored in EEPROM

Usage

To use the the NetEEPROM library the sketch will need to contain the following includes:

#include <EEPROM.h>
#include <SPI.h>
#include <Ethernet.h>
#include <NetEEPROM.h>

To set a MAC address with DHCP configuration, use the following code:

byte mac[6] = { 0xCA, 0xFE, 0xBA, 0xBE, 0x00, 0x00 };
NetEeprom.writeDhcpConfig(mac);

To set a MAC address with manual IP configuration, use the following code:

byte mac[6] = { 0xCA, 0xFE, 0xBA, 0xBE, 0x00, 0x00 };
byte ip[4] = { 192, 168, 1, 100 };
byte dns[4] = { 8, 8, 8, 8 };
byte gw[4] = { 192, 168, 1, 1 };
byte subnet[4] = { 255, 255, 255, 0 };
NetEeprom.writeManualConfig(mac, ip, dns, gw, subnet);

To set up the Ethernet adapter with configuration from EEPROM, use the following line:

NetEeprom.begin();

If you wish to configure the start address in EEPROM where the network configuration resides, call the setEepromOffset() following method before calling any other methods. If you do not call this method, then the default EEPROM location set set to 0. To set the network configuration at a custom EEPROM offset, use the following code.

NetEeprom.setEepromOffet(128);
byte mac[6] = { 0xCA, 0xFE, 0xBA, 0xBE, 0x00, 0x00 };
NetEeprom.writeDhcpConfig(mac);

To read network configuration at a custom EEPROM offset, use the following code:

NetEeprom.setEepromOffset(128);
NetEeprom.begin();

neteeprom's People

Contributors

gregington avatar juzam avatar per1234 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.