1647 views|8 replies

538

Posts

3

Resources
The OP
 

[RVB2601 Creative Application Development] 6. Online Weather Clock Draft Version [Copy link]

 

1. Description

Basic functions of Internet weather clock:

1. RTC real-time clock display and automatic time synchronization upon power on

2. Real-time weather information display

3. Future weather forecast (the plan is to provide weather forecast for the next 3 days, but I found that the free version of YY Weather can only forecast the weather for the current day and the next day )

In fact, the function is quite simple, it just took a long time to set up WiFi networking and NTP. Although NTP can currently synchronize time, it still feels imperfect.

2. Software modules/open source libraries used

1. u8g2 open source graphics library for display

2. cJSON open source library for parsing data in JSON format

3. MulitButton open source library for button operation

4. At the OS level, a software timer is used to periodically obtain and display time, with a period of 1s;

Message queues are used to implement cross-task communication and transmit weather data;

Events are used for task synchronization.

3. Key Functions

1. NTP network time synchronization

Regarding the NTP issue, several big guys in the forum have already written a manual to avoid pitfalls. There will be basically no problem with the configuration according to their posts.

I use version 7.4.6 of the ntp component, and I can't get version 7.4.3 to work.

The current version sometimes takes several attempts to succeed, and I have built a retry mechanism in my own code.

After ntp time synchronization is completed, set the event to let the GUI task area obtain the time for display:

static void network_event(uint32_t event_id, const void *param, void *context)
{
    switch(event_id) {
    case EVENT_NETMGR_GOT_IP:
        LOGD(TAG, "net got ip");
		do
		{
			ntp_status = ntp_sync_time(NULL);
		}while(ntp_status != 0);
		/*设置事件标志(0x00000001), 或操作*/
		aos_event_set(&ntp_complete_event, EVENT_FLAG_1, AOS_EVENT_OR);		
		//cjson_test ();
        break;
    case EVENT_NETMGR_NET_DISCON:
        LOGD(TAG, "net disconnect");
        break;
    }

    /*do exception process */
    app_exception_event(event_id);
}

2. GUI Tasks

The GUI task is to receive messages from the message queue and display different contents according to the message type.

The main body is as follows:

    while (1) {
		//button_test();
		button_ticks();
		//check data receive
		if(0 != aos_queue_is_valid(&queue_weather))
		{
			if(0 == aos_queue_recv(&queue_weather, 5, queue_msg, &quene_size))
			{
				if(display_page == 1)//显示时钟
				{
					rtc_display_control(queue_msg);
				}
				else if(display_page == 2)//显示实时天气
				{
					weather_real_time_display(queue_msg);
				}
				else if((display_page == 3) || (display_page == 4))//显示预报天气
				{
					weather_forecast_display(queue_msg);
				}
				
			}			
		}
    }

3. Buttons

The button operation transplanted the MultiButton library, and only used the click events of two onboard buttons, one for page up and one for page down:

//按键事件的callback
static void BTN1_SINGLE_Click_Handler(void* btn)
{
	char temp[50];
	display_page++;
	if(display_page > 4)
	{
		display_page = 1;
	}
	if(display_page == 1)
	{
		temp[0] = 50;//切到第一屏
		temp[1] = '\0';
		if(0 != aos_queue_send(&queue_weather, temp, sizeof(temp)))
		{
			printf("send display_page error-->button2 singel click\n");
		}
	}	
	else if(display_page == 2)//实时天气获取与显示
	{
		quest_weather();
	}
	else if((display_page >= 3) && (display_page <=4 ))//未来某天天气预报
	{
		quest_weather_forecast();
	}	
}

//按键事件的callback
static void BTN2_SINGLE_Click_Handler(void* btn)
{
	char temp[50];
	
	if(display_page > 1)
	{
		display_page--;
		if(display_page == 1)
		{
			temp[0] = 50;//切到第一屏
			temp[1] = '\0';
			if(0 != aos_queue_send(&queue_weather, temp, sizeof(temp)))
			{
				printf("send display_page error-->button2 singel click\n");
			}
		}
		else if(display_page == 2)//实时天气获取与显示
		{
			quest_weather();
		}
		else if((display_page >= 3) && (display_page <=4 ))//未来某天天气预报
		{
			quest_weather_forecast();
	}			
	}
	
}

