Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By DaveEvans
#53880 I was surprised that the following code [using only WiFi.waitForConnectResult()] connects to my router (and the internetz)...seemingly without using an SSID or password. How is that possible? Does the ESP8266 (Huzzah) store the SSID and password from previous sketches?

Code: Select all// this code prints out time and date from NTP servers
// source: http://www.esp8266.com/viewtopic.php?f=5&t=10094
//
// Somehow, this works without needing ssid and password!!
//
#include <ESP8266WiFi.h>
#include <time.h>

struct tm* tmStrc;

void setup() {
    Serial.begin(115200); Serial.println();
    WiFi.waitForConnectResult();
    configTime(-8 * 3600, 0, "pool.ntp.org", "time.nist.gov");
    // 0 * 3600 appears to give time in UTC.
    // currently, Alaska time is 8 hrs behind UTC, and
    // -8 * 3600 gives correct Alaska time as of Aug 2016 (DST).
    // DST starts mid-March, ends early November
   
}

void loop() {
    time_t t = time(NULL);
    Serial.println(ctime(&t));
    // first time thru, this prints:
    // Thu Jan  1 00:00:00 1970
    // next loop, correct date/time prints:
    // Fri Aug 26 16:06:13 2016

    tmStrc = localtime (&t);
    Serial.println(tmStrc->tm_mday);
    Serial.println((tmStrc->tm_mon)+1);
    Serial.println((tmStrc->tm_year)+1900);
    // more info on the tm struct here
    // http://en.cppreference.com/w/c/chrono/tm
   
    delay(30000);
}