I am using a UNO rev4 wifi ... Would someone please explain to me the meaning of this line of code:
client.readStringUntil('\r');
everything works ... it just takes a long time ... about 10 seconds... is this line expecting to receive something from the VB.net program with which it is connected?
I think that client inherits readStringUntil() from Stream. See the Stream reference
That function is going to read bytes from the client until it reads a 'carriage return' character, which is ASCII code 13 decimal. It will return everything reaad before the carriage return
[Edit started writing the above, and posted it, before I saw Bob's reply]
I guess I shoulda done this in the first place. It is not my code, I probably modified a couple things
thanks for taking a look. It takes about 10 seconds to update other than that, everything works.
Thank you both for responding... I tried sending a vbCR from the VB.net form, but it didn't make any difference and this is the only thing I can find that would seem to be able to cause any kind of delay
You could perhaps talk to the server using telnet on your PC rather than VB.net program, to see if the delay is in VB.net code. Or you could run WireShark on the PC where the VB.net code is running, capture the WiFi communication with the Uno, and then look at it to see if you can spot what's causing the delay.
I have been experimenting with this and I do not believe the delay is in the VB program... for one thing the arduino program is supposed to be updating without any input from the VB program
It does turn LED's on and off and receives the value of the analog input ... it just takes 10 seconds to do it
The arduino does nothing until it connects with the VB program... then it updates serially to the arduino IDE AND the VB.net WiFi client about every 10 sec until the VB disconnects
Let me add one more thing... this is an update to an arduino program that originally depended upon VB timer ticks to update... maybe the line is incorrect altogether because of that.
It was supposed to be updated to not depend upon the timer ticks and maybe I do not have it correct now
How could I get it to go through everything in it's while loop without any input from the VB ... AND still be able to respond to input from the VB.net program
thanks to everyone who considered this
Having looked at your code, I'm not sure how you think that should work. It seems a bit strange to me that you don't have a one to one request received / response sent.
If you add a Serial.println here:
This FireFox displaying a web page from an ESP32 web server in a pre-amp I built. The volume level display is responding to me chaning the volume using an IR remote. So there's definitely no long delays happening per update
Hahaha friend... you know way more about it than I.
As you can see, I copied this whole thing and made a few minor mods
everything works as it should ... on the arduino end and the VB end... It just takes about 10 seconds to do it, and although I am a noob at this I can't see anything else that should take that long
Is there any thing else I could use in place of
I think it would first be better to check what I said in post #7 and report back here with what you see in the serial monitor. I don't see any reason why receiving the request in that manner would cause such a delay.
Update what? Something the VB net program receives from your sketch?
I don't understand what you are trying to do, nor have I seen your VB code. So it's a bit hard for me to guess what your sketch and your VB code are supposed to do.
I'm going to be afk until tomorrow morning (it's 20:10 here ATM), so someone else may help in the meantime.
Thank you for your assistance
The arduino program is supposed to update the status of the LED's and the analog input both to the VB.net program by WiFi, and to the arduino IDE, serially. That was the only way I could tell if it was doing anything at all until I got some of the bugs worked out
I tried your suggestion and now it prints on the serial monitor "sending response" but everything else works the same
I am trying to receive ,by WiFi, the status of a couple of LEDs connected to the digital outputs on the arduino and the value of a voltage divider pot connected to an analog input... and also turn those LED's on and off.
What I am interested in is receiving those values in a manner that a VB.net program can use in variables
It all works ... it is just slow as death to update and I thought it must have something to do with that line of code
For a Stream, both readString and readStringUntil use the protected timedRead, which defaults to one second per character. As long as it makes progress within that time limit, it will continue to try.
So unless overridden, readString will always take at least one second, the time it takes to "give up" at the end. In contrast, readStringUntil will stop once it finds the given character.
'\r is a carriage return. The HTTP spec says that the lines at the beginning of a request are separated by a CRLF -- carriage return + line feed combination -- or "\r\n".
The shortest possible (typical) HTTP request starts with
GET / HTTP/1.1
14 characters before the carriage return. Could those be coming in at just under one second each to take about 10 seconds total? Possible, but not that likely with modern networks.
What is the request that you get?
It's not complicated to replace readStringUntil with your own code to visually see if/how the characters are coming in slowly.
Hey kenb4
Thank you. That is the kinda stuff i was hoping to find. I couldn’t find anything on the internet. I can’t do anything right now but i will certainly look into what you’ve said.
Thank you very much
I think what I need is some way of replacing client.readStringUntil('\r'); or rearranging things in the arduino
program
At this point, it seems to be waiting for the carriage return before it does anything else... and it is not going to get a carriage return unless I send a "request" from the VB.net program to change the state of one of the LEDs.
Even though I do not send a request to change the state of the LEDs, the analog value should update constantly ( or at least a heck of a lot faster than 10 sec )
I think I need a modification / re-arrangement that would allow the requests to be received by the arduino at random times but the analog value to be sent to the client as continuously as possible
Yes you do. Now I understand what you are trying to do.
The following line, if not commented out, would tell the browser to refresh the page every 5 seconds.
That might toggle the LED each time it refreshes, which I don't think you want to happen.
You should only send to the client in response to receiving a request.
@realolman You might benefit from taking a look at the WiFi Web Server example at the bottom of this page. Perhaps start from that and make the changes you want, rather than trying to fix your current code to make it do what you want.