cc3000_ntp_demo_F446RE

Dependencies:   NTPClient2 NVIC_set_all_priorities cc3000_hostdriver_mbedsocket mbed

Fork of cc3000_ntp_demo by Martin Kojtal

Files at this revision

API Documentation at this revision

Comitter:
JackB
Date:
Sat Oct 17 23:12:10 2015 +0000
Parent:
7:1c08892623a2
Commit message:
CC3000 NTP demo on Nucleo F446RE

Changed in this revision

NTPClient.lib Show annotated file Show diff for this revision Revisions of this file
NVIC_set_all_priorities.lib Show annotated file Show diff for this revision Revisions of this file
cc3000_hostdriver_mbedsocket.lib Show annotated file Show diff for this revision Revisions of this file
init.cpp Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
main.h Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 1c08892623a2 -r 6870e6801838 NTPClient.lib
--- a/NTPClient.lib	Tue Jun 03 08:41:53 2014 +0000
+++ b/NTPClient.lib	Sat Oct 17 23:12:10 2015 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/donatien/code/NTPClient/#881559865a93
+https://developer.mbed.org/users/JackB/code/NTPClient2/#adfce3421f39
diff -r 1c08892623a2 -r 6870e6801838 NVIC_set_all_priorities.lib
--- a/NVIC_set_all_priorities.lib	Tue Jun 03 08:41:53 2014 +0000
+++ b/NVIC_set_all_priorities.lib	Sat Oct 17 23:12:10 2015 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/frankvnk/code/NVIC_set_all_priorities/#01504ecd2025
+http://mbed.org/users/frankvnk/code/NVIC_set_all_priorities/#8acd3bf521ff
diff -r 1c08892623a2 -r 6870e6801838 cc3000_hostdriver_mbedsocket.lib
--- a/cc3000_hostdriver_mbedsocket.lib	Tue Jun 03 08:41:53 2014 +0000
+++ b/cc3000_hostdriver_mbedsocket.lib	Sat Oct 17 23:12:10 2015 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/Kojto/code/cc3000_hostdriver_mbedsocket/#50ab13d8f2dc
+https://developer.mbed.org/users/JackB/code/cc3000_hostdriver_mbedsocket/#64f025c8d3e3
diff -r 1c08892623a2 -r 6870e6801838 init.cpp
--- a/init.cpp	Tue Jun 03 08:41:53 2014 +0000
+++ b/init.cpp	Sat Oct 17 23:12:10 2015 +0000
@@ -16,55 +16,12 @@
 #include "main.h"
 #include "mbed.h"
 
-#if (MY_BOARD == WIGO)
-
-#include "NVIC_set_all_priorities.h"
-
-/**
- *  \brief Wi-Go initialization
- *  \param none
- *  \return none
- */
-void init() {
-    DigitalOut PWR_EN1(PTB2);
-    DigitalOut PWR_EN2(PTB3);
-
-    // Wi-Go set current to 500mA since we're turning on the Wi-Fi
-    PWR_EN1 = 0;
-    PWR_EN2 = 1;
-
-    NVIC_set_all_irq_priorities(3);
-    NVIC_SetPriority(SPI0_IRQn, 0x0);     // Wi-Fi SPI interrupt must be higher priority than SysTick
-    NVIC_SetPriority(PORTA_IRQn, 0x1);
-    NVIC_SetPriority(SysTick_IRQn, 0x2);  // SysTick set to lower priority than Wi-Fi SPI bus interrupt
-    PORTA->PCR[16] |=PORT_PCR_ISF_MASK;
-    PORTA->ISFR |= (1 << 16);
-}
-
-#elif (MY_BOARD == WIFI_DIPCORTEX)
-
-/**
- *  \brief Wifi DipCortex initialization
- *  \param none
- *  \return none
- */
-void init() {
-    NVIC_SetPriority(SSP1_IRQn, 0x0);
-    NVIC_SetPriority(PIN_INT0_IRQn, 0x1);
-
-    // SysTick set to lower priority than Wi-Fi SPI bus interrupt
-    NVIC_SetPriority(SysTick_IRQn, 0x2);
-}
-
-#else
-
-/**
- *  \brief Place here init routine for your board
- *  \param none
- *  \return none
- */
-void init() {
-
-}
-
+#if defined (TARGET_NUCLEO_F446RE)
+    #include "NVIC_set_all_priorities.h"
+    void init() {
+        NVIC_set_all_irq_priorities(3);
+        NVIC_SetPriority(SPI1_IRQn, 0x0);     // Wi-Fi SPI interrupt must be higher priority than SysTick
+        NVIC_SetPriority(EXTI3_IRQn, 0x1);    // PB3 interrupt
+        NVIC_SetPriority(SysTick_IRQn, 0x2);  // SysTick set to lower priority than Wi-Fi SPI bus interrupt
+    }
 #endif
diff -r 1c08892623a2 -r 6870e6801838 main.cpp
--- a/main.cpp	Tue Jun 03 08:41:53 2014 +0000
+++ b/main.cpp	Sat Oct 17 23:12:10 2015 +0000
@@ -18,20 +18,28 @@
 #include "main.h"
 #include "NTPClient.h"
 
+#define CC3000_IRQ   D3  // (D3)
+#define CC3000_EN    D5  // (D5)
+#define CC3000_CS    D10 // (D10)
+#define CC3000_MOSI  D11 // (D11)
+#define CC3000_MISO  D12 // (D12)
+#define CC3000_SCLK  D13 // (D13)
+
+#define SSID         "Prakjaroen"
+#define PHRASE       "A4B5C6D7E8F9"
+#define SECURITY     WPA2
+
+#define IP           "192.168.2.165"
+#define MASK         "255.255.255.0"
+#define GW           "192.168.2.1"
+#define DHCP         1
+
 using namespace mbed_cc3000;
 
-/* cc3000 module declaration specific for user's board. Check also init() */
-#if (MY_BOARD == WIGO)
-cc3000 wifi(PTA16, PTA13, PTD0, SPI(PTD2, PTD3, PTC5), "ssid", "key", WPA2, false);
+#if defined TARGET_NUCLEO_F446RE
+//cc3000 wifi(IRQ, EN, CS, SPI(MOSI, MISO, SCLK), SSID, PHRASE, SECURITY, false);
+cc3000 wifi(D3, D5, D10, SPI(D11, D12, D13), "Prakjaroen", "A4B5C6D7E8F9", WPA2, false);
 Serial pc(USBTX, USBRX);
-#elif (MY_BOARD == WIFI_DIPCORTEX)
-cc3000 wifi(p28, p27, p30, SPI(p21, p14, p37), "ssid", "key", WPA2, false);
-Serial pc(UART_TX, UART_RX);
-#elif (MY_BOARD == MBED_BOARD_EXAMPLE)
-cc3000 wifi(p9, p10, p8, SPI(p5, p6, p7), "ssid", "key", WPA2, false);
-Serial pc(USBTX, USBRX);
-#else
-
 #endif
 
 /**
@@ -41,31 +49,72 @@
  */
 int main() {
     init(); /* board dependent init */
-    pc.baud(115200);
+    pc.baud(230400);
     
-    printf("cc3000 NTP client demo. \r\n");
+    printf("\r\n--------------------------------------------------------------------------------\r\n");
+    printf("cc3000 NTP client demo.\r\n");
+#if (DHCP == 1)
+    printf("Initialize the interface using DHCP...\r\n");
+    printf("wifi.init() ");
     wifi.init();
+#else
+    printf("Initialize the interface using a static IP address...\r\n");
+    printf("wifi.init(%s, %s, %s) ", IP, MASK, GW);
+    wifi.init(IP, MASK, GW);
+#endif
+    printf("done.\r\n");
+    printf("wifi.connect() ");
     if (wifi.connect() == -1) {
+        printf("failed.\r\n");
         printf("Failed to connect. Please verify connection details and try again. \r\n");
     } else {
-        printf("IP address: %s \r\n",wifi.getIPAddress());
+        printf("done.\r\n");
+        printf("IP address: %s \r\n", wifi.getIPAddress());
     }
 
-    NTPClient ntp;
+    NTPClient ntp_client;
+    time_t ct_time;
+    char time_buffer[80];    
+    char time_buffer_old[80];    
+    wait(1);
+
+    strcpy(time_buffer_old, "");
+
+    // Parameters
+    char* domain_name = "0.uk.pool.ntp.org";
+    int   port_number = 123;
+    
+    // Read time from server
+    printf("Reading time...\r\n");
+    ntp_client.setTime(domain_name, port_number);
+
+//    ct_time = time(NULL);
+//    strftime(time_buffer, 80, "%a %b %d %T %p %z %Z\n", localtime(&ct_time));
+//    printf("UTC/GMT: %s\n", time_buffer);
+//    printf("UTC %s\n", ctime(&ct_time));
 
-    printf("Getting time, 10s timeout. \r\n");
-    if (ntp.setTime("0.uk.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));
+    // Choose standard or daylight savings time, comment out other
+//    ct_time= time(NULL) + 3600; // Winter time - Convert to Europe/Amsterdam Time
+    ct_time = time(NULL) + 7200; // Summer time - Convert to Europe/Amsterdam Time
+    set_time(ct_time);
+
+//    ct_time = time(NULL);
+    strftime(time_buffer, 80, "%a %d-%b-%Y %T", localtime(&ct_time));
+    printf("%s\r\n", time_buffer);
+
+    while (1) {
+        ct_time = time(NULL);
+        strftime(time_buffer, 80, "%S", localtime(&ct_time));
+        if (strcmp(time_buffer, time_buffer_old) != 0) {
+            strcpy(time_buffer_old, time_buffer);
+            strftime(time_buffer, 80, "%a %d-%b-%Y %T", localtime(&ct_time));
+            printf("%s\r\n", time_buffer);
+            // Sync ones a day
+            strftime(time_buffer, 80, "%T", localtime(&ct_time));
+            if (strcmp(time_buffer, "00:00:00") == 0) {
+                ntp_client.setTime(domain_name, port_number);
+            }
+        }
     }
-    else
-    {
-        printf("Error. \r\n");
-    }
-
-    wifi.disconnect();
 }
 
diff -r 1c08892623a2 -r 6870e6801838 main.h
--- a/main.h	Tue Jun 03 08:41:53 2014 +0000
+++ b/main.h	Sat Oct 17 23:12:10 2015 +0000
@@ -16,13 +16,6 @@
 #ifndef MAIN_H
 #define MAIN_H
 
-#define WIGO               1
-#define WIFI_DIPCORTEX     2
-#define MBED_BOARD_EXAMPLE 3
-#define UNDEFINED          4
-
-#define MY_BOARD WIGO
-
 void init();
 
 #endif
diff -r 1c08892623a2 -r 6870e6801838 mbed.bld
--- a/mbed.bld	Tue Jun 03 08:41:53 2014 +0000
+++ b/mbed.bld	Sat Oct 17 23:12:10 2015 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/0b3ab51c8877
\ No newline at end of file
+http://mbed.org/users/mbed_official/code/mbed/builds/34e6b704fe68
\ No newline at end of file