B4R Question WiFi AP: why no connection ?

peacemaker

Expert
Licensed User
Longtime User
Hi, All

My question is absolutely the same like this https://www.b4x.com/android/forum/threads/access-point-not-working-with-b4r.121009/
But trying on ESP32C3.

This Arduino sketch is fully OK, with connected USB-port of the board, or just powered up:
C++:
#include <WiFi.h>
#include <NetworkClient.h>
#include <WiFiAP.h>
void setup()
{
  Serial.begin(115200);
  Serial.println();
  Serial.print("Setting soft-AP ... ");
  boolean result = WiFi.softAP("ESPsoftAP_01", "");
  if(result == true)
  {
    Serial.println("Ready");
  }
  else
  {
    Serial.println("Failed!");
  }
}

void loop() {
  // put your main code here, to run repeatedly:

}

But my B4R variant
1) is OK only when board is connected to USB
2) but if just powered, without USB plugged - AP is visible but cannot be connected


B4X:
#Region Project Attributes
    #AutoFlushLogs: True
    #CheckArrayBounds: True
    #StackBufferSize: 600
#End Region

Sub Process_Globals
    Public Serial1 As Serial
    Private wifi As ESP8266WiFi
    
    Private bc As ByteConverter
    Private Astream As AsyncStreams
    Private server As WiFiServerSocket
End Sub

Private Sub AppStart
    Serial1.Initialize(115200)
    Delay(3000)
    Log("AppStart")
    Start
End Sub


Public Sub Start
    Log("StartAP: ", wifi.StartAccessPoint2("AP_name", ""))
    Log("My AP ip: ", wifi.AccessPointIp)
    server.Initialize(80, "server_NewConnection")
    server.Listen
End Sub

Private Sub Server_NewConnection (NewSocket As WiFiSocket)
    Astream.Initialize(NewSocket.Stream, "astream_NewData", "astream_Error")
End Sub

Private Sub Astream_NewData (Buffer() As Byte)
    Log(Buffer)
    If bc.IndexOf(Buffer, "GET") <> -1 Then
        If bc.IndexOf(Buffer, "/set") <> -1 Then
            
            Dim ssid = "", password  = "" As String
            Dim i1 As Int = 0
            Dim i2 As Int = 0
            For Each b1() As Byte In bc.Split(Buffer, " ")
                If i1 = 1 Then
                    For Each b2() As Byte In bc.Split(b1, "/")
                        Select i2
                            Case 2
                                ssid = bc.StringFromBytes(b2)
                                Log("New ssid = ", ssid)
                            Case 3
                                password = bc.StringFromBytes(b2)
                                Log("New pass = ", password)
                        End Select
                        i2 = i2 + 1
                    Next
                    
                End If
                i1 = i1 + 1
            Next
            Log("StackBufferUsage2 = ", StackBufferUsage)
            Astream.Write("HTTP/1.1 200").Write(CRLF)
            Astream.Write("Content-Type: text/html").Write(CRLF).Write(CRLF)
            If ssid.Length > 14 Or password.Length > 14 Then
                Astream.Write("WiFi SSID or password is too long, change shorter")
            Else
                Astream.Write("<script>setTimeout(function(){location.href=""http://192.168.4.1""} , 5000);</script>")
                Astream.Write("WiFi has been set to: ").Write(ssid).Write(", password: ").Write(password)    '.Write("<br/>Please wait...")
                Log("AP: ssid and password are received")
                GlobalStore.Put(0, ssid)
                GlobalStore.Put(1, password)

                CallSubPlus("ConnectWifi", 500, 0)
            End If
        Else If bc.IndexOf(Buffer, " / ") <> -1 Then
            Astream.Write("HTTP/1.1 200").Write(CRLF).Write(CRLF)
            If wifi.IsConnected Then
                Astream.Write("Connected to network.").Write(CRLF)
                Astream.Write("Device IP address: ").Write(wifi.LocalIp)
                'others.restart(0)
            Else
                Astream.Write("Not connected!")
            End If
        Else
            Astream.Write("HTTP/1.1 404").Write(CRLF)
        End If
        CallSubPlus("CloseConnection", 200, 0)
    End If
End Sub

Private Sub ConnectWifi(u As Byte)
    'example of connecting to a local network
    If wifi.Connect2(bc.StringFromBytes(GlobalStore.Slot0), bc.StringFromBytes(GlobalStore.Slot1)) Then
        Log("Connected to network")
    Else
        Log("Failed to connect to network")
    End If
