ESP8266 Developer Zone The Official ESP8266 Forum 2017-04-06T10:13:22+08:00 https://bbs.espressif.com:443/feed.php?f=16&t=3622 2017-04-06T10:13:22+08:00 2017-04-06T10:13:22+08:00 https://bbs.espressif.com:443/viewtopic.php?t=3622&p=12031#p12031 <![CDATA[Re: AT+CWJAP_DEF disconnects and so Station IP doesn't display]]>
It seems that you have 2 ESP8266 boards.
The first one (ESP8266-A) is working in station mode and trying to connect to an open AP named "esp8266".
The second one (ESP8266-B) works in station+softAP mode, but it seems not to be named as "esp8266"? Maybe you can set it to be softAP-only mode (AT+CWMODE_DEF=2), and name it as "esp8266" (AT+CWSAP_DEF="esp8266","",5,0), so that the ESP8266-A can connect to the ESP8266-B.

Statistics: Posted by ESP_Faye — Thu Apr 06, 2017 10:13 am


]]>
2017-04-03T00:09:10+08:00 2017-04-03T00:09:10+08:00 https://bbs.espressif.com:443/viewtopic.php?t=3622&p=11876#p11876 <![CDATA[AT+CWJAP_DEF disconnects and so Station IP doesn't display]]>
Screen Shot 2017-04-02 at 16.10.36.png


Screen Shot 2017-04-02 at 15.39.46.png



Code:

#include "mbed.h"
#include <stdio.h>
#include <string.h>

Serial serial(USBTX, USBRX);
Serial esp(P4_28, P4_29); // tx, rx
DigitalOut reset(P0_4);
DigitalOut blueLed(P2_3);
DigitalOut greenLed(P2_4);
DigitalOut redLed(P2_5);
DigitalOut vibr(P2_12);

Timer t;

int  count,ended,timeout;


char buf[4096];
char snd[255];
char sendStr[11];

char ssid[32] = "esp8266";     // enter WiFi router ssid inside the quotes
char pwd [32] = ""; // enter WiFi router password inside the quotes

void SendCMD();
void getReply();

DigitalOut myled(LED1);

int main() {
   
      //Make sure all feedback mechanisms are turned off
    blueLed=0;
    greenLed=0;
    redLed=0;
    vibr=0;
   
    //set buad rates for comms
    esp.baud(115200);
    serial.baud(115200);
   
    esp.attach(&getReply, Serial::RxIrq); // This needs to be define only once
   
    reset = 1; // This is pin P0_14 in the Egg.
    wait(2);// Give the user some to setup the virtual terminal
   
    serial.printf("\n---------- Clear Buffer ----------\r\n"); //Simple way to clear the buffer
    strcpy(snd, "AT+GMR\r\n");
    timeout=3;
    SendCMD();
    getReply();
    serial.printf(buf);
   
    serial.printf("\n---------- set default mode ----------\r\n");  //
    strcpy(snd, "AT+CWMODE_DEF=1\r\n");
    timeout=2;
    SendCMD();
    getReply();
    serial.printf(buf);  //Prints out response, should be "OK"
   
    serial.printf("\n---------- check mode ----------\r\n");  //
    strcpy(snd, "AT+CWMODE?\r\n");
    timeout=2;
    SendCMD();
    getReply();
    serial.printf(buf);  //Prints out response, should be "OK"
   
    serial.printf("\n---------- Connecting to AP ----------\r\n");
    serial.printf("ssid = %s pwd = %s\r\n",ssid,pwd);
    strcpy(snd, "AT+CWJAP_DEF=\"");
    strcat(snd, ssid);
    strcat(snd, "\",\"");
    strcat(snd, pwd);
    strcat(snd, "\"\r\n");
    timeout=15;
    SendCMD();
    getReply();
    serial.printf(buf);
   
    //Check to see that the connection has been established
    serial.printf("\n---------- Connection Information ----------\r\n");
    strcpy(snd, "AT+CIFSR\r\n"); //get local IP address
    timeout=5;
    SendCMD();
    getReply();
    serial.printf(buf);
   
   
   
    while(1) {
       
    }
}

//This function sends the command string to the ESP8266
void SendCMD()
{
    esp.printf("%s", snd);
}



