Android Question B4A failed to connect to Esp8266 with hidden ssid

Discussion in 'Android Questions' started by hung, Feb 1, 2019.

  1. hung

    hung Member Licensed User

    I used MLwifi 3.07 to make wifi connection in B4A but found the following problem
    - B4A app shows connected successfully but Android phone's wifi setting is still showing old ssid
    - then in 2-3 seconds Android phone disconnect wifi and start searching to saved prefered ssid

    Any one help?

    B4A code as below
    Code:
    Sub Process_Globals
        
    'These global variables will be declared once when the application starts.
        'These variables can be accessed from all modules.
        Dim wifi As MLwifi
        
    Dim scan As MLScan 
    End Sub

    Sub Globals
        
    'These global variables will be redeclared each time the activity is created.
        'These variables can only be accessed from this module.

        
    Private btn_connect As Button
        
    Private edt_pass As EditText
        
    Private edt_ssid As EditText
    End Sub

    Sub Activity_Create(FirstTime As Boolean)
        
    'Do not forget to load the layout file created with the visual designer. For example:
        Activity.LoadLayout("main")
        
        
    If Not (wifi.isWifiConnected) Then
            wifi.EnableWifi(
    True)
        
    End If
        scan.startScan(
    "wifiscan"True)   
        
    End Sub

    Sub Activity_Resume

    End Sub

    Sub Activity_Pause (UserClosed As Boolean)

    End Sub

    Sub btn_connect_Click
        wifi.disconnectWifiAP()
        Sleep(
    1000)
        
    Msgbox("Start connecting""wifi")
        
    If wifi.saveWifiAP(edt_ssid.Text, 2, edt_pass.Text, False) = True Then
            
    If wifi.connectWifiAP(edt_ssid.Text ) = True Then
            
    'If wifi.isWifiConnected() Then
                Msgbox("Connected", edt_ssid.Text )
            
    Else
                
    Msgbox("Failed to connect", edt_ssid.Text)
            
    End If
        
    Else
            
    Msgbox("Failed to save AP", edt_ssid.text)
        
    End If
        
        
    Msgbox(wifi.WifiSSID, "Current SSID")
    End Sub

    Sub wifiscan_ScanDone(results() As String, count As Int)
        
    Dim lstr_ap As String
        
        
    For i = 0 To count - 1
            lstr_ap = lstr_ap & 
    ":" & results(i).Replace(",","    ")
        
    Next
        
    Msgbox(lstr_ap, count)
    End Sub
    ESP8266 (NodeMCU) code as below
    Code:
    #include <ESP8266WiFi.h>

    // WiFi Definitions
    const char* ssid = "Esp01-1901";
    const char* password = "Esp01-1901"
    const char* value = "";

    WiFiServer 
    server(80); // default ip http://192.168.4.1:80

    void setup() {

       
    Serial.begin(115200);
       delay(
    10);

       WiFi.mode(WIFI_AP);
       WiFi.softAP(ssid, password, 
    11);
     
       
    server.begin();
    }

    void loop() {
      // Check of client has connected
      WiFiClient client = server.available();
      if(!client) {
        return;
      }

      // Read the request line
      String request = client.readStringUntil('\r');
      Serial.println(request);
      client.flush();
    }
     
  2. Erel

    Erel Administrator Staff Member Licensed User

  3. hung

    hung Member Licensed User

    Thank you Erel. The link helps.

    I am good at Arduino C. Will try B4R later :)
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice