Webserver on ESP01 using Leonardo or Uno

I quite successfully set up my Arduino Leonardo with some sensor and ESP01 wifi module.

I run code based on this link:

where some commands are sent to Serial (Serial Monitor on Arduino IDE software) and some to Serial1 (ESP01).

i sent to ESP via this code command like:
AT+CWJAP=… with ssid and psk

and everything work ok - I have micro web server with info about sensor status but…

i don’t need to see what’s happening on Serial (monitor)
I just want to set up the connection and web server.
well I modified the code and I leave just the code with Serial1.println("…

ok it work but when I switch off all and start without PC connection via USB and opening Serial Monitor - just put power jack to arduino - the web server won’t start up, just the ESP associates with ssid…

Am I thinking and doing something wrong ? I know that I could do it just on ESP but I need also Arduino…
I’ll try on UNO R3 but I’m afraid I’m making something wrong ;(

In attachment - two codes - first longer with output also on serial monitor - it’s work when connection usb to pc is active and second shortened by me - doesn’t work at all ;\

just doesn’t work without USB active to Arduino IDE :frowning:

sensorwifi1.txt (4.48 KB)

sensorwifi2.txt (1.41 KB)

I'd try to just comment out the

   while (!dbgTerminal) { 
   ; // wait for serial port to connect. Needed for Leonardo only 

in first file. That just hangs-out the leonardo until the usb is plugged in.

I removed it.
also put this code to uno.
it works in the same way.
only when uno is plugged to pc via usb.. no other powering (jack or usb ac/dc) makes web server up. It only associates with ssid..
i need just simple web server who will display values from connected sensors.. :-\

I think you have too many dbgTerminal.doShit() intertwined in code, if that serial buffer blocks, all your execution blocks.
even dbgTerminal.begin(9600) might block if there-s no actual USB line connected.

You need to clean that up and make wrapper functions (or macros) for all dbgTerminal.doSomething() that test if debuging is enabled or not and print/open/do anything with debugging serial port only if it is enabled

I cleaned it and tried other examples from net.. other didn't work completelly.. only this but with usb connected..

it has no sense :frowning:
maybe someone have some simple code to just display "hello word" when connecting arduino via esp webserver??

all codes in internet are complicated and are with debugging :frowning: :frowning: