This is a modification of the NTPClient_HelloWorld to use the wifly link instead of the eth link

Dependencies:   mbed LM75B NTPClient WiflyInterface MMA7660 WebSocketClient

wifly-ntpc.cpp

Committer:
jpelletier
Date:
2019-11-10
Revision:
7:cf51acd03e52

File content as of revision 7:cf51acd03e52:

#include "mbed.h"
#include "WiflyInterface.h"
#include "LM75B.h"
#include "MMA7660.h"
#include "NTPClient.h"

/* wifly interface:
*     - p9 and p10 are for the serial communication
*     - p30 is for the reset pin
*     - p29 is for the connection status
*     - "mbed" is the ssid of the network
*     - "password" is the password
*     - WPA is the security
*/
WiflyInterface wifly(p9, p10, p30, p29, "mbed", "password", WPA);
NTPClient ntp;

int main()
{
    wifly.init(); //Use DHCP
    while (!wifly.connect());
    printf("IP Address is %s\n\r", wifly.getIPAddress());
    
    printf("Trying to update time...\r\n");
    if (ntp.setTime("0.pool.ntp.org") == 0)
    {
      printf("Set time successfully\r\n");
      time_t ctTime;
      ctTime = time(NULL);
      printf("Time is set to (UTC): %s\r\n", ctime(&ctTime));
    }
    else
    {
      printf("Error\r\n");
    } 
}