End Sub

Private Sub CloseConnection(u As Byte)
    Log("Close AP connection")
    If server.Socket.Connected Then
        server.Socket.Stream.Flush
        server.Socket.Close
    End If
End Sub

Private Sub AStream_Error
    Log("AP AStream_Error: disconnected")
    server.Listen
End Sub

Why ?

I have compared the lib - the same call of WiFi.softAP.
I have even made a lib clone for ESP32 only, to edit (attached). deleted there WiFi.disconnect() - all is the same, but ....does not work...
Where to dig ?
 

Attachments

  • rESP32WiFi.zip
    8.7 KB · Views: 55

peacemaker

Expert
Licensed User
Longtime User
More tests:
1) ESP32S2 - is also built-in USB-host (as ESP32C3), and also the B4R softAP code does not work, if powered without USB data connection (from just USB power adapter).
2) Old good ESP32 (without built-in USB) - B4R code is fully OK at any power variant!

Team, please, try to find the reason: ready test project is attached
 

Attachments

  • esp32c3_softap.zip
    2.9 KB · Views: 50
Last edited:
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
I can state that ESP32C3, S2, S3 and other fresh new MCU with built-in USB-host - are not somehow compatible with B4R's WiFiServerSocket and maybe also WiFiSocket.
As the AP is visible, but connection is not established, but Arduino's WiFiAccessPoint example works always OK (SDK 3.0.4).

@Erel, could you help to understand it and fix ?
 
Last edited:
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
ESP32C3 supermini board:

ESP32S2 mini board (purple color):

These are now tiniest MCUs with WiFi (some are + BT) and with USB ready to use and mass available. Old good ESP32 is huge now already in size.
 
Upvote 0

Pitag

Member
Licensed User
Longtime User
I'm interested in those type of new versions of ESP processors. They are very small but not despite of functionality.
Some month ago i tested those 2, i will try to remember the result but i will check again when will come back home from my businnes trip, next week
ESP-32 C3
cannot get it work even with a simple sketch, if i remember well.

ESP-32 S3
https://www.amazon.it/gp/product/B0CJJPJZ2H/ref=ppx_yo_dt_b_asin_image_o00_s00?ie=UTF8&psc=1
if i remember well (again) in this case i was able to upload a sketch, but there was no way to get the logs from the sketch (probably there something that i ignore to get it work)

Hope that in a near future this platforms will be compatible with B4R, even if for the moment i'm working very well with ESP32 D1 MINI that is small but with full functionality.
 
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
any driver
No special driver installed under Win10.

C3 is shown as COM-port (USB\VID_303A&PID_1001&MI_00\8&2C805C15&0&0000) and USB devices\USB JTAG/serial debug unit (USB\VID_303A&PID_1001&MI_02\8&2C805C15&0&0002)

S2 is just COM-port (USB\VID_303A&PID_0002&MI_00\8&1FE9EA56&0&0000)
 
Upvote 0

MbedAndroid

Well-Known Member
Licensed User
Longtime User
I'm interested in those type of new versions of ESP processors. They are very small but not despite of functionality.
Some month ago i tested those 2, i will try to remember the result but i will check again when will come back home from my businnes trip, next week
ESP-32 C3
cannot get it work even with a simple sketch, if i remember well.

ESP-32 S3
if i remember well (again) in this case i was able to upload a sketch, but there was no way to get the logs from the sketch (probably there something that i ignore to get it work)

Hope that in a near future this platforms will be compatible with B4R, even if for the moment i'm working very well with ESP32 D1 MINI that is small but with full functionality.
it's already a old post, but the 2 cents i can add: I bought 2 of these on ali, which look similar to the types you bought.

They don't work. Either you get no output at all, or the Esp resets. Both on Arduino, and with B4r. In a topic elsewhere I found that these are possibly Esp32 cores with no memory, so can't work.... Unfortunately I can't read the type well on the chip, but looks to me like the letters FN are present. .


mabbaco
1072310_2.png
mysteriousorb
1 meipost #22

I have used many of these boards. Make sure the SuperMini has the ESP32C3FN4 chip which has the on chip SRAM. I mistakenly purchased a batch of Esp32C3 CORE SuperMini which look identical, but do not have the on chip SRAM. These are useless as a mini module and do not work with the IDE or any other platform without additional SRAM. There are many CORE Dev boards I've used that are full size and have the SRAM as a separate chip. I do not understand why the SuperMini version of the CORE exists. I got burnt with them.
 
Upvote 0
Top