Build problems - MBED + NUCLEO_F429ZI + ESP8266


#1

Hello,
I use platformio with VSCode, and for beginning I try build simple application for NUCLEO with ESP8266. This is mbed-os-example-esp8266 from mbed Online Compiler where this app build without errors, and works well after flashing to board.
But when I try build this app in VSCode and PlatformIO I have only a lot of errors. Maybe this is a problem with framework configuration, maybe I don’t have configured needed features or options, but I can’t find good manual about this.

Where to look for solutions to this problems.

Best regards
Marek

Processing nucleo_f429zi (platform: ststm32; board: nucleo_f429zi; framework: mbed)
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/ststm32/nucleo_f429zi.html
PLATFORM: ST STM32 > ST Nucleo F429ZI
SYSTEM: STM32F429ZIT6 180MHz 256KB RAM (2MB Flash)
DEBUG: CURRENT(stlink) ON-BOARD(stlink) EXTERNAL(blackmagic, jlink)
Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF MODES: FINDER(chain) COMPATIBILITY(soft)
Collected 42 compatible libraries
Scanning dependencies...
Dependency Graph

Compiling .pioenvs\nucleo_f429zi\lib040\esp8266-driver\ESP8266Interface.o
Compiling .pioenvs\nucleo_f429zi\lib040\esp8266-driver\ESP8266\ESP8266.o
Compiling .pioenvs\nucleo_f429zi\src\main.o
In file included from C:\Users\mares\.platformio\packages\framework-mbed\components\wifi\esp8266-driver\ESP8266Interface.cpp:18:0:
C:/Users/mares/.platformio/packages/framework-mbed/components/wifi/esp8266-driver/ESP8266/ESP8266.h:136:14: error: 'WiFiAccessPoint' has not been declared
int scan(WiFiAccessPoint *res, unsigned limit);
^~~~~~~~~~~~~~~
In file included from C:\Users\mares\.platformio\packages\framework-mbed\components\wifi\esp8266-driver\ESP8266Interface.cpp:19:0:
C:\Users\mares\.platformio\packages\framework-mbed\components\wifi\esp8266-driver\ESP8266Interface.h:28:45: error: expected class-name before ',' token
class ESP8266Interface : public NetworkStack, public WiFiInterface
^
C:\Users\mares\.platformio\packages\framework-mbed\components\wifi\esp8266-driver\ESP8266Interface.h:29:1: error: expected class-name before '{' token
{
^
In file included from C:\Users\mares\.platformio\packages\framework-mbed\components\wifi\esp8266-driver\ESP8266Interface.cpp:19:0:
C:\Users\mares\.platformio\packages\framework-mbed\components\wifi\esp8266-driver\ESP8266Interface.h:130:22: error: 'WiFiAccessPoint' has not been declared
virtual int scan(WiFiAccessPoint *res, unsigned count);
^~~~~~~~~~~~~~~
C:\Users\mares\.platformio\packages\framework-mbed\components\wifi\esp8266-driver\ESP8266Interface.h:146:11: error: 'NetworkInterface' has not been declared
using NetworkInterface::gethostbyname;
^~~~~~~~~~~~~~~~
C:\Users\mares\.platformio\packages\framework-mbed\components\wifi\esp8266-driver\ESP8266Interface.h:153:11: error: 'NetworkInterface' has not been declared
using NetworkInterface::add_dns_server;
^~~~~~~~~~~~~~~~
C:\Users\mares\.platformio\packages\framework-mbed\components\wifi\esp8266-driver\ESP8266Interface.h:230:49: error: 'SocketAddress' does not name a type; did you mean 'USB_SetDevAddress'?
virtual int socket_bind(void *handle, const SocketAddress &address);
^~~~~~~~~~~~~
USB_SetDevAddress
C:\Users\mares\.platformio\packages\framework-mbed\components\wifi\esp8266-driver\ESP8266Interface.h:245:52: error: 'SocketAddress' does not name a type; did you mean 'USB_SetDevAddress'?
virtual int socket_connect(void *handle, const SocketAddress &address);
^~~~~~~~~~~~~
USB_SetDevAddress
C:\Users\mares\.platformio\packages\framework-mbed\components\wifi\esp8266-driver\ESP8266Interface.h:254:60: error: 'SocketAddress' has not been declared
virtual int socket_accept(void *handle, void **socket, SocketAddress *address);
^~~~~~~~~~~~~
C:\Users\mares\.platformio\packages\framework-mbed\components\wifi\esp8266-driver\ESP8266Interface.h:285:51: error: 'SocketAddress' does not name a type; did you mean 'USB_SetDevAddress'?
virtual int socket_sendto(void *handle, const SocketAddress &address, const void *data, unsigned size);
^~~~~~~~~~~~~
USB_SetDevAddress
C:\Users\mares\.platformio\packages\framework-mbed\components\wifi\esp8266-driver\ESP8266Interface.h:298:47: error: 'SocketAddress' has not been declared
virtual int socket_recvfrom(void *handle, SocketAddress *address, void *buffer, unsigned size);
^~~~~~~~~~~~~
C:\Users\mares\.platformio\packages\framework-mbed\components\wifi\esp8266-driver\ESP8266Interface.h:312:13: error: 'NetworkStack' does not name a type
virtual NetworkStack *get_stack()
^~~~~~~~~~~~
C:\Users\mares\.platformio\packages\framework-mbed\components\wifi\esp8266-driver\ESP8266Interface.cpp:223:28: error: 'int ESP8266Interface::scan' is not a static data member of 'class ESP8266Interface'
int ESP8266Interface::scan(WiFiAccessPoint *res, unsigned count)
^~~~~~~~~~~~~~~
C:\Users\mares\.platformio\packages\framework-mbed\components\wifi\esp8266-driver\ESP8266Interface.cpp:223:28: error: 'WiFiAccessPoint' was not declared in this scope
In file included from C:\Users\mares\.platformio\packages\framework-mbed\components\wifi\esp8266-driver\ESP8266\ESP8266.cpp:17:0:
C:\Users\mares\.platformio\packages\framework-mbed\components\wifi\esp8266-driver\ESP8266\ESP8266.h:136:14: error: 'WiFiAccessPoint' has not been declared
int scan(WiFiAccessPoint *res, unsigned limit);
^~~~~~~~~~~~~~~
C:\Users\mares\.platformio\packages\framework-mbed\components\wifi\esp8266-driver\ESP8266\ESP8266.cpp:257:19: error: 'int ESP8266::scan' is not a static data member of 'class ESP8266'
int ESP8266::scan(WiFiAccessPoint *res, unsigned limit)
^~~~~~~~~~~~~~~
C:\Users\mares\.platformio\packages\framework-mbed\components\wifi\esp8266-driver\ESP8266\ESP8266.cpp:257:19: error: 'WiFiAccessPoint' was not declared in this scope
C:\Users\mares\.platformio\packages\framework-mbed\components\wifi\esp8266-driver\ESP8266\ESP8266.cpp:257:36: error: 'res' was not declared in this scope
int ESP8266::scan(WiFiAccessPoint *res, unsigned limit)
^~~
C:\Users\mares\.platformio\packages\framework-mbed\components\wifi\esp8266-driver\ESP8266\ESP8266.cpp:257:36: note: suggested alternative: 'reset'
int ESP8266::scan(WiFiAccessPoint *res, unsigned limit)
^~~
reset
C:\Users\mares\.platformio\packages\framework-mbed\components\wifi\esp8266-driver\ESP8266\ESP8266.cpp:257:41: error: expected primary-expression before 'unsigned'
int ESP8266::scan(WiFiAccessPoint *res, unsigned limit)
^~~~~~~~
C:\Users\mares\.platformio\packages\framework-mbed\components\wifi\esp8266-driver\ESP8266\ESP8266.cpp:257:55: error: expression list treated as compound expression in initializer [-fpermissive]
int ESP8266::scan(WiFiAccessPoint *res, unsigned limit)
^
C:\Users\mares\.platformio\packages\framework-mbed\components\wifi\esp8266-driver\ESP8266Interface.cpp:223:45: error: 'res' was not declared in this scope
int ESP8266Interface::scan(WiFiAccessPoint *res, unsigned count)
^~~
C:\Users\mares\.platformio\packages\framework-mbed\components\wifi\esp8266-driver\ESP8266Interface.cpp:223:45: note: suggested alternative: '_esp'
int ESP8266Interface::scan(WiFiAccessPoint *res, unsigned count)
^~~
_esp
C:\Users\mares\.platformio\packages\framework-mbed\components\wifi\esp8266-driver\ESP8266Interface.cpp:223:50: error: expected primary-expression before 'unsigned'
int ESP8266Interface::scan(WiFiAccessPoint *res, unsigned count)
^~~~~~~~
C:\Users\mares\.platformio\packages\framework-mbed\components\wifi\esp8266-driver\ESP8266Interface.cpp:223:64: error: expression list treated as compound expression in initializer [-fpermissive]
int ESP8266Interface::scan(WiFiAccessPoint *res, unsigned count)
^
*** [.pioenvs\nucleo_f429zi\lib040\esp8266-driver\ESP8266\ESP8266.o] Error 1
C:\Users\mares\.platformio\packages\framework-mbed\components\wifi\esp8266-driver\ESP8266Interface.cpp:298:5: error: 'SocketAddress' does not name a type; did you mean 'USB_SetDevAddress'?
SocketAddress addr;
^~~~~~~~~~~~~
USB_SetDevAddress
C:\Users\mares\.platformio\packages\framework-mbed\components\wifi\esp8266-driver\ESP8266Interface.cpp:352:55: error: 'SocketAddress' does not name a type; did you mean 'USB_SetDevAddress'?
int ESP8266Interface::socket_bind(void *handle, const SocketAddress &address)
^~~~~~~~~~~~~
USB_SetDevAddress
C:\Users\mares\.platformio\packages\framework-mbed\components\wifi\esp8266-driver\ESP8266Interface.cpp: In member function 'virtual int ESP8266Interface::socket_bind(void*, const int&)':
C:\Users\mares\.platformio\packages\framework-mbed\components\wifi\esp8266-driver\ESP8266Interface.cpp:361:20: error: request for member 'get_addr' in 'address', which is of non-class type 'const int'
if(address.get_addr().version != NSAPI_UNSPEC) {
^~~~~~~~
C:\Users\mares\.platformio\packages\framework-mbed\components\wifi\esp8266-driver\ESP8266Interface.cpp:366:44: error: request for member 'get_port' in 'address', which is of non-class type 'const int'
if(_local_ports[id] == address.get_port() && id != socket->id) { // Port already reserved by another socket
^~~~~~~~
C:\Users\mares\.platformio\packages\framework-mbed\components\wifi\esp8266-driver\ESP8266Interface.cpp:372:44: error: request for member 'get_port' in 'address', which is of non-class type 'const int'
_local_ports[socket->id] = address.get_port();
^~~~~~~~
C:\Users\mares\.platformio\packages\framework-mbed\components\wifi\esp8266-driver\ESP8266Interface.cpp: At global scope:
C:\Users\mares\.platformio\packages\framework-mbed\components\wifi\esp8266-driver\ESP8266Interface.cpp:384:58: error: 'SocketAddress' does not name a type; did you mean 'USB_SetDevAddress'?
int ESP8266Interface::socket_connect(void *handle, const SocketAddress &addr)
^~~~~~~~~~~~~
USB_SetDevAddress
C:\Users\mares\.platformio\packages\framework-mbed\components\wifi\esp8266-driver\ESP8266Interface.cpp: In member function 'virtual int ESP8266Interface::socket_connect(void*, const int&)':
C:\Users\mares\.platformio\packages\framework-mbed\components\wifi\esp8266-driver\ESP8266Interface.cpp:394:46: error: request for member 'get_ip_address' in 'addr', which is of non-class type 'const int'
ret = _esp.open_udp(socket->id, addr.get_ip_address(), addr.get_port(), _local_ports[socket->id]);
^~~~~~~~~~~~~~
C:\Users\mares\.platformio\packages\framework-mbed\components\wifi\esp8266-driver\ESP8266Interface.cpp:394:69: error: request for member 'get_port' in 'addr', which is of non-class type 'const int'
ret = _esp.open_udp(socket->id, addr.get_ip_address(), addr.get_port(), _local_ports[socket->id]);
^~~~~~~~
C:\Users\mares\.platformio\packages\framework-mbed\components\wifi\esp8266-driver\ESP8266Interface.cpp:399:45: error: request for member 'get_ip_address' in 'addr', which is of non-class type 'const int'
if (!_esp.open_tcp(socket->id, addr.get_ip_address(), addr.get_port(), socket->keepalive)) {
^~~~~~~~~~~~~~
C:\Users\mares\.platformio\packages\framework-mbed\components\wifi\esp8266-driver\ESP8266Interface.cpp:399:68: error: request for member 'get_port' in 'addr', which is of non-class type 'const int'
if (!_esp.open_tcp(socket->id, addr.get_ip_address(), addr.get_port(), socket->keepalive)) {
^~~~~~~~
C:\Users\mares\.platformio\packages\framework-mbed\components\wifi\esp8266-driver\ESP8266Interface.cpp: At global scope:
C:\Users\mares\.platformio\packages\framework-mbed\components\wifi\esp8266-driver\ESP8266Interface.cpp:408:66: error: 'SocketAddress' has not been declared
int ESP8266Interface::socket_accept(void *server, void **socket, SocketAddress *addr)
^~~~~~~~~~~~~
C:\Users\mares\.platformio\packages\framework-mbed\components\wifi\esp8266-driver\ESP8266Interface.cpp:448:57: error: 'SocketAddress' does not name a type; did you mean 'USB_SetDevAddress'?
int ESP8266Interface::socket_sendto(void *handle, const SocketAddress &addr, const void *data, unsigned size)
^~~~~~~~~~~~~
USB_SetDevAddress
C:\Users\mares\.platformio\packages\framework-mbed\components\wifi\esp8266-driver\ESP8266Interface.cpp: In member function 'virtual int ESP8266Interface::socket_sendto(void*, const int&, const void*, unsigned int)':
C:\Users\mares\.platformio\packages\framework-mbed\components\wifi\esp8266-driver\ESP8266Interface.cpp:456:21: error: request for member 'get_ip_address' in 'addr', which is of non-class type 'const int'
if((strcmp(addr.get_ip_address(), "0.0.0.0") == 0) || !addr.get_port())  {
^~~~~~~~~~~~~~
C:\Users\mares\.platformio\packages\framework-mbed\components\wifi\esp8266-driver\ESP8266Interface.cpp:456:65: error: request for member 'get_port' in 'addr', which is of non-class type 'const int'
if((strcmp(addr.get_ip_address(), "0.0.0.0") == 0) || !addr.get_port())  {
^~~~~~~~
C:\Users\mares\.platformio\packages\framework-mbed\components\wifi\esp8266-driver\ESP8266Interface.cpp:460:38: error: 'struct esp8266_socket' has no member named 'addr'
if (socket->connected && socket->addr != addr) {
^~~~
C:\Users\mares\.platformio\packages\framework-mbed\components\wifi\esp8266-driver\ESP8266Interface.cpp:472:17: error: 'struct esp8266_socket' has no member named 'addr'
socket->addr = addr;
^~~~
C:\Users\mares\.platformio\packages\framework-mbed\components\wifi\esp8266-driver\ESP8266Interface.cpp: At global scope:
C:\Users\mares\.platformio\packages\framework-mbed\components\wifi\esp8266-driver\ESP8266Interface.cpp:478:53: error: 'SocketAddress' has not been declared
int ESP8266Interface::socket_recvfrom(void *handle, SocketAddress *addr, void *data, unsigned size)
^~~~~~~~~~~~~
C:\Users\mares\.platformio\packages\framework-mbed\components\wifi\esp8266-driver\ESP8266Interface.cpp: In member function 'virtual int ESP8266Interface::socket_recvfrom(void*, int*, void*, unsigned int)':
C:\Users\mares\.platformio\packages\framework-mbed\components\wifi\esp8266-driver\ESP8266Interface.cpp:488:25: error: 'struct esp8266_socket' has no member named 'addr'
*addr = socket->addr;
^~~~
*** [.pioenvs\nucleo_f429zi\lib040\esp8266-driver\ESP8266Interface.o] Error 1
In file included from C:/Users/mares/.platformio/packages/framework-mbed/components/wifi/esp8266-driver/ESP8266Interface.h:21:0,
from src\main.cpp:22:
C:/Users/mares/.platformio/packages/framework-mbed/components/wifi/esp8266-driver/ESP8266/ESP8266.h:136:14: error: 'WiFiAccessPoint' has not been declared
int scan(WiFiAccessPoint *res, unsigned limit);
^~~~~~~~~~~~~~~
In file included from src\main.cpp:22:0:
C:/Users/mares/.platformio/packages/framework-mbed/components/wifi/esp8266-driver/ESP8266Interface.h:28:54: error: invalid use of incomplete type 'class WiFiInterface'
class ESP8266Interface : public NetworkStack, public WiFiInterface
^~~~~~~~~~~~~
In file included from C:/Users/mares/.platformio/packages/framework-mbed/features/netsocket/NetworkStack.h:23:0,
from C:/Users/mares/.platformio/packages/framework-mbed/features/netsocket/InternetSocket.h:24,
from C:/Users/mares/.platformio/packages/framework-mbed/features/netsocket/TCPSocket.h:23,
from src\main.cpp:18:
C:/Users/mares/.platformio/packages/framework-mbed/features/netsocket/NetworkInterface.h:29:7: note: forward declaration of 'class WiFiInterface'
class WiFiInterface;
^~~~~~~~~~~~~
In file included from src\main.cpp:22:0:
C:/Users/mares/.platformio/packages/framework-mbed/components/wifi/esp8266-driver/ESP8266Interface.h:130:22: error: 'WiFiAccessPoint' has not been declared
virtual int scan(WiFiAccessPoint *res, unsigned count);
^~~~~~~~~~~~~~~
C:/Users/mares/.platformio/packages/framework-mbed/components/wifi/esp8266-driver/ESP8266Interface.h:146:29: error: type 'NetworkInterface' is not a base type for type 'ESP8266Interface'
using NetworkInterface::gethostbyname;
^~~~~~~~~~~~~
C:/Users/mares/.platformio/packages/framework-mbed/components/wifi/esp8266-driver/ESP8266Interface.h:153:29: error: type 'NetworkInterface' is not a base type for type 'ESP8266Interface'
using NetworkInterface::add_dns_server;
^~~~~~~~~~~~~~
src\main.cpp: In function 'void scan_demo(WiFiInterface*)':
src\main.cpp:46:5: error: 'WiFiAccessPoint' was not declared in this scope
WiFiAccessPoint *ap;
^~~~~~~~~~~~~~~
src\main.cpp:46:22: error: 'ap' was not declared in this scope
WiFiAccessPoint *ap;
^~
src\main.cpp:50:21: error: invalid use of incomplete type 'class WiFiInterface'
int count = wifi->scan(NULL,0);
^~
In file included from C:/Users/mares/.platformio/packages/framework-mbed/features/netsocket/NetworkStack.h:23:0,
from C:/Users/mares/.platformio/packages/framework-mbed/features/netsocket/InternetSocket.h:24,
from C:/Users/mares/.platformio/packages/framework-mbed/features/netsocket/TCPSocket.h:23,
from src\main.cpp:18:
C:/Users/mares/.platformio/packages/framework-mbed/features/netsocket/NetworkInterface.h:29:7: note: forward declaration of 'class WiFiInterface'
class WiFiInterface;
^~~~~~~~~~~~~
src\main.cpp:50:23: error: invalid use of incomplete type 'class WiFiInterface'
int count = wifi->scan(NULL,0);
^~~~
In file included from C:/Users/mares/.platformio/packages/framework-mbed/features/netsocket/NetworkStack.h:23:0,
from C:/Users/mares/.platformio/packages/framework-mbed/features/netsocket/InternetSocket.h:24,
from C:/Users/mares/.platformio/packages/framework-mbed/features/netsocket/TCPSocket.h:23,
from src\main.cpp:18:
C:/Users/mares/.platformio/packages/framework-mbed/features/netsocket/NetworkInterface.h:29:7: note: forward declaration of 'class WiFiInterface'
class WiFiInterface;
^~~~~~~~~~~~~
src\main.cpp:55:14: error: 'WiFiAccessPoint' does not name a type
ap = new WiFiAccessPoint[count];
^~~~~~~~~~~~~~~
src\main.cpp:56:17: error: invalid use of incomplete type 'class WiFiInterface'
count = wifi->scan(ap, count);
^~
In file included from C:/Users/mares/.platformio/packages/framework-mbed/features/netsocket/NetworkStack.h:23:0,
from C:/Users/mares/.platformio/packages/framework-mbed/features/netsocket/InternetSocket.h:24,
from C:/Users/mares/.platformio/packages/framework-mbed/features/netsocket/TCPSocket.h:23,
from src\main.cpp:18:
C:/Users/mares/.platformio/packages/framework-mbed/features/netsocket/NetworkInterface.h:29:7: note: forward declaration of 'class WiFiInterface'
class WiFiInterface;
^~~~~~~~~~~~~
src\main.cpp:56:19: error: invalid use of incomplete type 'class WiFiInterface'
count = wifi->scan(ap, count);
^~~~
In file included from C:/Users/mares/.platformio/packages/framework-mbed/features/netsocket/NetworkStack.h:23:0,
from C:/Users/mares/.platformio/packages/framework-mbed/features/netsocket/InternetSocket.h:24,
from C:/Users/mares/.platformio/packages/framework-mbed/features/netsocket/TCPSocket.h:23,
from src\main.cpp:18:
C:/Users/mares/.platformio/packages/framework-mbed/features/netsocket/NetworkInterface.h:29:7: note: forward declaration of 'class WiFiInterface'
class WiFiInterface;
^~~~~~~~~~~~~
src\main.cpp:65:14: error: type '<type error>' argument given to 'delete', expected pointer
delete[] ap;
^~
src\main.cpp: In function 'int main()':
src\main.cpp:97:20: error: cannot convert 'ESP8266Interface*' to 'WiFiInterface*' for argument '1' to 'void scan_demo(WiFiInterface*)'
scan_demo(&wifi);
^

src\main.cpp:113:20: error: cannot convert 'ESP8266Interface*' to 'NetworkInterface*' for argument '1' to 'void http_demo(NetworkInterface*)'
http_demo(&wifi);
^
*** [.pioenvs\nucleo_f429zi\src\main.o] Error 1
====================================================================================================== [ERROR] Took 34.21 seconds ======================================================================================================
The terminal process terminated with exit code: 1

Terminal will be reused by tasks, press any key to close it.

#2

What code are you compiling exactly? This one: https://os.mbed.com/teams/ESP8266/code/mbed-os-example-esp8266 ?

This is 2 years old. Mbed-os provides new examples at https://github.com/ARMmbed/mbed-os-example-wifi with the ESP8266 driver being at https://github.com/ARMmbed/esp8266-driver. I’ll try and compile this with my NodeMCU and Nucleo L152RE…


#3

Yeah I can get the above mbed-os-example-esp8266 to compile for a Bluepill board and with the latest v.1.7.0 firmware from Espressif (here, mind the issue I had with it here), but there are bugs preventing this from working correctly. One is that the esp8266-driver parses the APs in a wrong way, the other is that it can’t DNS resolve any host. Probably serial problems (buffer overrun due to not activated flow control, buffer sizes, …). I’ll debug this tomorrow.

BTW PIO / mbed-os actually has the mbed-esp8266-driver already builtin, but since you need to make modifications for now, downloading the library and putting it in lib/ is good idea.

[env:bluepill_f103c8]
platform = ststm32
; hacked according to https://github.com/platformio/platform-ststm32/issues/98 to get 128K flash 
; instead of 64K
board = genericSTM32F103CB
framework = mbed
lib_deps = esp8266-driver-master
lib_ignore = mbed-esp8266-driver
build_flags = 
	-D MBED_CONF_DRIVERS_UART_SERIAL_RXBUF_SIZE=2048
	-D MBED_CONF_APP_WIFI_SSID=\"my_wifi_name_here\" 
	-D MBED_CONF_APP_WIFI_PASSWORD=\"my_wifi_password_here\" 
	-D MBED_CONF_ESP8266_TX=PA_9
	-D MBED_CONF_ESP8266_RX=PA_10
;	-D MBED_CONF_ESP8266_RTS=PA_12
;	-D MBED_CONF_ESP8266_CTS=PA_11
	-D MBED_CONF_ESP8266_PROVIDE_DEFAULT=true
	-D MBED_CONF_ESP8266_SOCKET_BUFSIZE=4096
	-D PIO_FRAMEWORK_MBED_RTOS_PRESENT
	-D PIO_FRAMEWORK_MBED_EVENTS_PRESENT
	-D MBED_CONF_RTOS_PRESENT
	-D MBED_CONF_EVENTS_PRESENT
	-D MBED_CONF_NSAPI_PRESENT
	-I lib/esp8266-driver-master/ESP8266
	-I"$PIOHOME_DIR/packages/framework-mbed/features"
upload_protocol = stlink

the main.cpp needs the addition of

#include "ESP8266Interface.h"
ESP8266Interface esp;

and

    wifi = &esp;//WiFiInterface::get_default_instance();

Outputs right now


WiFi example
Mbed OS version 5.10.1

Scan:

Network: my_wifi_name_here secured: WPA2 BSSID: XX:XX:XX:XX:XX:XX RSSI: -34 Ch: 11
[... more networks...]
15 networks available.

Connecting to my_wifi_name_here
Success

MAC: XX:XX:XX:XX:XX:XX 
IP: 192.168.1.135
Netmask: 255.255.255.0
Gateway: 192.168.1.1
RSSI: -34

Sending HTTP request to www.arm.com...
Error connecting: -3009


#4

OK, if the code in scan_demo() doesn’t allocate enough AP objects the parser doesn’t scan the entire output and the there is a desync between the parser and the ESP, causing subsequent commands to be parsed wrong…

I have set up a repo at https://github.com/maxgerhardt/pio-mbedos-wifi. Please tell if you can reconfigure this for your board and get it working :).


#5

Thank You for advise.
This is my code, whitch I tried to compile with builtin ESP8266 library, ordinary example code.
Today I’ll try Your code.

/* WiFi Example
 * Copyright (c) 2016 ARM Limited
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "mbed.h"
#include "TCPSocket.h"

Serial ser(SERIAL_TX, SERIAL_RX, 115200);

#include "ESP8266Interface.h"
ESP8266Interface wifi(D1, D0);

const char *sec2str(nsapi_security_t sec)
{
    switch (sec) {
        case NSAPI_SECURITY_NONE:
            return "None";
        case NSAPI_SECURITY_WEP:
            return "WEP";
        case NSAPI_SECURITY_WPA:
            return "WPA";
        case NSAPI_SECURITY_WPA2:
            return "WPA2";
        case NSAPI_SECURITY_WPA_WPA2:
            return "WPA/WPA2";
        case NSAPI_SECURITY_UNKNOWN:
        default:
            return "Unknown";
    }
}

void scan_demo(WiFiInterface *wifi)
{
    WiFiAccessPoint *ap;

    printf("Scan:\r\n");

    int count = wifi->scan(NULL,0);

    /* Limit number of network arbitrary to 15 */
    count = count < 15 ? count : 15;

    ap = new WiFiAccessPoint[count];
    count = wifi->scan(ap, count);
    for (int i = 0; i < count; i++)
    {
        printf("Network: %s secured: %s BSSID: %hhX:%hhX:%hhX:%hhx:%hhx:%hhx RSSI: %hhd Ch: %hhd\r\n", ap[i].get_ssid(),
               sec2str(ap[i].get_security()), ap[i].get_bssid()[0], ap[i].get_bssid()[1], ap[i].get_bssid()[2],
               ap[i].get_bssid()[3], ap[i].get_bssid()[4], ap[i].get_bssid()[5], ap[i].get_rssi(), ap[i].get_channel());
    }
    printf("%d networks available.\r\n", count);

    delete[] ap;
}

void http_demo(NetworkInterface *net)
{
    TCPSocket socket;

    printf("Sending HTTP request to www.arm.com...\r\n");

    // Open a socket on the network interface, and create a TCP connection to www.arm.com
    socket.open(net);
    socket.connect("www.arm.com", 80);

    // Send a simple http request
    char sbuffer[] = "GET / HTTP/1.1\r\nHost: www.arm.com\r\n\r\n";
    int scount = socket.send(sbuffer, sizeof sbuffer);
    printf("sent %d [%.*s]\r\n", scount, strstr(sbuffer, "\r\n")-sbuffer, sbuffer);

    // Recieve a simple http response and print out the response line
    char rbuffer[64];
    int rcount = socket.recv(rbuffer, sizeof rbuffer);
    printf("recv %d [%.*s]\r\n", rcount, strstr(rbuffer, "\r\n")-rbuffer, rbuffer);

    // Close the socket to return its memory and bring down the network interface
    socket.close();
}

int main()
{
    printf("WiFi example\r\n\r\n");

    // Scan for available access points 
    scan_demo(&wifi);

    printf("\r\nConnecting...\r\n");
    int ret = wifi.connect(MBED_CONF_APP_WIFI_SSID, MBED_CONF_APP_WIFI_PASSWORD, NSAPI_SECURITY_WPA_WPA2);
    if (ret != 0) {
        printf("\r\nConnection error\r\n");
        return -1;
    }

    printf("Success\r\n\r\n");
    printf("MAC: %s\r\n", wifi.get_mac_address());
    printf("IP: %s\r\n", wifi.get_ip_address());
    printf("Netmask: %s\r\n", wifi.get_netmask());
    printf("Gateway: %s\r\n", wifi.get_gateway());
    printf("RSSI: %d\r\n\r\n", wifi.get_rssi());

    http_demo(&wifi);

    wifi.disconnect();

    printf("\r\nDone\r\n");
}

#6

I tried, but success was not complete :slight_smile:
First time I changed only board name, program build without errors and run, but not found any AP’s.
When I disconnect RTS/CTS (and changed in platformio.ini to NC, maybe my nodeMCU board don’t have this signals connected) program find AP’s, but can’t connect to network with -3010 error (DHCP failed).
I think my hardware works well, when I load my app, build with mbed os 5.7.6 and old ESP8266 driver, works good, list available APs, connects and communicate with network and myDevices trough Cayenne MQTT Client.
I think my ESP8266 have newest AT software:
AT+GMR
AT version:1.7.0.0(Aug 16 2018 00:57:04)
SDK version:3.0.0(d49923c)
compile time:Aug 23 2018 16:58:12
Bin version(Wroom 02):v1.7.0
OK

Your test app output:

WiFi example
Mbed OS version 5.10.1

Scan:
Network: 2.4G-czeska-23-1 secured: WPA/WPA2 BSSID: 54:A6:5C:51:50:2d RSSI: -63 Ch: 1
Network: vnet-14ECD4 secured: WPA/WPA2 BSSID: C0:7C:D1:31:71:e8 RSSI: -89 Ch: 1
Network: 2.4G-vnet-097CE6 secured: WPA/WPA2 BSSID: 0:71:C2:45:3f:e6 RSSI: -64 Ch: 7
Network: Vectra-WiFi-25E4A4 secured: WPA/WPA2 BSSID: DC:FE:7:1b:a:1e RSSI: -76 Ch: 8
4 networks available.

Connecting to 2.4G-czeska-23-1…

Connection error: -3010


#7

Do you have a special DHCP setup within your network? Static IP?

Could you take another USB-Serial converter and connect GND->GND and the RX of the adapter to the TX of the ESP8266 to see what data it responds with?


#8

I don’t have any special DHCP setup or Static IP setup. When I connect my ESP direct trough USB-serial to my PC, it connects without any problems to my WLAN (AT+CWJAP=SSID,PASWD).

But I don’t understand why response to wifi.connect() command is -3010 (DHCP ERROR)
esp8266-driver-master connect() member function don’t have this response in return possibilities. Maybe this is not error, because ret is not initialized it may have random value.

nsapi_error_t ESP8266::connect(const char *ap, const char *passPhrase)
{
_smutex.lock();
set_timeout(ESP8266_CONNECT_TIMEOUT);

_parser.send("AT+CWJAP_CUR=\"%s\",\"%s\"", ap, passPhrase);
if (!_parser.recv("OK\n")) {
    if (_fail) {
        _smutex.unlock();
        nsapi_error_t ret;
        if (_connect_error == 1) {
            ret = NSAPI_ERROR_CONNECTION_TIMEOUT;
        } else if (_connect_error == 2) {
            ret = NSAPI_ERROR_AUTH_FAILURE;
        } else if (_connect_error == 3) {
            ret = NSAPI_ERROR_NO_SSID;
        } else {
            ret = NSAPI_ERROR_NO_CONNECTION;
        }

        _fail = false;
        _connect_error = 0;
        set_timeout();
        return ret;
    }
}
set_timeout();
_smutex.unlock();

return NSAPI_ERROR_OK;

}


#9

But in all cases ret gets a value because there is an else { .. } path. It should come from https://github.com/ARMmbed/esp8266-driver/blob/master/ESP8266Interface.cpp#L162-L164. And for that we need to see what the ESP8266 sends via UART.


#10

I connected ESP serial port to serial monitor and tried run app.
Before this test I restored my ESP to factory defaults and … Success :slight_smile:
below session between NUCLEO and ESP:

ready
AT

OK
AT+RST

OK

 ets Jan  8 2013,rst cause:2, boot mode:(3,6)

load 0x40100000, len 2592, room 16
tail 0
chksum 0xf3
load 0x3ffe8000, len 764, room 8
tail 4
chksum 0x92
load 0x3ffe82fc, len 676, room 4
tail 0
chksum 0x22
csum 0x22

2nd boot version : 1.7(5d6f877)
SPI Speed : 40MHz
SPI Mode : DIO
SPI Flash Size & Map: 16Mbit(1024KB+1024KB)
jump to run user1 @ 1000

ü
Ź,˙ÂĹfc000ăě2Nä{ňo|älě{$b

rlÜoŕNÂll`
          ârlű
              ěsd
                 ârlěl
l`
  ârl
ű
 ll`{$n"äbcB|âě2BäňnÎoăl

                        l
dä
  lllnüllě˙"
l
c{$rl
ready
AT+GMR
AT version:1.7.0.0(Aug 16 2018 00:57:04)
SDK version:3.0.0(d49923c)
compile time:Aug 23 2018 16:58:12
Bin version(Wroom 02):v1.7.0
OK
AT+GMR
AT version:1.7.0.0(Aug 16 2018 00:57:04)
SDK version:3.0.0(d49923c)
compile time:Aug 23 2018 16:58:12
Bin version(Wroom 02):v1.7.0
OK
AT+CWMODE_DEF=1

OK
AT+CIPRECVMODE=1

OK
AT+CWMODE_CUR=1

OK
AT+CIPMUX=1

OK
AT+CWLAP
+CWLAP:(4,"2.4G-czeska-23-1",-74,"54:a6:5c:51:50:2d",1,15,0,5,3,7,1)
+CWLAP:(4,"vnet-14ECD4",-88,"c0:7c:d1:31:71:e8",1,-9,0,5,3,7,1)
+CWLAP:(4,"2.4G-vnet-097CE6",-67,"00:71:c2:45:3f:e6",7,0,0,5,3,7,1)

OK
AT+CWMODE_CUR=1

OK
AT+CIPMUX=1

OK
AT+CWDHCP_CUR=1,1

OK
AT+CWJAP_CUR="2.4G-czeska-23-1","passwd"
WIFI CONNECTED
WIFI GOT IP

OK
AT+CIFSR
+CIFSR:STAIP,"192.168.0.13"
+CIFSR:STAMAC,"5c:cf:7f:d1:a7:23"

OK
AT+CIFSR
+CIFSR:STAIP,"192.168.0.13"
+CIFSR:STAMAC,"5c:cf:7f:d1:a7:23"

OK
AT+CIFSR
+CIFSR:STAIP,"192.168.0.13"
+CIFSR:STAMAC,"5c:cf:7f:d1:a7:23"

OK
AT+CIPSTA_CUR?
+CIPSTA_CUR:ip:"192.168.0.13"
+CIPSTA_CUR:gateway:"192.168.0.1"
+CIPSTA_CUR:netmask:"255.255.255.0"

OK
AT+CIPSTA_CUR?
+CIPSTA_CUR:ip:"192.168.0.13"
+CIPSTA_CUR:gateway:"192.168.0.1"
+CIPSTA_CUR:netmask:"255.255.255.0"

OK
AT+CWJAP_CUR?
+CWJAP_CUR:"2.4G-czeska-23-1","54:a6:5c:51:50:2d",1,-76,0

OK
AT+CWLAP="","54:a6:5c:51:50:2d",
+CWLAP:(4,"2.4G-czeska-23-1",-70,"54:a6:5c:51:50:2d",1,15,0,5,3,7,1)

OK
AT+CIFSR
+CIFSR:STAIP,"192.168.0.13"
+CIFSR:STAMAC,"5c:cf:7f:d1:a7:23"

OK
AT+CIPSTART=1,"UDP","8.8.8.8",53,65535
1,CONNECT

OK
AT+CIPSEND=1,31

OK
>
Recv 31 bytes

SEND OK
AT+CIPCLOSE=1
1,CLOSED

OK
AT+CIPSTART=1,"UDP","209.244.0.3",53,65535
1,CONNECT

OK
AT+CIPSEND=1,31

OK
>
Recv 31 bytes

SEND OK

+IPD,1,225apiipifyorgŔ
T
nagano-19599    herokusslcomŔ+  o.elb097307-934924932   us-east-1elb    amazonawsŔBŔSyŰŔS6Ýę×ŔS2řÝŔS2ĺüŔS6ó{'ŔSr{AT+CIPCLOSE=1
1,CLOSED

OK
AT+CIPSTART=0,"TCP","23.21.121.219",80
0,CONNECT

OK
AT+CIPSEND=0,58

OK
>
Recv 58 bytes

SEND OK

+IPD,0,180
0,CLOSED
AT+CIPRECVDATA=0,64

+CIPRECVDATA,64:HTTP/1.1 200 OK
Server: Cowboy
Connection: close
Content-Type
OK
AT+CIPCLOSE=0
UNLINK

ERROR
AT+CWQAP

OK
WIFI DISCONNECT

But when I pushed reset button the problem came back, and I have DHCP error again.

AT

OK
AT+RST

OK

 ets Jan  8 2013,rst cause:2, boot mode:(3,6)

load 0x40100000, len 2592, room 16
tail 0
chksum 0xf3
load 0x3ffe8000, len 764, room 8
tail 4
chksum 0x92
load 0x3ffe82fc, len 676, room 4
tail 0
chksum 0x22
csum 0x22

2nd boot version : 1.7(5d6f877)
SPI Speed : 40MHz
SPI Mode : DIO
SPI Flash Size & Map: 16Mbit(1024KB+1024KB)
jump to run user1 @ 1000

ü
Ź,˙ÂĹfc000âěNě{űN|älělcÜđž
                          {$Üoŕnâld`
                                    â{l
                                       l
ě$`ărŰ$ěd
l â{l
ld`{loăBě
         b
          bb|ă
              ěäňnîoNâlß
                        l
$ě
  llloüâ
        b
$lä

žbcl

cr$rd
ready
AT+GMR
AT version:1.7.0.0(Aug 16 2018 00:57:04)
SDK version:3.0.0(d49923c)
compile time:Aug 23 2018 16:58:12
Bin version(Wroom 02):v1.7.0
OK
AT+GMR
AT version:1.7.0.0(Aug 16 2018 00:57:04)
SDK version:3.0.0(d49923c)
compile time:Aug 23 2018 16:58:12
Bin version(Wroom 02):v1.7.0
OK
AT+CWMODE_DEF=1

OK
AT+CIPRECVMODE=1

OK
AT+CWMODE_CUR=1

OK
AT+CIPMUX=1

OK
AT+CWLAP
+CWLAP:(4,"2.4G-czeska-23-1",-74,"54:a6:5c:51:50:2d",1,15,0,5,3,7,1)
+CWLAP:(4,"vnet-14ECD4",-91,"c0:7c:d1:31:71:e8",1,-9,0,5,3,7,1)
+CWLAP:(4,"2.4G-vnet-097CE6",-72,"00:71:c2:45:3f:e6",7,0,0,5,3,7,1)
+CWLAP:(4,"Vectra-WiFi-25E4A4",-73,"dc:fe:07:1b:0a:1e",8,5,0,5,3,7,1)

OK
AT+CWMODE_CUR=1

OK
AT+CIPMUX=1

OK
AT+CWDHCP_CUR=1,1

OK
AT+CWJAP_CUR="2.4G-czeska-23-1","passwd"
WIFI DISCONNECT
WIFI CONNECTED
WIFI GOT IP

OK

Here you can see, that there is a connection, but driver or parser signal an error.
Yesterday I had saved old configuraction of SSID and pass (the same because only one visible network is mine) and driver can’t connect. Today connected only once, after restore, later misinterprets WIFI DISCONNECT/CONNECT sequence.


#11

The log looks OK but as you said the AT command parser seems to wrongly interpret the responses.

Or its serial buffer overflows… In the platformio.ini I have a RX buffer size switch. Maybe also try to find out if the RTS/CTS pins from the ESP8266 are routed to your board? They are IO13 and IO15 as I’ve written in thr readme.

I can’t reproduce this here with flow control activated.

Can you put debug prints in the dhcp() function where it fails (returns DHCP error) to see what the parser thinks it saw?


#12

I don’t know why, but now I disconnected/connected power and all works with sucess after start, after reset, all the time.


#13

Maybe try to factory restore one more time to make it reproducable? Send AT+RESTORE to the ESP.

But hey, if it works :). Development of that driver with the v1.7 firmware will only improve over time. They even merged the bugfix for the AP already.


#14

Unfortunatly it does not work well. It works very slow and unstable. When I run my app, compiled online with old mbed 5.7.6 and esp driver, when program starts and connects to WLAN, to console MAC, IP, and other info are writen, all this takes a split second, but when I run your example lines are displayed every 1-2 seconds. I tried set serial buffers, nothing changed.

I moved my application (Cayenne myDevices client with BME280 sensor) from Online Compiler to VSCode with platformio (only copy my sources and replace main.cpp from Your example) It works, but startup infos are displayed just as slowly and after receiving 1-2 commands from Cayenne dashboard all crashes with general fault:

++ MbedOS Fault Handler ++

FaultType: HardFault

Context:
R0 : B908006D
R1 : 00000018
R2 : 20001A60
R3 : 00000025
R4 : 20005CA0
R5 : 00000001
R6 : 00000001
R7 : 20005A84
R8 : 20001D98
R9 : 20001D97
R10 : 0801D2EC
R11 : 00000000
R12 : 08007D51
SP : 2002FFA8
LR : 08006DDB
PC : 08007DFC
xPSR : 810F000B
PSP : 20001D18
MSP : 2002FF88
CPUID: 410FC241
HFSR : 40000000
MMFSR: 00000000
BFSR : 00000082
UFSR : 00000000
DFSR : 00000008
AFSR : 00000000
BFAR : B908008D
Mode : Handler
Priv : Privileged
Stack: MSP

– MbedOS Fault Handler –

It’s enough for today, I’m going to watch “House of Cards” :slight_smile:


#15

There’s still the possibility to downgrade to a lower mbed-os version and use the same ESP8266-driver code you’re using now. In the platformio.ini you can e.g. specify platform = ststm32@4.3.0 to get a version with mbedos 5.8.6. Release page is at https://github.com/platformio/platform-ststm32/releases.

BTW I also noticed that this newer driver takes very long to do anything. Not sure if misconfiguration or bug.


#16

I changed esp8266-driver-master to my old, good esp8266-driver and all works fast and stable in mbed os 5.10.1 for several hours. This old driver have own ATParser and BufferedSerial code, differently than newest. Maybe here is the main problem of new driver ?

Thank you for help.
Marek