ESP8266-SDK Development into the Pit (iv)-Station mode

Source: Internet
Author: User
Tags bssid

Remember a painful lesson, remember to save the file instantly. (This time not lost, but not build). Remember, remember that eclipse must be ctrl+s and clean before build. 1, the purpose of the experiment

Learn about the STA mode operation method developed by SDK and familiarize yourself with relevant API functions. 2. Function Interpretation

1, Wifi_get_opmode

Can be said to be very clear, then we will take a look at our module mode now.

/
 * * USER_MAIN.C
 * *  Created on:2018 January 3
 * author:clay */

#include "user_main.h " 
#include" driver/uart.h "  //serial port 0 required header file

void User_init ()
{
    uint8 wifimode;
    Uart_init (115200,115200);
    Wifimode = Wifi_get_opmode ();

    os_printf ("\ r \ n Current mode is:%d\r\n", Wifimode);
}
void User_rf_pre_init () {}

About "User_main.h", this is my custom file in App/include, so that later need to which header file directly to throw, and then only need to refer to "User_main.h" on the line ...

Compile, there is an error. The header file about os_printf is in the os_api.h.

Uart0 and Uart1 Study

At the end of the chapter, I mentioned something about it.

8266 There are two serial ports, UART0 and Uart1,uart1 in GPIO2 equivalent to TXD1. The main and os_printf from where output is concerned, but regardless of which, download the program or use UART0.

APP/DRIVER/UART.C 332 I added a comment and downloaded the completed program, the serial port appears as:

After switching to TX1,

Haha, get to a new skill bar.

Related manuals See, share: https://pan.baidu.com/s/1hs7xZTi Password: yc6y

There's this, too.

[Question]: RTS and CTS have seen the relevant points of knowledge before, add it later.

There is a feeling will be used, first recorded first.

2, Wifi_set_mode & Wifi_set_mode_current

1->station mode
2->ap mode
3->sta+ap mode

And then compare the two

Test code

/
 * * USER_MAIN.C
 * *  Created on:2018 January 3
 * author:clay */

#include "user_main.h"
#include "driver/uart.h"  //serial port 0 required header file

void User_init ()
{
    uint8 opmode;
    Uart_init (115200,115200);
    Opmode = Wifi_get_opmode ();
    os_printf ("\ r \ n Current mode is:%d\r\n", opmode);
    Wifi_set_opmode_current (0x01);
    Opmode = Wifi_get_opmode ();
    os_printf ("\ r \ n Current mode:%d\r\n", opmode);
}
void User_rf_pre_init () {}

You can also know that current is not saved to Flah.

Take another look at the other

The verification is as I expected.

3, Wifi_station_scan

Get the APS in the current environment

pay special attention to the

cannot be called in User_int, it must be in the case of system initialization and station enable (i.e. in Ap+sta or STA mode)

So, here's the problem. When does initialization finish. How to know if initialization is complete.

This introduces the callback function --

SYSTEM_INIT_DONE_CB

Look at this function.

4, Wifi_station_get_connect_status

3. Code Display

The entire code bar, while understanding the annotation side to learn the above mentioned function usage!

