9 years, 3 months ago.

Any example code?

Hi, I tried this, maybe I'm doing it wrong :)

It doesn't get past pc.printf("after reset\n");

Update: I used

Serial pc(USBTX, USBRX);
ESP8266_WebServer ESP_WS(&pc);

And I see requests on my pc terminal, but it hangs inside functions due to not having a timeout

#include "mbed.h"
#include "ESP8266_WebServer.h"

Serial pc(USBTX, USBRX);
Serial esp(PA_11, PA_12);
ESP8266_WebServer ESP_WS(&esp);


int main()
{
    pc.baud(115200);
    esp.baud(115200);
    wait(0.5);
    
    pc.printf("before reset?");
    ESP_WS.ResetModule();
    pc.printf("after reset\n");
    ESP_WS.Initialize();
    pc.printf("initialized?\n");
    
    while(1) {
        
    }
}

Question relating to:

ESP8266 WiFi Module Web Server library ESP8266

2 Answers

9 years, 3 months ago.

Hi Radu

This library is not quite ready for public consumption yet, and is primarily used in our WiFi Lamp project. It still has a few kinks and quibbles, and thats also why I haven't publicly listed it yet,

Nonetheless, here is a bit of code which should get you started

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

//#define DEBUG_WIFI

Serial wifiSerial(PA_11,PA_12);
Serial pc(USBTX,USBRX);
ESP8266_WebServer server(&wifiSerial);

void rxint(void) {
    server.rxint();
}

int main() {
    pc.baud(115200);
    wifiSerial.baud(115200);
    wifiSerial.attach(&rxint);
#ifdef DEBUG_WIFI
    server.debugSerial = &pc;
    pc.printf("Debug WiFi Enabled!\r\n");
#endif
    wait_ms(1000);
    
    pc.printf("Hardware Reset WiFi...\r\n");    
    server.ResetModule();
    
    std::string fwVer = server.GetFirmwareVersion();
    pc.printf("ESP Firmware Version: %s\r\n", fwVer.c_str());
    
    pc.printf("Starting Web Server...\r\n");
    server.Initialize();
    pc.printf("Done\r\n");

    int opMode = server.GetOperatingMode();
    pc.printf("Operating Mode: %s(%d)\r\n", opModes[opMode], opMode);
    if( (opMode & OPMODE_STATION) ) {
        pc.printf("Waiting 5 secs for join to WiFi Network...\r\n");
        wait_ms(5000);
        std::string stationMAC = server.GetStationMAC();
        std::string stationIP = server.GetStationIP();
        std::string ssid = server.GetStationSSID();
        pc.printf("Station MAC: %s, Station SSID: %s, Station IP: %s\r\n", stationMAC.c_str(), ssid.c_str(), stationIP.c_str());
    }
    if( (opMode & OPMODE_SOFTAP) ) {
        std::string apMAC = server.GetAPMAC();
        std::string apIP = server.GetAPIP();
        pc.printf("SoftAP MAC: %s, SoftAP IP: %s\r\n", apMAC.c_str(), apIP.c_str());
    }

    while(true) {
        ESP8266_WebRequest* request = server.GetRequest();
        if( request != NULL ) {
            pc.printf("HTTP %s %s\r\n", request->Method.c_str(), request->URI.c_str());
            if( request->URI == "/" || request->URI == "/index.html" ) {
                server.SendReply(request->LinkID, "<html><body>It Works!</body></html>", mimeHTML, 0);
            } else {
                server.Send404Error(request->LinkID);
            }
            pc.printf("\r\nHTTP Reply Sent\r\n");
            delete request;
        }
    }
}

Information

You can uncomment the DEBUG_WIFI define to make the library print out a lot of debugging information.

Warning

This sample requires about 33kb of Flash, and 8kb of RAM. Any hardware with less RAM or Flash will not work.

Accepted Answer

Hi and thanks, I was reluctant at first to ask, considering it was not public, but I just had to :D I'm packed with a Nucleo F411RE. I'll keep you posted.

Well, as a good news it works.I need to update my firmware to support the new CIPSTA commands

posted by Radu Radoveneanu 12 Jan 2015

All good. A bit of publicity will force me to bring it up to standard :-)

BTW, I have found this firmware to be quite stable and seems pretty official https://github.com/espressif/esp8266_at

posted by Sebastian Schocke 13 Jan 2015
9 years, 3 months ago.

As I and other have found, the recent ESP8266 modules are 9600 buad, there is no auto-baud so you may want to try this setting.

Mine works at 11500 so that was not the issue :)

posted by Radu Radoveneanu 12 Jan 2015

Hi Paul

A lot of recent ESP8266 modules are very mixed in regards to their baud rate, and I have not been able to determine a definite guide to figuring it out. My own module was first 9600, but when I upgraded it to the latest Espressif AT firmware, it changed to 115200 https://github.com/espressif/esp8266_at

posted by Sebastian Schocke 13 Jan 2015