Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "osapi.h"
- #include "user_interface.h"
- #define INFO( format, ... ) os_printf( format, ## __VA_ARGS__ )
- LOCAL os_timer_t ntp_timer;
- LOCAL char ssid[32] = "ssidthingy";
- LOCAL char password[64] = "passwordthingy";
- uint32 ICACHE_FLASH_ATTR user_rf_cal_sector_set(void)
- {
- return 1019;
- }
- void NTPTimer(void* arg)
- {
- static uint8_t cnt = 50;
- uint32 current_stamp;
- current_stamp = sntp_get_current_timestamp();
- if (current_stamp == 0 && cnt > 0)
- {
- cnt--;
- os_timer_arm(&ntp_timer, 100, 0);
- }
- else
- {
- INFO("Current timestamp (%d): %d - %s", cnt, current_stamp, sntp_get_real_time(current_stamp));
- }
- }
- void ICACHE_FLASH_ATTR mywifi_handle_events(System_Event_t *evt)
- {
- switch (evt->event)
- {
- case EVENT_STAMODE_CONNECTED:
- {
- break;
- }
- case EVENT_STAMODE_DISCONNECTED:
- {
- break;
- }
- case EVENT_STAMODE_GOT_IP:
- {
- sntp_init();
- os_timer_arm(&ntp_timer, 100, 0);
- }
- }
- }
- void ICACHE_FLASH_ATTR user_init(void)
- {
- gpio_init();
- uart_init(74880, 74880);
- struct station_config stConf;
- os_memcpy(&stConf.ssid, ssid, 32);
- os_memcpy(&stConf.password, password, 64);
- wifi_set_event_handler_cb(mywifi_handle_events);
- wifi_set_opmode_current(STATION_MODE);
- wifi_station_set_config(&stConf);
- wifi_set_sleep_type(NONE_SLEEP_T);
- os_timer_disarm(&ntp_timer);
- os_timer_setfn(&ntp_timer, (os_timer_func_t *)NTPTimer, NULL);
- sntp_setservername(0, "0.ca.pool.ntp.org"); // set server 0 by domain name
- sntp_setservername(1, "1.ca.pool.ntp.org"); // set server 1 by domain name
- sntp_setservername(2, "2.ca.pool.ntp.org"); // set server 2 by domain name
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement