Difference between revisions of "Grove - UART WiFi V2"

From
Jump to: navigation, search
(UART Wifi V2)
Line 10: Line 10:
  
 
[[File:Grove - UART Wifi V2.jpg | 400px]]
 
[[File:Grove - UART Wifi V2.jpg | 400px]]
 +
 +
=== Code ===
 +
 +
<pre>
 +
// test grove - uart wifi
 +
// scan ap and display on Grove - OLED 0.96'
 +
// Loovee @ 2015-7-28
 +
 +
#include <Wire.h>
 +
#include <SeeedOLED.h>
 +
 +
char ap_buf[30][16];
 +
int ap_cnt = 0;
 +
 +
void setup()
 +
{
 +
    Serial.begin(115200);
 +
 +
    delay(3000);
 +
    Wire.begin();
 +
    SeeedOled.init();                  // initialze SEEED OLED display
 +
 +
    SeeedOled.clearDisplay();          // clear the screen and set start position to top left corner
 +
    SeeedOled.setNormalDisplay();      // Set display to normal mode (i.e non-inverse mode)
 +
    SeeedOled.setPageMode();            // Set addressing mode to Page Mode
 +
 +
}
 +
 +
 +
void loop()
 +
{
 +
    ap_cnt = 0;
 +
    SeeedOled.clearDisplay();
 +
    SeeedOled.setTextXY(3,0);   
 +
    SeeedOled.putString("Wifi Scan...");
 +
 +
    cmd_send("AT+CWLAP");
 +
    wait_result();
 +
   
 +
    display_ap();
 +
    delay(5000);
 +
}
 +
 +
// send command
 +
void cmd_send(char *cmd)
 +
{
 +
    if(NULL == cmd)return;
 +
    Serial.println(cmd);
 +
}
 +
 +
 +
// wait result of ap scan
 +
// +CWLAP:(3,"360WiFi-UZ",-81,"08:57:00:01:61:ec",1)
 +
void wait_result()
 +
{
 +
    while(1)
 +
    {
 +
LOOP1:
 +
        char c1=0;
 +
        if(Serial.available()>=2)
 +
        {
 +
            c1 = Serial.read();
 +
            if(c1 == 'O' && 'K' == Serial.read())return;      // OK means over
 +
        }
 +
       
 +
        if('('==c1)
 +
        {
 +
            while(Serial.available()<3);
 +
            Serial.read();
 +
            Serial.read();
 +
            Serial.read();
 +
 +
            int d = 0;
 +
            while(1)
 +
            {
 +
                if(Serial.available() && '"' == Serial.read());      // find "
 +
                {
 +
                    while(1)
 +
                    {
 +
                        if(Serial.available())
 +
                        {
 +
                            char c = Serial.read();
 +
                            ap_buf[ap_cnt][d++] = c;
 +
                            if(c == '"' || d==16)
 +
                            {
 +
                                ap_buf[ap_cnt][d-1] = '\0';
 +
                                ap_cnt++;
 +
                                goto LOOP1;
 +
                            }
 +
                        }
 +
                    }
 +
                }
 +
            }
 +
        }
 +
    }
 +
}
 +
 +
// display
 +
void display_ap()
 +
{
 +
    char strtmp[16];
 +
    sprintf(strtmp, "get %d ap", ap_cnt);
 +
   
 +
    SeeedOled.clearDisplay();          // clear
 +
    SeeedOled.setTextXY(3,3);          // Set the cursor to Xth Page, Yth Column
 +
    SeeedOled.putString(strtmp);        // Print the String
 +
 +
    delay(2000);
 +
   
 +
    int cnt = ap_cnt;
 +
    int offset = 0;
 +
    while(1)
 +
    {
 +
        SeeedOled.clearDisplay();
 +
        if(cnt>=8)
 +
        {
 +
            for(int i=0; i<8; i++)
 +
            {
 +
                SeeedOled.setTextXY(i,0);          // Set the cursor to Xth Page, Yth Column
 +
                SeeedOled.putString(ap_buf[8*offset+i]);        // Print the String
 +
            }
 +
            cnt-=8;
 +
            offset++;
 +
        }
 +
        else
 +
        {
 +
            for(int i=0; i<cnt; i++)
 +
            {
 +
                SeeedOled.setTextXY(i,0);          // Set the cursor to Xth Page, Yth Column
 +
                SeeedOled.putString(ap_buf[8*offset+i]);        // Print the String
 +
            }
 +
           
 +
            return;
 +
        }
 +
       
 +
        delay(2000);
 +
    }
 +
}
 +
</pre>
  
 
=== Liens ===
 
=== Liens ===

Revision as of 22:43, 9 October 2024

UART Wifi V2

WiFi Chip = ESP8285
Antenna Type = On-board

images

Grove - UART Wifi V2 front.jpg Grove - UART Wifi V2 back.jpg

Grove - UART Wifi V2.jpg

Code

// test grove - uart wifi
// scan ap and display on Grove - OLED 0.96'
// Loovee @ 2015-7-28

#include <Wire.h>
#include <SeeedOLED.h>

char ap_buf[30][16];
int ap_cnt = 0;

void setup()
{
    Serial.begin(115200);

    delay(3000);
    Wire.begin();
    SeeedOled.init();                   // initialze SEEED OLED display

    SeeedOled.clearDisplay();           // clear the screen and set start position to top left corner
    SeeedOled.setNormalDisplay();       // Set display to normal mode (i.e non-inverse mode)
    SeeedOled.setPageMode();            // Set addressing mode to Page Mode

}


void loop()
{
    ap_cnt = 0;
    SeeedOled.clearDisplay();
    SeeedOled.setTextXY(3,0);    
    SeeedOled.putString("Wifi Scan..."); 

    cmd_send("AT+CWLAP");
    wait_result();
    
    display_ap();
    delay(5000);
}

// send command
void cmd_send(char *cmd)
{
    if(NULL == cmd)return;
    Serial.println(cmd);
}


// wait result of ap scan
// +CWLAP:(3,"360WiFi-UZ",-81,"08:57:00:01:61:ec",1)
void wait_result()
{
    while(1)
    {
LOOP1:
        char c1=0;
        if(Serial.available()>=2)
        {
            c1 = Serial.read();
            if(c1 == 'O' && 'K' == Serial.read())return;       // OK means over
        }
        
        if('('==c1)
        {
            while(Serial.available()<3);
            Serial.read();
            Serial.read();
            Serial.read();

            int d = 0;
            while(1)
            {
                if(Serial.available() && '"' == Serial.read());      // find "
                {
                    while(1)
                    {
                        if(Serial.available())
                        {
                            char c = Serial.read();
                            ap_buf[ap_cnt][d++] = c;
                            if(c == '"' || d==16)
                            {
                                ap_buf[ap_cnt][d-1] = '\0';
                                ap_cnt++;
                                goto LOOP1;
                            }
                        }
                    }
                }
            }
        }
    }
}

// display
void display_ap()
{
    char strtmp[16];
    sprintf(strtmp, "get %d ap", ap_cnt);
    
    SeeedOled.clearDisplay();           // clear
    SeeedOled.setTextXY(3,3);           // Set the cursor to Xth Page, Yth Column
    SeeedOled.putString(strtmp);        // Print the String
 
    delay(2000);
    
    int cnt = ap_cnt;
    int offset = 0;
    while(1)
    {
        SeeedOled.clearDisplay(); 
        if(cnt>=8)
        {
            for(int i=0; i<8; i++)
            {
                SeeedOled.setTextXY(i,0);           // Set the cursor to Xth Page, Yth Column
                SeeedOled.putString(ap_buf[8*offset+i]);        // Print the String
            }
            cnt-=8;
            offset++;
        }
        else 
        {
            for(int i=0; i<cnt; i++)
            {
                SeeedOled.setTextXY(i,0);           // Set the cursor to Xth Page, Yth Column
                SeeedOled.putString(ap_buf[8*offset+i]);        // Print the String
            }
            
            return;
        }
        
        delay(2000);
    }
}

Liens

www.seeedstudio.com/Grove-UART-WiFi-V2-ESP8285.html shop bazar

github.com/Seeed-Studio/OLED_Display_128X64 github

wiki.seeedstudio.com/Grove-UART_Wifi_V2 wiki

Libraries