Chat here is you are connecting ESP-xx type modules to existing AVR based Arduino

Moderator: igrr

User avatar
By Tristan8686
#67600 Hello, this is my first post and I hope you forgive my English since my native language is Spanish.
I have been trying to communicate an android smart phone (also a laptop with Windows 10) for several days, but I can only link to ESP8266 in STA + AP mode with some problems :? .
I have tried with two different boards, both are clone Wemos D1 R2. For the test I'm going to show, I used the WifiAccessPoint sample program. The Arduino IDE is 1.6.12 and the Core of ESP8266 is 2.3.0. Before performing the test I deleted the entire flash to avoid problems with other configurations. I added the WiFi.printDiag (Serial) line so that the configuration will be visible.
The IDE configuration is:
    Board: Generic ESP8266 module.
    Flash mode: QIO.
    Flash Frecuency: 40 MHz.
    CPU Frecuency: 80 MHz.
    Flash size: 4 M (3 M SPIFFS).
    Debug port: Serial.
    Debug Level: All.
    Reset method: Nodemcu.
The result is:
Configuring access point...[AP] IP config Invalid resetting...
[APConfig] local_ip: 192.168.244.1 gateway: 192.168.244.1 subnet: 255.255.255.0
[APConfig] DHCP IP start: 192.168.244.100
[APConfig] DHCP IP end: 192.168.244.200
[APConfig] IP config Invalid?!
[AP] softAPConfig failed!
Mode: AP
PHY mode: N
Channel: 1
AP id: 0
Status: 255
Auto connect: 1
SSID (0):
Passphrase (0):
BSSID set: 0
AP IP address: 0.0.0.0
HTTP server started
add if1
dhcp server start:(ip:192.168.244.1,mask:255.255.255.0,gw:192.168.244.1)
bcn 100
wifi evt: 7
wifi evt: 7
wifi evt: 7
wifi evt: 7

"Wifi evt: 7" is repeated every 1 s approximately, although sometimes stop and then several lines appear together.
When I try to connect the smart phone presents this result:
wifi evt: 7
wifi evt: 7
add 1
aid 1
station: **:**:**:**:**:** join, AID = 1 (Correct mac address)
wifi evt: 5
wifi evt: 7
wifi evt: 7
wifi evt: 7
wifi evt: 7
wifi evt: 7
wifi evt: 7
wifi evt: 7
wifi evt: 7
wifi evt: 7
wifi evt: 7
wifi evt: 7
wifi evt: 7
wifi evt: 7
wifi evt: 7
station: **:**:**:**:**:** leave, AID = 1
rm 1
wifi evt: 6
wifi evt: 7
wifi evt: 7

When is in STA + AP mode, connection is achieved after several attempts and also access the Web server, although the "Wifi evt: 7" events still occur at lower frequency.
Has this happened to anyone?
Do you know any solution?
Thanks for the attention.
User avatar
By QuickFix
#67615 First: I'm not sure what you're trying to do
Second: where is your code, giving you problems?
User avatar
By Tristan8686
#67619
QuickFix wrote:First: I'm not sure what you're trying to do
Second: where is your code, giving you problems?


First of all thanks for your answer. The code is the "WiFiAccessPoint" example of the ESP8266WIFI library (and I've tried all the examples I've found on the web). Three lines have been added to enable debugging and to set the "WIFI_AP" mode.
But something similar happens in any program I've used after activating the AP mode. However, if the mode is STA + AP a smart phone or the computer can link to the 8266 through its access point (without going through the home Wifi).
The program I'm working on is to connect a smart android phone to the ESP8266 in AP mode (among other things).
Code: Select all/*
 * Copyright (c) 2015, Majenko Technologies
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without modification,
 * are permitted provided that the following conditions are met:
 *
 * * Redistributions of source code must retain the above copyright notice, this
 *   list of conditions and the following disclaimer.
 *
 * * Redistributions in binary form must reproduce the above copyright notice, this
 *   list of conditions and the following disclaimer in the documentation and/or
 *   other materials provided with the distribution.
 *
 * * Neither the name of Majenko Technologies nor the names of its
 *   contributors may be used to endorse or promote products derived from
 *   this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

/* Create a WiFi access point and provide a web server on it. */

#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>

/* Set these to your desired credentials. */
const char *ssid = "ESPap";
const char *password = "thereisnospoon";

ESP8266WebServer server(80);

/* Just a little test message.  Go to http://192.168.4.1 in a web browser
 * connected to this access point to see it.
 */
void handleRoot() {
   server.send(200, "text/html", "<h1>You are connected</h1>");
}

void setup() {
   delay(1000);
   Serial.begin(115200);
   Serial.println();
  Serial.setDebugOutput(true);
   Serial.print("Configuring access point...");
   /* You can remove the password parameter if you want the AP to be open. */
  WiFi.mode(WIFI_AP);
   WiFi.softAP(ssid, password);
  WiFi.printDiag(Serial);

   IPAddress myIP = WiFi.softAPIP();
   Serial.print("AP IP address: ");
   Serial.println(myIP);
   server.on("/", handleRoot);
   server.begin();
   Serial.println("HTTP server started");
}

void loop() {
   server.handleClient();
}
User avatar
By Tristan8686
#67645 Hello philbowles and thanks for the answer. I already sent a message with the complete program, although it is only a small modification of the example of the library, but I still can not see the message, I guess it will soon appear.
philbowles wrote:A few points:
1) You appear to have the board set wrongly. You say "The IDE configuration is: Board: Generic ESP8266 module..." but you also tell us "both are clone Wemos D1 R2"

1- I have tried with many configurations, besides the WeMos D1 R2 that is the one that corresponds. In all configurations the same thing happens, but to see the debug information, I need to configure the board as well. This way I can know the events that are happening. I think the configuration of the board is more to be able to upload the program, but just as it also modifies the program in machine code that performs. However, as I said, in all cases the same, the program does not works.
philbowles wrote:2) "The Arduino IDE is 1.6.12" - this is not the latest

This is correct, but as this version compiles well and I am using it in other programs I did not think about changing it, since I have had bad experiences when updating some version of the IDE. I will try to install it on another computer to see if the problem is fixed.
philbowles wrote:3) The error messages:

As I said in the first message, these errors are due to the fact that the entire flash has been deleted to avoid that previous configurations interfere in the example. With the following line of configuration before activating the AP mode solves it.
Code: Select all  WiFi.softAPConfig(IPAddress(192,168,10,1), IPAddress(192,168,10,1), IPAddress(255,255,255,0));

I have tried it already and the debugging does not show any configuration problem but ... The connection problem persists!
The same board, with the same IDE configuration, in the STA + AP mode (after first connecting STA with the home wifi) connects (not the first time) with the AP of the ESP8266 and can access the (very simple) Web server, that implements the example, from the browser.
If when you see the message with the program, you notice some configuration problem other than the commented (and tested) I would appreciate the indication. If someone has some ESP and can do the example work with another version of the IDE I would appreciate it if you showed it to me.
Thank you very much again.