//This function establishes the space for the received string, starts a timer so that if things get stuck, the
//app won't hang. 
void getReply()
{

    memset(buf, '\0', sizeof(buf));
    t.start();
    ended=0;
    count=0;
    while(!ended) {
        if(esp.readable()) {
            buf[count] = esp.getc();
            count++;
        }
        if(t.read() > timeout) {
            ended = 1;
            t.stop();
            t.reset();
        }
       
   
    }
   
    serial.printf(buf);
   
}

Code:

#include "mbed.h"
#include <stdio.h>
#include <string.h>

Serial serial(USBTX, USBRX);
Serial esp(P4_28, P4_29); // tx, rx
DigitalOut reset(P0_4);
DigitalOut blueLed(P2_3);
DigitalOut greenLed(P2_4);
DigitalOut redLed(P2_5);
DigitalOut vibr(P2_12);

Timer t;

int  count,ended,timeout;


char buf[4096];
char snd[255];
char sendStr[11];

char ssid[32] = "";     // enter WiFi router ssid inside the quotes
char pwd [32] = ""; // enter WiFi router password inside the quotes

void SendCMD();
void getReply();



int main() {
   
    //Make sure all feedback mechanisms are turned off
    blueLed=0;
    greenLed=0;
    redLed=0;
    vibr=0;

    //set buad rates for comms
    esp.baud(115200);
    serial.baud(115200);


    // Setup a serial interrupt function to capture received data
    esp.attach(&getReply, Serial::RxIrq);

    //Device doesn't appear to need a reset upon waking up so the device is not reset (i.e. reset = 1);
    reset=1;

    // Give the user some to setup the virtual terminal
    wait(5);


    serial.printf("\n---------- Clear Buffer ----------\r\n");  //Simple way to clear the buffer
    strcpy(snd, "AT+GMR\r\n");    //View version info
    timeout=3;
    SendCMD();
    getReply();
    serial.printf(buf);
   
    serial.printf("\n---------- set default mode ----------\r\n");  //
    strcpy(snd, "AT+CWMODE_DEF=3\r\n");
    timeout=2;
    SendCMD();
    getReply();
    serial.printf(buf);  //Prints out response, should be "OK"
   
    serial.printf("\n---------- check mode ----------\r\n");  //
    strcpy(snd, "AT+CWMODE?\r\n");
    timeout=2;
    SendCMD();
    getReply();
    serial.printf(buf);  //Prints out response, should be "OK"
   
    serial.printf("\n---------- Turn off DHCP for Station----------\r\n");  //
    strcpy(snd, "AT+CWDHCP_DEF=1,0\r\n");
    timeout=2;
    SendCMD();
    getReply();
    serial.printf(buf);  //Prints out response, should be "OK"
   
    serial.printf("\n---------- check DHCP settings----------\r\n");  //
    strcpy(snd, "AT+CWDHCP?\r\n");
    timeout=2;
    SendCMD();
    getReply();
    serial.printf(buf);  //Prints out response, should be "OK"
 
    serial.printf("\n---------- Set static Station IP Address  ----------\r\n");  //
    strcpy(snd, "AT+CIPSTA_DEF=\"192.168.0.5\",\"192.168.4.1\",\"255.255.255.0\"\r\n");
    timeout=5;
    SendCMD();
    getReply();
    serial.printf(buf);  //Prints out response, should be "OK"
   
    serial.printf("\n---------- check mode ----------\r\n");  //
    strcpy(snd, "AT+CIPSTA_DEF?\r\n");
    timeout=2;
    SendCMD();
    getReply();
    serial.printf(buf);  //Prints out response, should be "OK"
   
   
    while(1) {
       
    }
}

//This function sends the command string to the ESP8266
void SendCMD()
{
    esp.printf("%s", snd);
}



//This function establishes the space for the received string, starts a timer so that if things get stuck, the
//app won't hang. 
void getReply()
{

    memset(buf, '\0', sizeof(buf));
    t.start();
    ended=0;
    count=0;
    while(!ended) {
        if(esp.readable()) {
            buf[count] = esp.getc();
            count++;
        }
        if(t.read() > timeout) {
            ended = 1;
            t.stop();
            t.reset();
        }
       
   
    }
   
    serial.printf(buf);
   
}

Statistics: Posted by sc00486 — Mon Apr 03, 2017 12:09 am


]]>