Giter Site home page Giter Site logo

Comments (7)

ameerhazo avatar ameerhazo commented on August 23, 2024

Hi @Juerd, could you please help me with my problem here :D Would be greatly appreciated.

from esp-wifisettings.

Juerd avatar Juerd commented on August 23, 2024

from esp-wifisettings.

ameerhazo avatar ameerhazo commented on August 23, 2024

Hello @Juerd, thanks for the fast reply. In the API reference section, you wrote,

void portal();

Normally, this function is called by .connect(). To allow reconfiguration after the initial configuration, you could call .portal() manually, for example when a button is pressed during startup.

I wish it would work like this. Unfortunately, when this function is called, the portal AP is opened and I'm able to connect to the AP but accessing the AP on the browser gives me a HTTP 500 error.

from esp-wifisettings.

Juerd avatar Juerd commented on August 23, 2024

from esp-wifisettings.

ameerhazo avatar ameerhazo commented on August 23, 2024

Hi @Juerd thanks for the code example, I'll try it out on my end to see if it works for me. Thank you and have a nice evening :D

from esp-wifisettings.

ameerhazo avatar ameerhazo commented on August 23, 2024

Hi @Juerd, so I've been trying to figure out why WiFiSettings.portal() is not working for me for my code usage. The code is as follows:

` // display device info on config page
WiFiSettings.hostname = device_ID;
WiFiSettings.heading("Device ID:");
WiFiSettings.heading(device_ID);

// Define custom settings saved by WifiSettings
// MQTT configuration variable to be shown on config UI provided by the WiFi Settings library
bool checkbox_mqtt_auth_dummy = WiFiSettings.checkbox("MQTT broker authentification");
String mqtt_brokeraddress_dummy = WiFiSettings.string("MQTT broker address", "mqtt.eclipse.org");
String mqtt_brokerauth_user = WiFiSettings.string("Username", "username");
String mqtt_brokerauth_pass = WiFiSettings.string("Password", "password");

// try to connect to WiFi with a timeout of 30 seconds - launch portal if connection fails
WiFiSettings.connect(true, -1);

// MQTT config
checkbox_mqtt_auth = checkbox_mqtt_auth_dummy;
Mqttbrokeraddress = mqtt_brokeraddress_dummy;
Mqtt_auth_username = mqtt_brokerauth_user;
Mqtt_auth_password = mqtt_brokerauth_pass;
//

// if user wants MQTT to be used, set the MQTT Broker, port number and the MQTT Client

MQTT_Client.setServer(Mqttbrokeraddress.c_str(), 1883);
MQTT_Client.setClient(hagerClient);

int retries = 0;

while (retries < 5)
{
    retries++;

    if (checkbox_mqtt_auth) // mqtt broker needs authentification data to connect
    {
        connected_tobroker = MQTT_Client.connect(device_ID, Mqtt_auth_username.c_str(), Mqtt_auth_password.c_str(), lwt_Topic.c_str(), 1, true, lwt_message.c_str());
    }
    else // mqtt broker doesnt need authentication to connect
    {
        connected_tobroker = MQTT_Client.connect(device_ID, lwt_Topic.c_str(), 1, true, lwt_message.c_str());
    }

    if (connected_tobroker)
    {
        Serial.println("Connected to MQTT Broker."); // successfully connected to broker

        break;
    }
    else
    {
        Serial.println(retries);
        Serial.println("Connecting to MQTT Broker failed... ");
        Serial.print("failed, MQTT connection status =");
        Serial.print(MQTT_Client.state());
        Serial.println(" try again in 5 seconds");
        // Wait 5 seconds before retrying
        delay(5000);
    }
}

if(!connected_tobroker) // if number of MQTT reconnection attempts exceeds the maximum retry limit, open the portal
{
    Serial.println("Retries exceeded, restarting device");
    WiFiSettings.portal(); // this doesnt work for some reason
}`

So the gist of the code is that I want the portal to be restarted again if the MQTT connection to the broker is not successful after a few tries. (User may have given wrong username or password for the broker connection on the portal or the MQTT broker is down). This is to ensure that I'm able to prevent the device from going into an infinite loop not doing anything and gives the user the option to fix the mistake.

The bug I found is that when I called the WiFiSettings.portal() method, I can see that the portal is up. I'm also able to connect to the soft AP (takes longer for some reason) but I'm unable to access the portal (HTTP ERROR 500). I also noticed that I cant see the debugging output in the serial monitor that usually shows up when I'm connected to device (eg. 13 WiFi Networks found).

It would be greatly appreciated if you could help me debug this because this library is really quite practical :D and I thank you again for your work.

Regards,
Ameer

from esp-wifisettings.

Juerd avatar Juerd commented on August 23, 2024

I don't know what's wrong.

from esp-wifisettings.

Related Issues (18)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.