16-ESP8266 SDK Development Foundation Introduction Chapter--TCP Server Non-RTOS Running Edition, Serial Port Pass-through

Keywords: PHP network SDK Mobile

https://www.cnblogs.com/yangfengwu/p/11105466.html

 

In fact, the official version of RTOS was added to the original non-RTOS version.

https://www.cnblogs.com/yangfengwu/p/5205570.html The basic configuration of TCP and UDP is just like AT, but we developed it with SDK.

Configure WIFI's working mode, wireless name

 

 

 

 

 

 

 

    wifi_set_opmode(STATIONAP_MODE);//To configure WiFi Patterns STATION + AP AP--Connect WIFI Self-realization of wireless communication  STATION--wifi Connection router,Mobile phones or computers are also connected to routers,Implementing communication
    soft_ap_Config.ssid_len = strlen(SSID);//Hotspot name length, just the same as your actual name length

    memcpy(soft_ap_Config.ssid,SSID,soft_ap_Config.ssid_len);//Actual hotspot name settings, according to your needs
    memcpy(soft_ap_Config.password,PWD,strlen(PWD));//Hot Password Settings
    soft_ap_Config.authmode = AUTH_WPA2_PSK;//Encryption mode
    soft_ap_Config.channel = 1;//Channel, total support 1~13 Channels
    soft_ap_Config.max_connection = 4;//Maximum number of connections, maximum support of four, default of four

    wifi_softap_set_config_current(&soft_ap_Config);//Set up Wi-Fi SoftAP Interface configuration, not saved to Flash
    //    wifi_softap_set_config(&soft_ap_Config);//Set up Wi-Fi SoftAP Interface configuration, saved to Flash

 

Download it

       

 

 

Then do the TCP server

In fact, it refers to this document.

 

 

 

 

 

Actually, let's just say... Officials actually give examples.. That's the 1.5 version without SDK.

 

 

 

 

 

If you don't understand why http uses TCP https://www.cnblogs.com/yangfengwu/category/1383497.html Look at the first few sections

 

So I'm not going to make an axe out of my class... Copy it directly and write a comment on it.

 

 

 

 

 

 

 

 

//Received data
void TcpServerRecv(void *arg, char *pusrdata, unsigned short length)
{
    while(length--)
    {
        USART_SendData(UART0, *(pusrdata++));//Received data sent to serial port
    }
}

//To break off
void TcpServerDisCon(void *arg)
{
    struct espconn *pesp_conn = arg;

    os_printf("TCP Client %d.%d.%d.%d:%d disconnect\n", pesp_conn->proto.tcp->remote_ip[0],
                pesp_conn->proto.tcp->remote_ip[1],pesp_conn->proto.tcp->remote_ip[2],
                pesp_conn->proto.tcp->remote_ip[3],pesp_conn->proto.tcp->remote_port);
}

//The program starts listening
void TcpServerListen(void *arg)
{
    struct espconn *pesp_conn = arg;//Receiving incoming espconn information

    espconn_regist_recvcb(pesp_conn, TcpServerRecv);//Setting Receive Callback
    espconn_regist_disconcb(pesp_conn, TcpServerDisCon);//Setting disconnect callback
}

 

 

Finished above is the WIFI monitor 8888 port, the data sent after the client connection is forwarded directly to the serial port.

Module default is 192.168.4.1

test

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Now let's go one step further and make the data received by the WIFI serial port send to the network.

https://blog.csdn.net/u010333084/article/details/51336886

 

In the last section, we used task to process serial data, this time we used callback to achieve, so it can be processed quickly.

 

 

 

 

 

 

 

 

 

 

 

 

test

 

 

Now forward the data received by the serial port to the network

 

Because of the need to send

 

So let's define a global variable.

The idea is that this variable is assigned to listen to connections, disconnect, and receive data from the network.

If we only put it in the data received by the network to assign value. Then if the client connects, it does not send data to us first, we can not send it to him, because the variables are not assigned.

But now there's a problem like this: the TCP client that finally connects or sends me the data, and I'll send it next time.

You can make an array again, save all of this, and expand it by yourselves, Ha-ha-ha-ha-ha-ha-ha-ha-ha-ha-ha-ha-ha-ha-ha-ha-ha-ha-ha-ha-ha-ha-ha-ha-ha-ha

Hint Ha, you can do four arrays, and loop to determine which one is sent in connection state.

 

 

 

test

 

 

 

 

 

 

 

 

It would be perfect to change the sending from here to copy the array directly to the sending buffer of the serial port (only calling a sentence).

 

Use your brain to find a way out

 

 

 

https://www.cnblogs.com/yangfengwu/p/11112015.html

Posted by bernard_hinault on Sun, 30 Jun 2019 14:59:09 -0700