4. Effect display


Latest reply

Can I use RVB2601's WiFi to connect to a network that requires authentication?   Details Published on 2022-5-11 15:41
 
 

6818

Posts

11

Resources
2
 

There is progress, congratulations!

Comments

Thank you, but there is still a long way to go  Details Published on 2022-5-3 20:13
 
 
 

538

Posts

3

Resources
3
 
lugl4313820 posted on 2022-5-3 19:45 There is progress, congratulations!

Thank you, there is still a long way to go

 
 
 

6818

Posts

11

Resources
4
 

Could you please send me your NTP example so I can learn from it?

 
 
 

538

Posts

3

Resources
5
 
lugl4313820 posted on 2022-5-3 20:22 Can you send me your NTP example for me to learn from?

My changes are very simple, just two steps:

1. Modify the function in w800_api.c: int w800_connect_remote(int id, net_conn_e type, char *srvname, uint16_t port)

specific:

int w800_connect_remote(int id, net_conn_e type, char *srvname, uint16_t port)
{
int ret = -1;
int ret_id;

uint16_t local_port = 1024;

if (g_net_status < NET_STATUS_GOTIP) {
LOGE(TAG, "net status error\n");
return -1;
}

aos_mutex_lock(&g_cmd_mutex, AOS_WAIT_FOREVER);

atparser_clr_buf(g_atparser_uservice_t);

switch (type) {
case NET_TYPE_TCP_SERVER:
/* TCP Server can NOT ignore lport */
break;

case NET_TYPE_UDP_UNICAST:
ret = atparser_send(g_atparser_uservice_t, "AT+CIPSTART=%d,%s,%s,%d,%d", id, "udp_unicast", srvname, port,local_port);
break;

case NET_TYPE_TCP_CLIENT:
ret = atparser_send(g_atparser_uservice_t, "AT+CIPSTART=%d,%s,%s,%d", id, "tcp_client", srvname, port);
break;

default:
LOGE(TAG, "type=%d err!", type);
return -1;

}

if (ret == 0) {
ret = -1;

if ((atparser_recv(g_atparser_uservice_t, "OK\n") == 0) \
&& (atparser_recv(g_atparser_uservice_t, "+EVENT=CONNECT,%d\n", &ret_id) == 0)) {
if (ret_id == id ) {
ret = 0;
}
}
}

atparser_cmd_exit(g_atparser_uservice_t);

aos_mutex_unlock(&g_cmd_mutex);

return ret;
}

2. The ntp component uses version 7.4.6

After the above two operations, ntp can obtain the correct time.

Comments

Thank you very much, I'll try it back.  Details Published on 2022-5-4 15:20
 
 
 

6818

Posts

11

Resources
6
 
xinmeng_wit posted on 2022-5-4 09:20 My changes are very simple, just two steps: 1. Modify the function in w800_api.c: int w800_connect_remote(int id, net_conn_e ...

Thank you very much, I'll try it back.

 
 
 

396

Posts

4

Resources
7
 

Oh my, this is well done, much better than what I did. It supports inputting and saving WIFI SSID and password, and supports custom input of NTP IP address. It's perfect.

Comments

Very good suggestion, it is indeed possible  Details Published on 2022-5-7 18:13
 
 
 

538

Posts

3

Resources
8
 
ylyfxzsx posted on 2022-5-7 13:46 Oh my, this is well done, much better than what I did. Make a host computer that supports input and save WIFI SSID and password, and supports custom input of NTP IP address...

The suggestion is very good, it is indeed possible to have

 
 
 

149

Posts

0

Resources
9
 

Can I use RVB2601's WiFi to connect to a network that requires authentication?

 
 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list