Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add WiFi.getTime() to retrieve system time from WINC #84

Merged
merged 2 commits into from Sep 20, 2016

Conversation

sandeepmistry
Copy link
Contributor

This change requires IDE 1.6.10 for AVR based boards, because the newer version of AVR libc provides time.h which is needed for mktime to convert a decomposed time into epoch time.

Note: the Travis CI build is failing again for the Leonardo board because MDNS_WiFiWebServer sketch is too big again for the board. I think it's time to remove this board from the Travis CI build, it is listed as "retired" on Arduino.cc website.

@agdl
Copy link
Member

agdl commented Sep 20, 2016

tested with this example

#include <RTCZero.h>
#include <WiFi101.h>

char ssid[] = "ssid";      //  your network SSID (name)
char pass[] = "pass";   // your network password
int keyIndex = 0;            // your network key Index number (needed only for WEP)

int status = WL_IDLE_STATUS;

// Initialize the Wifi client library
WiFiClient client;

/* Create an rtc object */
RTCZero rtc;

void setup() {
  Serial.begin(9600);

  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

// check for the presence of the shield :
  if (WiFi.status() == WL_NO_SHIELD) {
      Serial.println("WiFi shield not present");
      // don't continue:
      while (true);
    }

  // attempt to connect to Wifi network:
  while ( status != WL_CONNECTED) {
    Serial.print("Attempting to connect to SSID: ");
    Serial.println(ssid);
    // Connect to WPA/WPA2 network. Change this line if using open or WEP network:
    status = WiFi.begin(ssid, pass);

    // wait 10 seconds for connection:
    delay(10000);
  }
  // you're connected now, so print out the status:
  printWifiStatus();

  rtc.begin(); // initialize RTC

  rtc.setEpoch(WiFi.getTime()); // Jan 1, 2016
}

void loop() {
  Serial.print("Unix time = ");
  Serial.println(rtc.getEpoch());

  Serial.print("Seconds since Jan 1 2000 = ");
  Serial.println(rtc.getY2kEpoch());

  // Print date...
  Serial.print(rtc.getDay());
  Serial.print("/");
  Serial.print(rtc.getMonth());
  Serial.print("/");
  Serial.print(rtc.getYear());
  Serial.print("\t");

  // ...and time
  print2digits(rtc.getHours());
  Serial.print(":");
  print2digits(rtc.getMinutes());
  Serial.print(":");
  print2digits(rtc.getSeconds());

  Serial.println();

  delay(1000);
}

void print2digits(int number) {
  if (number < 10) {
    Serial.print("0");
  }
  Serial.print(number);
}

void printWifiStatus() {
  // print the SSID of the network you're attached to:
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());

  // print your WiFi shield's IP address:
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);

  // print the received signal strength:
  long rssi = WiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.print(rssi);
  Serial.println(" dBm");
}

Basically RTC epoch example + WiFi connection

@agdl agdl merged commit e0435ba into arduino-libraries:master Sep 20, 2016
@akash73
Copy link

akash73 commented Sep 20, 2016

handled

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants