mirror of
https://github.com/oopuuu/zTC1.git
synced 2025-12-12 21:18:13 +08:00
add:增加sntp功能
This commit is contained in:
@@ -25,5 +25,8 @@
|
|||||||
NAME := App_TC1
|
NAME := App_TC1
|
||||||
|
|
||||||
$(NAME)_SOURCES := main.c\
|
$(NAME)_SOURCES := main.c\
|
||||||
wifi.c\
|
user_wifi.c\
|
||||||
key.c
|
user_key.c\
|
||||||
|
user_sntp.c
|
||||||
|
|
||||||
|
$(NAME)_COMPONENTS := protocols/SNTP
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include "key.h"
|
|
||||||
#include "wifi.h"
|
#include "user_key.h"
|
||||||
|
#include "user_wifi.h"
|
||||||
|
|
||||||
#define os_log(format, ...) custom_log("TC1", format, ##__VA_ARGS__)
|
#define os_log(format, ...) custom_log("TC1", format, ##__VA_ARGS__)
|
||||||
|
|
||||||
|
|||||||
@@ -35,10 +35,10 @@
|
|||||||
|
|
||||||
#define APP_INFO "MiCO BASIC Demo"
|
#define APP_INFO "MiCO BASIC Demo"
|
||||||
|
|
||||||
#define FIRMWARE_REVISION "MICO_BASIC_1_0"
|
#define FIRMWARE_REVISION "ZYC_BASIC_1_0"
|
||||||
#define MANUFACTURER "MXCHIP Inc."
|
#define MANUFACTURER "ZYC Inc."
|
||||||
#define SERIAL_NUMBER "20140606"
|
#define SERIAL_NUMBER "20190105"
|
||||||
#define PROTOCOL "com.mxchip.basic"
|
#define PROTOCOL "com.zyc.basic"
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* Application thread stack size */
|
* Application thread stack size */
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ static void key_long_press(void)
|
|||||||
{
|
{
|
||||||
os_log("key_long_press");
|
os_log("key_long_press");
|
||||||
MicoGpioOutputHigh(MICO_GPIO_5);
|
MicoGpioOutputHigh(MICO_GPIO_5);
|
||||||
|
|
||||||
}
|
}
|
||||||
static void key_short_press(void)
|
static void key_short_press(void)
|
||||||
{
|
{
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
|
|
||||||
#ifndef __KEY_H_
|
#ifndef __USER_KEY_H_
|
||||||
#define __KEY_H_
|
#define __USER_KEY_H_
|
||||||
|
|
||||||
|
|
||||||
#include "mico.h"
|
#include "mico.h"
|
||||||
45
TC1/user_sntp.c
Normal file
45
TC1/user_sntp.c
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
|
||||||
|
#define os_log(format, ...) custom_log("SNTP", format, ##__VA_ARGS__)
|
||||||
|
|
||||||
|
#include "main.h"
|
||||||
|
//#include "key.h"
|
||||||
|
#include "user_sntp.h"
|
||||||
|
|
||||||
|
/* Callback function when MiCO UTC time in sync to NTP server */
|
||||||
|
static void sntp_time_call_back( void )
|
||||||
|
{
|
||||||
|
struct tm * currentTime;
|
||||||
|
// iso8601_time_t iso8601_time;
|
||||||
|
mico_utc_time_t utc_time;
|
||||||
|
mico_rtc_time_t rtc_time;
|
||||||
|
|
||||||
|
// mico_time_get_iso8601_time( &iso8601_time );
|
||||||
|
// os_log("sntp_time_synced: %.26s", (char*)&iso8601_time);
|
||||||
|
|
||||||
|
mico_time_get_utc_time( &utc_time );
|
||||||
|
utc_time+=28800; //+8:00
|
||||||
|
currentTime = localtime( (const time_t *)&utc_time );
|
||||||
|
rtc_time.sec = currentTime->tm_sec;
|
||||||
|
rtc_time.min = currentTime->tm_min;
|
||||||
|
rtc_time.hr = currentTime->tm_hour;
|
||||||
|
|
||||||
|
rtc_time.date = currentTime->tm_mday;
|
||||||
|
rtc_time.weekday = currentTime->tm_wday;
|
||||||
|
rtc_time.month = currentTime->tm_mon + 1;
|
||||||
|
rtc_time.year = (currentTime->tm_year + 1900) % 100;
|
||||||
|
|
||||||
|
MicoRtcSetTime( &rtc_time );
|
||||||
|
|
||||||
|
|
||||||
|
MicoRtcGetTime(&rtc_time);
|
||||||
|
os_log("time:20%d/%d/%d %d %d:%d:%d",rtc_time.year,rtc_time.month,rtc_time.date,rtc_time.weekday,rtc_time.hr,rtc_time.min,rtc_time.sec);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void sntp_init(void)
|
||||||
|
{
|
||||||
|
struct in_addr ipp;ipp.s_addr=0xd248912c;
|
||||||
|
sntp_set_server_ip_address (0,ipp);
|
||||||
|
sntp_start_auto_time_sync (15000, sntp_time_call_back);
|
||||||
|
}
|
||||||
13
TC1/user_sntp.h
Normal file
13
TC1/user_sntp.h
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
|
||||||
|
#ifndef __USER_SNTP_H_
|
||||||
|
#define __USER_SNTP_H_
|
||||||
|
|
||||||
|
|
||||||
|
#include "mico.h"
|
||||||
|
#include "MiCOKit_EXT.h"
|
||||||
|
|
||||||
|
extern void sntp_init(void);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -1,6 +1,9 @@
|
|||||||
|
#include "user_wifi.h"
|
||||||
|
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include "wifi.h"
|
#include "mico_socket.h"
|
||||||
#include "key.h"
|
#include "user_sntp.h"
|
||||||
|
#include "user_key.h"
|
||||||
|
|
||||||
#define os_log(format, ...) custom_log("WIFI", format, ##__VA_ARGS__)
|
#define os_log(format, ...) custom_log("WIFI", format, ##__VA_ARGS__)
|
||||||
|
|
||||||
@@ -31,7 +34,7 @@ void wifi_start_easylink( )
|
|||||||
micoWlanStartEasyLink( 20000 );
|
micoWlanStartEasyLink( 20000 );
|
||||||
led( 1 );
|
led( 1 );
|
||||||
}
|
}
|
||||||
|
uint32_t ip=0xd248912c;
|
||||||
//easylink 完成回调
|
//easylink 完成回调
|
||||||
void wifi_easylink_completed_handle( network_InitTypeDef_st *nwkpara, void * arg )
|
void wifi_easylink_completed_handle( network_InitTypeDef_st *nwkpara, void * arg )
|
||||||
{
|
{
|
||||||
@@ -60,22 +63,13 @@ void wifi_easylink_completed_handle( network_InitTypeDef_st *nwkpara, void * arg
|
|||||||
os_log("EasyLink stop");
|
os_log("EasyLink stop");
|
||||||
micoWlanStopEasyLink( );
|
micoWlanStopEasyLink( );
|
||||||
}
|
}
|
||||||
|
|
||||||
//wifi已连接获取到IP地址 回调
|
//wifi已连接获取到IP地址 回调
|
||||||
static void wifi_get_ip_callback( IPStatusTypedef *pnet, void * arg )
|
static void wifi_get_ip_callback( IPStatusTypedef *pnet, void * arg )
|
||||||
{
|
{
|
||||||
os_log("got IP:%s", pnet->ip);
|
os_log("got IP:%s", pnet->ip);
|
||||||
wifi_status = WIFI_STATE_CONNECTED;
|
wifi_status = WIFI_STATE_CONNECTED;
|
||||||
|
|
||||||
// /* Store SSID and KEY*/
|
|
||||||
// mico_rtos_lock_mutex( &inContext->flashContentInRam_mutex );
|
|
||||||
// memcpy( inContext->flashContentInRam.micoSystemConfig.ssid, nwkpara->wifi_ssid, maxSsidLen );
|
|
||||||
// memset( inContext->flashContentInRam.micoSystemConfig.bssid, 0x0, 6 );
|
|
||||||
// memcpy( inContext->flashContentInRam.micoSystemConfig.user_key, nwkpara->wifi_key, maxKeyLen );
|
|
||||||
// inContext->flashContentInRam.micoSystemConfig.user_keyLength = strlen( nwkpara->wifi_key );
|
|
||||||
// inContext->flashContentInRam.micoSystemConfig.dhcpEnable = true;
|
|
||||||
// mico_rtos_unlock_mutex( &inContext->flashContentInRam_mutex );
|
|
||||||
// system_log("Get SSID: %s, Key: %s", inContext->flashContentInRam.micoSystemConfig.ssid, inContext->flashContentInRam.micoSystemConfig.user_key);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
//wifi连接状态改变回调
|
//wifi连接状态改变回调
|
||||||
static void wifi_status_callback( WiFiEvent status, void *arg )
|
static void wifi_status_callback( WiFiEvent status, void *arg )
|
||||||
@@ -106,7 +100,7 @@ static void wifi_led_timer_callback( void* arg )
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case WIFI_STATE_CONNECTING:
|
case WIFI_STATE_CONNECTING:
|
||||||
if ( num > 2 )
|
if ( num > 1 )
|
||||||
{
|
{
|
||||||
num = 0;
|
num = 0;
|
||||||
led( -1 );
|
led( -1 );
|
||||||
@@ -146,7 +140,7 @@ void wifi_init( void )
|
|||||||
mico_system_notify_register( mico_notify_DHCP_COMPLETED, (void *) wifi_get_ip_callback, NULL );
|
mico_system_notify_register( mico_notify_DHCP_COMPLETED, (void *) wifi_get_ip_callback, NULL );
|
||||||
//wifi连接状态改变回调
|
//wifi连接状态改变回调
|
||||||
mico_system_notify_register( mico_notify_WIFI_STATUS_CHANGED, (void*) wifi_status_callback, NULL );
|
mico_system_notify_register( mico_notify_WIFI_STATUS_CHANGED, (void*) wifi_status_callback, NULL );
|
||||||
|
sntp_init();
|
||||||
//启动定时器开始进行wifi连接
|
//启动定时器开始进行wifi连接
|
||||||
if ( !mico_rtos_is_timer_running( &wifi_led_timer ) ) mico_rtos_start_timer( &wifi_led_timer );
|
if ( !mico_rtos_is_timer_running( &wifi_led_timer ) ) mico_rtos_start_timer( &wifi_led_timer );
|
||||||
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
|
|
||||||
#ifndef __WIFI_H_
|
#ifndef __USER_WIFI_H_
|
||||||
#define __WIFI_H_
|
#define __USER_WIFI_H_
|
||||||
|
|
||||||
|
|
||||||
#include "mico.h"
|
#include "mico.h"
|
||||||
1
mico-os.component
Normal file
1
mico-os.component
Normal file
@@ -0,0 +1 @@
|
|||||||
|
https://code.aliyun.com/mico/mico-os.git/#6c465211d3ff8797cd835e400ec54a06530dd476
|
||||||
Reference in New Issue
Block a user