ArchMax_CC3000_NTP
Dependencies: NTPClient3 NVIC_set_all_priorities cc3000_hostdriver_mbedsocket mbed
Revision 0:0e8d73b27253, committed 2015-10-17
- Comitter:
- JackB
- Date:
- Sat Oct 17 23:31:20 2015 +0000
- Commit message:
- None
Changed in this revision
diff -r 000000000000 -r 0e8d73b27253 NTPClient.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/NTPClient.lib Sat Oct 17 23:31:20 2015 +0000 @@ -0,0 +1,1 @@ +https://developer.mbed.org/users/JackB/code/NTPClient3/#13ccddd70dcf
diff -r 000000000000 -r 0e8d73b27253 NVIC_set_all_priorities.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/NVIC_set_all_priorities.lib Sat Oct 17 23:31:20 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/frankvnk/code/NVIC_set_all_priorities/#c19fcbd73dbc
diff -r 000000000000 -r 0e8d73b27253 cc3000_hostdriver_mbedsocket.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cc3000_hostdriver_mbedsocket.lib Sat Oct 17 23:31:20 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/Kojto/code/cc3000_hostdriver_mbedsocket/#192e2fde71e9
diff -r 000000000000 -r 0e8d73b27253 init.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/init.cpp Sat Oct 17 23:31:20 2015 +0000 @@ -0,0 +1,70 @@ +/* mbed Microcontroller Library + * Copyright (c) 2006-2013 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#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() { + +} + +#endif
diff -r 000000000000 -r 0e8d73b27253 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Sat Oct 17 23:31:20 2015 +0000 @@ -0,0 +1,110 @@ +#include "mbed.h" +#include "main.h" +//#include "EthernetInterface.h" +#include "NTPClient.h" +//#include "NetworkAPI/buffer.hpp" +//#include "NetworkAPI/tcp/socket.hpp" +#include "cc3000.h" + +#define PORT 1234 +#define MAX_PENDING 1 + +#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 + +Serial pc(USBTX, USBRX); + +using namespace mbed_cc3000; + +cc3000 wifi(CC3000_IRQ, CC3000_EN, CC3000_CS, SPI(CC3000_MOSI, CC3000_MISO, CC3000_SCLK), SSID, PHRASE, SECURITY, false); //SparkFun Board on Arduino pin definitions + +// array to store RM parameters from EEPROM +unsigned char cRMParamsFromEeprom[128]; + +// array to store MAC address from EEPROM +unsigned char cMacFromEeprom[6]; + +int main() { + init(); /* board dependent init */ + pc.baud(230400); + + 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("done.\r\n"); + printf("IP address: %s \r\n", wifi.getIPAddress()); + } + + 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)); + + // 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); + } + } + } +} +
diff -r 000000000000 -r 0e8d73b27253 main.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.h Sat Oct 17 23:31:20 2015 +0000 @@ -0,0 +1,21 @@ +/* mbed Microcontroller Library + * Copyright (c) 2006-2013 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef MAIN_H +#define MAIN_H + +void init(); + +#endif
diff -r 000000000000 -r 0e8d73b27253 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Sat Oct 17 23:31:20 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/34e6b704fe68 \ No newline at end of file