B4R Question Configure esp8266 through the B4A application

Cesar_Morisco

Active Member
Hey guys
All good
Could anyone let me know or have an example I could start with.
How can I configure the esp8266 through my B4A app to not use the ESPConfigurator B4J Thanks in advance
 

hatzisn

Expert
Licensed User
Longtime User
Morisco? Sounds 'different'...
 
Upvote 0

hatzisn

Expert
Licensed User
Longtime User
I have ready made woking example wirh code like this. I can sell it to you for 25EUR. If you are interested please send me a PM. It includes getting wifi data, connecting, saving credentials, identification and OTA update.
 
Upvote 0

candide

Active Member
Licensed User
why not to add a small server on your esp8266 and after you can make configuration with a navigators on PC, smartphone or tablet.
you can find several examples FREE on this forum
 
Upvote 0

Cesar_Morisco

Active Member
por que não adicionar um pequeno servidor em seu esp8266 e depois você pode fazer a configuração com um navegador no PC, smartphone ou tablet.
você pode encontrar vários exemplos GRÁTIS neste fórum

Hello Candide how are you?
Seriously, where I already did a scan about it, I didn't find anything on the esp configuration web
Thank you already
 
Upvote 0

candide

Active Member
Licensed User
not sure if it is what you are looking for, but you can have a look on 2 things :

in WiFiServer.bas you have a WIFI server to make provisioning of esp cionfiguration

https://www.b4x.com/android/forum/threads/rf-433mhz-repeater-with-esp8266.118558/
also, in WiFiServer.bas you have a WIFI server to make provisioning of esp cionfiguration

good luck in your research.
 
Upvote 0

Cesar_Morisco

Active Member
not sure if it is what you are looking for, but you can have a look on 2 things :

in WiFiServer.bas you have a WIFI server to make provisioning of esp cionfiguration

https://www.b4x.com/android/forum/threads/rf-433mhz-repeater-with-esp8266.118558/
also, in WiFiServer.bas you have a WIFI server to make provisioning of esp cionfiguration

good luck in your research.
Hello again Candide
This is going to help me a lot
A doubt to configure the esp I have to fill in all the fields or just the configuration of my router, thank you
 
Upvote 0

candide

Active Member
Licensed User
first time, without WIFI configuration, esp will start in ap mode : you will have to connect your mobile or you PC on the network "esp" and you have to connect your navigator to 192.168. 4.1 and you will see html page from esp.

after, when esp is able to connect to a network with provisioning, you can connect to Ip address of esp and you will have same esp page.

if you want only parameters for wifi , you have to take fields for wifi, and to remove others
 
Upvote 0

Cesar_Morisco

Active Member
first time, without WIFI configuration, esp will start in ap mode : you will have to connect your mobile or you PC on the network "esp" and you have to connect your navigator to 192.168. 4.1 and you will see html page from esp.

after, when esp is able to connect to a network with provisioning, you can connect to Ip address of esp and you will have same esp page.

if you want only parameters for wifi , you have to take fields for wifi, and to remove others
Hello everything is fine
I made a new one using your example I can't make a connection with my routed here my code
I thank
SSID:
Private Sub Astream_NewData (Buffer() As Byte)
    Log("startB=",Buffer,"=endB")
    If bc.IndexOf(Buffer, "save?_nwk=") <> -1 Then

        Dim init(10) As Object
        Dim pt1,pt2 As Int

        pt1 = bc.IndexOf(Buffer, "save?_nwk=")+10
        pt2 = bc.IndexOf(Buffer, "&_key=")
        init(0) = bc.substring2(Buffer,pt1,pt2)

        pt2 = bc.IndexOf(Buffer, "&_ss1=")
        init(1) =bc.substring2(Buffer,pt1,pt2)
        init(1) = ReplaceString(init(1),"%2F","/")
        init(1) = ReplaceString(init(1),"%25","%")
        
        pt1 = pt2+6
        pt2 = bc.IndexOf(Buffer, "&_ss2=")
        init(2) =bc.substring2(Buffer,pt1,pt2)
        
        pt1 = pt2+6
        pt2 = bc.IndexOf(Buffer, "&_save=")
        init(3) =bc.substring2(Buffer,pt1,pt2)

        Main.SaveNetworkDetails(sr.ConvertArrayToBytes(init))
    Else
        If bc.IndexOf(Buffer, "/_abort?_abort=") <> -1 Then
            Log("abort input")
        Else
            If bc.IndexOf(Buffer, "/_abort?_clear=") <> -1 Then
                Log("clear eeprow")
                Main.ClearStoredDataLength
            End If
        End If
    End If

