B4R Question ESP8266 - WiFi Remote Configuration -> Astream_NewData(Buffer () as byte) Fires multiple times

Cableguy

Expert
Licensed User
Longtime User
Hi guys,

I confess, Web communication is like Chinese to me. This said, I re-started fiddling with my ESP32 Dev Module, and am in the mist of changing the Responses within the above mentioned sub.
While sending very basic responses to the browser (using Astream.write) works fine, I was having trouble when adding something as simple as a checkbox in the <body> part.
What I am trying to do is to return a much more complex html response, with components such as input text fields and others. What I came to find is that the NewData event is fired multiple times (anything between 5 to 9 times) with each individual browser GET "request"... and so I was getting the same amount of web components rendered into the browser.
Is this normal behavior? I ended up working around this by setting a control variable and exiting the NewData if its value was not as expected.
This results in a single response, which renders correctly in the browser...

But.... Is this normal behavior? Am I missing something (Data wise)?
 

hatzisn

Well-Known Member
Licensed User
Longtime User
Hi guys,

I confess, Web communication is like Chinese to me. This said, I re-started fiddling with my ESP32 Dev Module, and am in the mist of changing the Responses within the above mentioned sub.
While sending very basic responses to the browser (using Astream.write) works fine, I was having trouble when adding something as simple as a checkbox in the <body> part.
What I am trying to do is to return a much more complex html response, with components such as input text fields and others. What I came to find is that the NewData event is fired multiple times (anything between 5 to 9 times) with each individual browser GET "request"... and so I was getting the same amount of web components rendered into the browser.
Is this normal behavior? I ended up working around this by setting a control variable and exiting the NewData if its value was not as expected.
This results in a single response, which renders correctly in the browser...

But.... Is this normal behavior? Am I missing something (Data wise)?

Normal behavior. If what is to be received is greater than N bytes (I am not sure but the buffer N is 256 bytes I think). There is a workaround. See in my signature, in my contributions, the B4R web app in tutorials I think - I am writing from my phone and I do not see my signature to tell you for sure if it is in the tutorials section.

Edit - On a second read of the title, you are trying to configure WiFi, so maybe although the article in my contributions is useful when you already have WiFi it is of no use to you when you are trying to configure WiFi...
 
Last edited:
Upvote 0

hatzisn

Well-Known Member
Licensed User
Longtime User
Also do not forget that a request is not just what you send but also a bunch of headers and the top header HTTP... So technically you neglect everything else before two times the bytes 13 and 10. If I were you, for a POST request, I would create a big enough array of bytes and write there the POST request I would get in the consequent times the async_NewData would fire. Then I would use byteconverter and would start looking for "Content-Length:" and when I would find it from this point of the array I would then check for the two bytes 13,10. Everything between the Asc(":") and 13 is the content length posted. Convert it to a string with byte converter and assign it to an int. Afterwards from this point of the array I would search for these 4 bytes: 13,10,13,10. When I would find them I would take the rest after the second 10 with a length of the int I assigned the before mentioned content length.

Here is a POST Request:

B4X:
POST / HTTP/1.1
Content-Type: application/json
User-Agent: PostmanRuntime/7.36.0
Accept: */*
Postman-Token: faa310ac-3047-4c29-9e4f-bae9e83092c5
Host: 127.0.0.1:51833
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
Content-Length: 84

{"action": "deleterec", "recid":"3", "appuser":"iamtheuser", "apppass":"iamthepass"}


P.S. In order to get a grip of how a GET request looks like use the program Telerik Fiddler or just log/display what is received.
 
Last edited:
Upvote 0

hatzisn

Well-Known Member
Licensed User
Longtime User
Neglect the previous for Telerik Fiddler - it is payable now... Here is how a GET request looks like. You can figure out the rest:

The request both times is http://127.0.0.1:51833?ssid=myssid&pass=webpass


From postman:

B4X:
GET /?ssid=myssid&pass=webpass HTTP/1.1
User-Agent: PostmanRuntime/7.36.0
Accept: */*
Postman-Token: 979aec6b-0a3a-4cb3-84e1-9c9cc447612f
Host: 127.0.0.1:51833
Accept-Encoding: gzip, deflate, br
Connection: keep-alive


From Chrome (you can see why it fires 5 to 9 times the async_NewData) :

B4X:
GET /?ssid=myssid&pass=webpass HTTP/1.1
Host: 127.0.0.1:51833
Connection: keep-alive
sec-ch-ua: "Not_A Brand";v="8", "Chromium";v="120", "Google Chrome";v="120"
sec-ch-ua-mobile: ?0
sec-ch-ua-platform: "Windows"
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7
Sec-Fetch-Site: none
Sec-Fetch-Mode: navigate
Sec-Fetch-User: ?1
Sec-Fetch-Dest: document
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9,el;q=0.8
 
Last edited:
Upvote 0

hatzisn

Well-Known Member
Licensed User
Longtime User
You can still download telerik fiddler for free (go to "Try it for free" and select Fiddler Classic) :

It will get you here:

Make the request from browser, select it, go to inspectors in the tabs and select raw in the upper tabs that appear.
 
Upvote 0

candide

Active Member
Licensed User
possible rAWOT can help you... with AWOT you can create a real serveur in esp.

several examples are provided with library, or in project below:
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
possible rAWOT can help you... with AWOT you can create a real serveur in esp.

several examples are provided with library, or in project below:
Seems to be exactly what I need.
I will test it tonight and get back to this
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
Hi @candide,

I just tried the examples in the links you referred to me.
It's way to complex for the simple task I am trying to achieve.
I understand this is an (almost?) full featured webserver solution, but I don't really need that complexity.
 
Upvote 0
Top