1545 views|4 replies

295

Posts

0

Resources
The OP
 

[RVB2601 Creative Application Development] 5. Initial test of RVB2601 WiFi networking and data interaction [Copy link]

 

Pingtou Ge RVB2601 provides a web player demo. After running it, I couldn't find the resource http://xxx.com/abcd.mp3 for evaluation.

It's actually a WEB player, so it must be able to connect to the Internet. I have been trying to find a demo example of Pingtou Ge connecting to the Internet, but I haven't found a suitable one. After reading many blog posts on the Pingtou Ge website,

I also planned to try out the networking routine, so I copied the ch2601_webplayer_demo routine and renamed it to ch2601_wifitest_demo

Then changed the project file name, etc.

More on Pingtouge's blog, added the int w800_connect_srv(char *srvname, uint16_t port) function in W800_api.c to facilitate direct TCP networking later

Modified init.c in the original Web player to facilitate network testing

#include <stdbool.h>
#include <aos/kv.h>
#include <yoc/partition.h>
#include <yoc/init.h>
#include <drv/pin.h>
#include <yoc/at_port.h>
#include <devices/w800.h>
#include <devices/drv_snd_alkaid.h>

#include "app_main.h"
#include "board.h"

#define TAG "init"

netmgr_hdl_t app_netmgr_hdl;
extern at_channel_t spi_channel;

void w800_in(int linkid, void *data, size_t len, char remote_ip[16], uint16_t remote_ports)
{
	uint8_t* d;
	d=(uint8_t *)data;
	printf("data:%x,%x,%x,%x,%x ... \n",d[0],d[1],d[2],d[3],d[4]);
	printf("rev:%s\n",data);
}

typedef void (*net_data_input_cb_t)(int linkid, void *data, size_t len, char remote_ip[16], uint16_t remote_ports);
extern int w800_packet_input_cb_register(net_data_input_cb_t cb);
//net_data_input_cb_t cb = &w800_in;
extern int w800_module_init(utask_t *task, w800_wifi_param_t *param);

static void network_init()
{
    w800_wifi_param_t w800_param;
    /* init wifi driver and network */
    w800_param.reset_pin      = PA21;
    w800_param.baud           = 1*1000000;
    w800_param.cs_pin         = PA15;
    w800_param.wakeup_pin     = PA25;
    w800_param.int_pin        = PA22;
    w800_param.channel_id     = 0;
    w800_param.buffer_size    = 4*1024;

    wifi_w800_register(NULL, &w800_param);
    app_netmgr_hdl = netmgr_dev_wifi_init();

    if (app_netmgr_hdl) {
        utask_t *task = utask_new("netmgr", 2 * 1024, QUEUE_MSG_COUNT, AOS_DEFAULT_APP_PRI);
        netmgr_service_init(task);
        netmgr_config_wifi(app_netmgr_hdl, "TP-LINK_xxxx", 12, "12345678900", 11);
		w800_module_init(task,  &w800_param);
		w800_packet_input_cb_register(&w800_in);
        netmgr_start(app_netmgr_hdl);
    }
}

void board_yoc_init(void)
{
    board_init();
    event_service_init(NULL);
    console_init(CONSOLE_UART_IDX, 115200, 512);
    //ulog_init();
    //aos_set_log_level(AOS_LL_DEBUG);

    //int ret = partition_init();
    //if (ret <= 0) {
    //    LOGE(TAG, "partition init failed");
    //} else {
    //    LOGI(TAG, "find %d partitions", ret);
    //}

    aos_kv_init("kv");
    //snd_card_alkaid_register(NULL);
    network_init();

    board_cli_init();
}

w800_in is the callback function that simply prints the received data.

netmgr_config_wifi configures the ssid and pswd of WiFi.

Some changes were also made in the main function.

/*
 * Copyright (C) 2019-2020 Alibaba Group Holding Limited
 */
#include <stdlib.h>
#include <string.h>
#include <aos/list.h>
#include <aos/debug.h>

#include <uservice/uservice.h>
#include <uservice/eventid.h>
#include <yoc/sysinfo.h>
#include <board.h>
#include "player_demo.h"

#include "app_main.h"

#define TAG "APP"

extern int w800_software_reset(void);
extern int w800_ap_info(char ssid[32], int bssid[6], int *channel, int *rssi);
extern int w800_get_status(int *stat);
extern int w800_connect_srv(char *srvname, uint16_t port);
extern int w800_send_data(const uint8_t *pdata, int len,int timeout);

static void cmd_at_client_handler(void);

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");
        break;
    case EVENT_NETMGR_NET_DISCON:
        LOGD(TAG, "net disconnect");
        break;
    }

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

#include <aos/cli.h>

int cli_reg_cmd_at(void)
{
    static const struct cli_command at_cmd_info = {
        "attest",
        "at client test",
        cmd_at_client_handler,
    };
    aos_cli_register_command(&at_cmd_info);
    return 0;
}

static void cmd_at_client_handler(void)
{
	const uint8_t pdata[]="{\"M\":\"checkin\",\"ID\":\"25923\",\"K\":\"df02bd2ef\"}\n";
	char ssid[32];
	int bssid[6];
	int channel;
	int rssi;
	int status = 0;

	while(status != 2) {
		w800_ap_info( ssid, bssid , &channel,  &rssi);
		printf("ssid: %s\r\n", ssid);
		printf("channel: %d\r\n", channel);
		printf("rssi: %d\r\n", rssi);
		w800_get_status( &status); //[  16.360]<D>w800_api link status 2 已获取到ip
		printf("w800_get_status: %d\r\n", status);
		aos_msleep(2000); 
	}

	char *srvname="www.bigiot.net";
	uint16_t port = 8181;
	status = w800_connect_srv(srvname, port);
	printf("w800_connect_srv: %d\r\n", status);
	
	int len;
	len=strlen(pdata);
	int timeout=120;
	status = w800_send_data(pdata, len, timeout);
	printf("w800_send_data: %d\r\n", status);
}
		 
static void iot_time(void)
{
	const uint8_t pdata[]="{\"M\":\"time\",\"F\":\"Y-m-d-w H:i:s\"}\n";
	int len;
	len=strlen(pdata);
	int timeout=120;
	w800_send_data(pdata, len, timeout);
}


int main(void)
{
	//int *stu;
	board_yoc_init();
	//player_init();
	netmgr_dev_wifi_init();
	//cli_reg_cmd_player();
	cli_reg_cmd_at();    
	/* Subscribe */
	event_subscribe(EVENT_NETMGR_GOT_IP, network_event, NULL);
	event_subscribe(EVENT_NETMGR_NET_DISCON, network_event, NULL);
	aos_msleep(10000);
	cmd_at_client_handler();
	while(1)
	{
		aos_msleep(10000);      
		//w800_get_status();
		//w800_iot_status();     
		iot_time(); 
	}
}

I used the method provided by the big guy above. The website www.bigiot.net provides some functions. I feel that the test is quite good. If you want to get the time, you have to register the user first, and then register the device. The operation is relatively simple.

Pins 1 and 2 of J4 of the development board are the serial ports on the CPU side, which are used for the output of the printf function.

Pins 3 and 4 are connected to USB, and pins 5 and 6 are the outputs on the W800 side.

If you need to see all the data, it is best to connect another serial port TTL module to display the data.

It can be seen that WiFi can be used to connect to the Internet normally, send and obtain information, and the code implements the function of updating the time every 10 seconds.

You can type help on both serial ports, but the functions are quite different.

The CDK component cli should be an interactive debugging component with powerful functions. I will study it carefully later.

Latest reply

Code line number: 50 and 51, "w800_module_init" and "w800_packet_input_cb_register" do not need to be called, because these two APIs have been called in "wifi_w800_register".   Details Published on 2022-3-23 09:49
 
 

6818

Posts

11

Resources
2
 

I don't know if Pingtou Ge has a post that introduces the use of each module separately. I want to combine LVGL with networking, but it fails.

Comments

I haven't tested LVGL yet, I'll learn from it later.  Details Published on 2022-3-23 21:18
 
 
 

41

Posts

2

Resources
3
 

Code line number: 50 and 51, "w800_module_init" and "w800_packet_input_cb_register" do not need to be called, because these two APIs have been called in "wifi_w800_register".

Comments

w800_module_init can be repeated, there is a mark for successful registration, if it has been registered, it will return directly. The purpose of w800_packet_input_cb_register is to debug what information is received.  Details Published on 2022-3-23 21:19
 
 
 

295

Posts

0

Resources
4
 
lugl4313820 posted on 2022-3-22 11:18 I don't know if Pingtou Ge has a separate post introducing the use of each module. I want to combine LVGL with networking, but it doesn't work when combined.

I haven't tested LVGL yet, I'll learn from it later.

 
 
 

295

Posts

0

Resources
5
 
Posted by Uncle Xiaomo on 2022-3-23 09:49 Code line number: 50 and 51, "w800_module_init" and "w800_packet_input_cb_register" do not need to be adjusted...

w800_module_init can be repeated, there is a mark for successful registration, if it has been registered, it will return directly. The purpose of w800_packet_input_cb_register is to debug what information is received.

 
 
 

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