End Sub
 

Attachments

  • Sem título.png
    Sem título.png
    74.8 KB · Views: 146
Upvote 0

candide

Active Member
Licensed User
with a Log at start of "Sub Astream_NewData", you can check what you receive from html page and after with a few more "Log" you can check what values are extracted in init(1), init(2) and init(3)
when this part is OK, you have to look at save in eeprom, but if no modification in this part, it should work.
after you can check what are values from eeprom at wifi connection...
 
Upvote 0

Cesar_Morisco

Active Member
Hello Candide
OK I don't know what's wrong I can't get a connection to my router
here the logo
If anyone could tell me what is wrong I would be grateful
here in the code:
AppStart
StartAP: 1
My AP ip: 192.168.4.1
My local ip: (IP unset)
Network data not found.
startB=GET /save?_nwk=Help-Info+Central+Tec+8.00&_key=Pp1c6s0m8&_save= HTTP/1.1
Host: 192.168.4.1
Connection: keep-alive
Upgrade-Insecure-Requests: 1


User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36 Edg/115.0.1901.188
Accept: text/html,application/xhtml+xml,application/xml;q=0=endB
 ets Jan  8 2013,rst cause:4, boot mode:(3,6)
wdt reset
load 0x4010f000, len 3460, room 16
tail 4
chksum 0xcc
load 0x3fff20b8, len 40, room 4
tail 4
chksum 0xc9
csum 0xc9
v000484e0
~ld
AppStart
StartAP: 1
My AP ip: 192.168.4.1
My local ip: (IP unset)
Network data not found.
here in the code:
Dim init(4) As Object
        Dim pt1,pt2 As Int

        pt1 = bc.IndexOf(Buffer, "save?_nwk=")+10
        pt2 = bc.IndexOf(Buffer, "&_key=")
        init(0) = bc.substring2(Buffer,pt1,pt2)

    
        init(2) = ReplaceString(init(2),"%2F","/")
        init(2) = ReplaceString(init(2),"%25","%")
        
        
        pt1 = pt2+6
        pt2 = bc.IndexOf(Buffer, "&_save=")
        init(3) =bc.substring2(Buffer,pt1,pt2)

        Main.SaveNetworkDetails(sr.ConvertArrayToBytes(init))
 
Upvote 0

candide

Active Member
Licensed User
can you check if this functional code quicky built can help you ?

new version without Gstore.bas and more clean.

First time, connect PC or Mobile on AP network 'esp' and open on Navigator a page on 198.168.4.1
next times, you have to connect to Ip of esp.

2 text inputs for SSID and Password
Button Save will save inputs in eeprom
Button Clear eeprom will erase eeprom
Button Reload data will update html page ( mandatory after Save or Clear to update eeprom content in html page)
to update wifi connexion, you have to reset esp.
 
Last edited:
Upvote 0

Cesar_Morisco

Active Member
can you check if this functional code quicky built can help you ?

hello candido all
Good.
The mistake as always was mine lol
the wifi network
I had the freco signal
It worked after deleting this code... I have no idea what it's for
Thank you from the heart
here:
'        init(1) = ReplaceString(init(1),"%2F","/")
'        init(1) = ReplaceString(init(1),"%25","%")
'
 
Upvote 0

candide

Active Member
Licensed User
here:
B4X:
'        init(1) = ReplaceString(init(1),"%2F","/")
'        init(1) = ReplaceString(init(1),"%25","%")
'
it is in case of char "/" and "%" used in SSID or password, in this case we receive in Astream_NewData "%2F" and "%25"

new version taking in account all unicode possible in user/password.
 

Attachments

  • ESP_ConfigV1.1.zip
    3.9 KB · Views: 120
Last edited:
Upvote 0

Cesar_Morisco

Active Member
it is in case of char "/" and "%" used in SSID or password, in this case we receive in Astream_NewData "%2F" and "%25"
Hello Candide Thank you for the answer and your help. I have a doubt. I use Mqtt hivemq First time with a tip from "XorAndOr" I have 02 boards with 8 relays in each. My app activates both cards at the same time. How can I make an ap for each different ID card? Thank you
 
Upvote 0

candide

Active Member
Licensed User
i don't use Mqtt hivernq, but it should be the same with all brokers:
- each client subscribe to a topic . (one topic for one board)
- and your app will publish to a first topic in case of command to first board or to an other topic for command to second board.

it is my understanding
 
Upvote 0
Top