/* * USER_MAIN.C * * Created on:2018 January 3 * author:clay */#include "user_main.h" #include "driver/uart.h"
    Serial 0 Required header file void icache_flash_attr wifi_conned (void *arg) {static uint8 count=0;

    Uint8 status;
    Os_timer_disarm (&connect_timer);//The timer is closed first, once connected or more than seven times not connected, it will not repeat printing.

    count++;
    Status = Wifi_station_get_connect_status ();
        if (status = = Station_got_ip) {os_printf ("WIFI Connect success\r\n");
    Return
            } else {if (Count >= 7) {os_printf ("WIFI Connect fail\r\n");
        Return;//if forgot to include the return, and then causes the above two to not print: }} os_timer_arm (&connect_timer,2000,null);//Reopen timer} void Icache_flash_attr scan_done (void *arg, STATUS s tatus)//scan completed callback function Scan_done (this is interesting, ARG exists in the form of a list.)
    ) {uint8 ssid[33];

    struct Station_config stationconf; if (status = = OK) {struct Bss_info *bss_link = (struct bss_info *) arg;//list pointer bss_link = Bss_link-&gt ; next.stQe_next;//ignore first while (bss_link! = NULL) {os_memset (SSID, 0, +);//memset Initialize array if (Os_strlen (BSS_LINK-&GT;SSID) <=) {os_memcpy (SSID, Bss_link->ssid, OS_STR
            Len (BSS_LINK-&GT;SSID));
            } else {os_memcpy (SSID, Bss_link->ssid, 32); } os_printf ("+cwlap: (%d,\"%s\ ",%d,\" "Macstr" \ ",%d) \ r \ n", Bss_link->authmode, SSID, Bss_link-&gt

            ; Rssi, Mac2str (BSS_LINK-&GT;BSSID), Bss_link->channel);
        Bss_link = bss_link->next.stqe_next; } os_memcpy (&stationconf.ssid, "6103", 32);
        0s_memcpy memory copy function 32 means copy the first 32 characters os_memcpy (&stationconf.password, "12346103", 64);
        Wifi_station_set_config_current (&stationconf); Wifi_station_connect (); This function, when the previous function is not called in User_int, needs to be added to the OS_TIMER_SETFN (&connect_timer,wifi_conned,null) elsewhere; Timer callback function (when the timerWhat to do when the time is up. Callback) Os_timer_arm (&connect_timer,2000,null);
    Every 2s to detect if the connection is true.
    } else {//os_sprintf (temp, "Err, scan status%d\r\n", status);

    UART0_SENDSTR (temp);

}} void To_scan (void) {Wifi_station_scan (null,scan_done);}
    void User_init () {uint8 opmode;
    Uart_init (115200,115200);
    Wifi_set_opmode (0x03);
    Opmode = Wifi_get_opmode ();
    os_printf ("\ r \ n Current mode is:%d\r\n", opmode);
    Wifi_set_opmode_current (0x01);
    Opmode = Wifi_get_opmode ();

    os_printf ("\ r \ n Current mode:%d\r\n", opmode);
    Wifi_set_opmode (Station_mode);


 SYSTEM_INIT_DONE_CB (To_scan);//callback function after initialization is complete} void User_rf_pre_init () {}

And my user_main.h.

/
 * * User_main.h
 * *  Created on:2018 January 3
 * author:clay */

#ifndef app_include_ User_main_h_
#define App_include_user_main_h_

#include "osapi.h"    //os_printf the required header files
#include " User_interface.h "
Etstimer Connect_timer;


#endif/* App_include_user_main_h_ */

As for the above procedure, most of them refer to someone else's at program. But not ashamed, just started to learn, can become their own things good. The porters are only temporary.

Find the relevant program path:

At_init (), System_os_task (At_proctask ...)
Zt_cmdprocess->at_fun (this array, at specify all here, find what we want to refer to, Cwlap)->at_execmccwlap-so you can refer to someone else's code ... ->wifi_station_scan, Scan_done,

Especially use to the list that point, and review a wave of linked list of knowledge, hehe ...
(At that time the freshman C's linked list record, haha ha)

No, January 3, 2018 18:36:24. Lunch was not eaten. Starved of hunger. Go and have a meal first, come back and write. Hehe hey ... Experimental Summary

1, about the WiFi several commonly used array name

1. Auth_mode encryption Mode (enum type)

2. Ssid-wifi Name

3. RSSI-Signal Strength Unit db

4. Bssid MAC Address

5. Channel Channels

2, the magical icache_flash_attr of the macro

In fact, we can see this macro in a lot of function head, for example,

So, what does this macro mean?

After adding this macro, it is stored in the Irom, (in fact, it is ROM). The CPU only reads them into the cache when they are called. There is no function to add this macro, and a power-up is loaded into the Iram (actually RAM).

Due to space constraints, it is not possible to put all the functions into the iram, so most of the functions of money to add "icache_flash_attr" this macro, or RAM explosion, it will be wrong.

Need to be aware of

Do not call a function with such a macro in a gpio or UART interrupt, or it will cause an exception.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.