Skip to content

denis-stepanov/esp-ds-system

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Library of reusable functions for rapid development of ESP8266 sketches. Helps avoiding copy-pasting supporting code from one sketch to another and focus straight away on sketch business.

Supported features (aka "system capabilities")

The strong part of the library is that capabilities know about each other and often have synergy. E.g., if you activate both 'time' and 'network', time will be automatically sync from NTP; and if you add a 'led' on top, Wi-Fi connection process will be signalled with LED.

Most features rely on ESP8266 Arduino Core or several other excellent libraries from GitHub, and make just a thin interface on top. Library objects are deliberately declared public, so you have full access to the native interface, should you need it. Few things I haven't found a good support for and implemented myself:

Application Identification

Application Logger with Log Rotation and Decent Web Browsing:

App Log

"About" Web Page Listing Many ESP8266 Runtime Details:

About

User-configured Timers, Including Solar Events Support:

Web Timers

Usage

  1. Download the latest release locally (installation via Arduino Library Manager is not supported - see why);

  2. Copy files System.h, System.cpp and MySystem.h from src/ into your sketch folder. Reopen sketch in Arduino if you had it opened.

  3. Uncomment the desired features in MySystem.h;

  4. Add the following lines in your sketch (.ino):

     #include "MySystem.h"
     
     using namespace ds;
     ...
    
     void setup() {
     	System::begin();   // Could be omitted for some capabilities
     	...
     }
    
     void loop() {
     	...
     	System::update();  // Could be omitted for some capabilities
     }
    

Example: NTP Support

MySystem.h:

#define DS_CAP_SYS_NETWORK  // Enable network
#define DS_CAP_SYS_TIME     // Enable system time
#define DS_CAP_SYS_LOG_HW   // Enable syslog on hardware serial line

#define DS_TIMEZONE TZ_Europe_Paris  // Timezone. Pick yours from TZ.h coming with ESP Core

#include "System.h"         // System global definitions

sketch.ino:

#include "MySystem.h"

using namespace ds;

// Set network parameters
const char *System::wifi_ssid = "mySSID";             // Network SSID
const char *System::wifi_pass = "myPassword";         // Network password

void setup() {
  System::begin();
  delay(2000);           // Allow time to synchronize
  System::log->print("Current time: ");
  System::log->println(System::getTimeStr());  
}

void loop() {
  System::update();
}

That's it! Output when run:

0000000066: Started
0000000067: Connecting to network 'mySSID'... connected. IP address: 192.168.1.2
0000005969: Starting NTP client service... OK
0000005970: DS System v10100 initialization completed. Configured capabilities: SYS_LOG_HW SYS_TIME SYS_NETWORK
0000007974: System clock set: 2020/10/08 23:30:50
Current time: 2020/10/08 23:30:50

For detailed information and examples see Wiki pages.