Code Monkey home page Code Monkey logo

arduino-ntp's Introduction

Arduino NTP Client using the duinotech ESP13 with ESP8266 WiFi chip.

Arduino project code for conducting NTP communication and decoding the time.

Included in this repo:

  • Arduino NTPClient.ino project file that, when uploaded to the ESP13, connects to the internet over WiFi and requests, recieves and prints the current time.
  • New Arduino libraries that the .ino project requires. These libraries hide unnecessary complexity from the Arduino programmer of the NTP communication, calculating the hours, minutes, seconds, creating a time-string.

17 February 2018:

  1. This has been written-for and tested-with duinotech's ESP13 board (containing an ESP8266 WiFi chip).

Guide:

  1. Install the ESP8266 boards for the Arduino IDE/framework by following this guide: https://randomnerdtutorials.com/how-to-install-esp8266-board-arduino-ide/
  2. Clone or otherwise download this repo.
  3. Copy the library folders from this repo (TimeConverter, NTP, and ESP8266WiFi) to your ../Arduino/libraries location. On the Windows operating system, this is defaulted to the user's Documents folder.
  4. Copy the Arduino project folder (NTPClient) to wherever you store your regular Arduino projects.
  5. Open the NTPClient.ino Arduino project file with the Arduino IDE.
  6. Upload this code to your ESP13 WiFi board (see the Programming the ESP13 board section).
  7. Select "Serial Monitor" from the Arduino IDE's Tools menu to periodically see the latest time.

Notes:

  1. Originally programmed and tested on the duinotech's ESP13 WiFi board (with ESP8266 WiFi chip), the code has been written with the goal of ultimately working with Arduino compatible RJ45 (non WiFi) boards as well. Testing and polishing this additional use is pending, however.
  2. Note in the line of code in the NTPClient.ino project file: const char* timeString = TimeConverter::getInstance( UTC_OFFSET )->getTimeCString( ntp.decodeSeconds() ); ...

ntp.decodeSeconds() extracts the POSIX time (in total seconds) from the NTP response, and the rest of the line of code above provides a time string in the format HH:MM:SS.

Alternatively, if you are wanting to do something specific with either the hours, minutes of seconds, then these can be obtained by:

    unsigned long totalSeconds = ntp.decodeSeconds();
    
    unsigned short hours = TimeConverter::getInstance( UTC_OFFSET )->getHours( totalSeconds );
    
    // Note: The UTC_OFFSET only needs to be passed once.
    
    unsigned short minutes = TimeConverter::getInstance()->getMinutes( totalSeconds );
    
    unsigned short seconds = TimeConverter::getInstance()->getSeconds( totalSeconds ); 

Programming the ESP13 board: See the image below.

  1. Use a jumper cable to join D0 to G. Note:
  • There is a 2 x 9 grid of pins with the two rows labelled G, 3V, D. Each column is numbered. This is where to find D0.
  • There is a 3 x 4 grid of pins with the three rows labelled A, 5V, G. Connecting D0 to any of the pins on the row labelled G is fine.
  1. Connect USB wires to the board to provide power and enable writing. Note:
  • There is a 2 x 4 grid of pins with the two rows labelled UART, OTH. The columns are labelled 3V3, G, RXO, TXO.
  • The red and black wires from the USB plug connect to the 3V3 and G pins, on the UART row, respectively.
  • The green and white wires from the USB plug connect to the RXO and TXO pins, on the same UART row, respectively.
  1. Select Generic ESP8266 Module as the board.
  2. The port may not have a descriptive label other than COM#.
  3. Code can now be uploaded to the ESP13 board.
  4. the RST button on the ESP13 board may need to be pressed before each upload.

Image(s)

alt text Fig 1. USB plug wiring as per the instructions described in the Programming the ESP13 board section.

Email any questions or comments to me, John, at [email protected]. Please begin your email title with "NTPClient Repo". I look forward to answering your questions or reading your comments.

arduino-ntp's People

Contributors

johngraham1979 avatar

Stargazers

 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.