Mediatek Labs LinkIt Connect 7681 Developer's Manual page 53

Table of Contents

Advertisement

2) Exchange data with TCP Client
The logic and source code in iot_tcp_appcall is the same as used in section5.3.1. It prints
out whenever data are received and sends back "hello" once every 5 seconds:
File: iot_tcp_app.c
void
app_handle_connection(void)
{
static struct
static
if(uip_newdata())
uip_appdata
{
printf_high("TCP Server RX [%d]
iot_uart_output(uip_appdata, uip_datalen());
}
if
(uip_poll())
{
if((app_init == FALSE) || timer_expired(&user_timer))
{
}
}
}
iot_tcp_appcall(void)
{
u16_t lport
if
(lport
{
app_handle_connection();
}
...
}
To test the code, first make sure that MT7681 has network access. Second, have the remote client
connect to the IP of MT7681 (the IP address is output to UART during the acquisition process). You
can use nc (netcat), which is built-in to Linux and
> nc [IP of MT7681] 9999
The shell window at the remote client will start displaying "hello" periodically. You can also type
characters back, these should be output on UART of MT7681.
Placing the client and server (MT7681) under the same network will avoid potential issues with
local IP and port forwarding.
This document contains information that is proprietary to MediaTek Inc.
Unauthorized reproduction or disclosure of this information in whole or in part is strictly prohibited.
MediaTek LinkIt™ Connect 7681 Developer's Guide
timer
user_timer;
bool app_init
= FALSE;
// there are data to be received and stored in
printf_high("TCP Server timer is expired,
uip_send("hello\n", 6);
timer_set(&user_timer, 5*CLOCK_SECOND);
app_init = TRUE;
= HTONS(uip_conn->lport);
== 9999)
// if local port is 9999, it is our event
// Ex. nc 192.168.1.1 9999
© 2015, 2016 MediaTek Inc.
//create a timer;
bytes\n", uip_datalen());
available for
Windows, to do this:
TX\n");
Page 48 of 65

Advertisement

Table of Contents
loading

Related Products for Mediatek Labs LinkIt Connect 7681

Table of Contents