-
Notifications
You must be signed in to change notification settings - Fork 7.6k
UDP based NTP Time Client example does not work on esp32 after the first time through loop() #110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I also had to comment out udp.localPort() because that function appears to not be implemented. |
A small update: It appears that if I move the WifiUDP constructor into the loop, and make a new instance every time, it works almost every time. If I call udp.stop() , I immediately get a CPU Halt. There appear to be still some issues in the udp implementation. |
thanks for the updates. I'll have a look at what might not be closing the socket and get it fixed :) |
I've been calling Udp.flush(); at the bottom of my loop. It works similarly to rerunning Udp.begin(), but seems slightly more stable. Based on the way the code is written now, that seems to be the only way to get a second packet. As far as I can see the rx_buffer delete block never gets called: int WiFiUDP::read(){
if(!rx_buffer) return -1;
int out = rx_buffer->read();
if(!rx_buffer->size()){
cbuf *b = rx_buffer;
rx_buffer = 0;
delete b;
}
return out;
} As far as I can see, the cbuf::size function isn't being used properly in the UDP server. It is assuming the size changes as data is read out, but looking at cbuf.cpp, the size shouldn't change unless you explicitly resize it. |
Thanks for noting this! Please pull the latest git and give it another go |
yeah I must have been looking at older version of cbuf while writing UDP. |
That did the trick! Thanks @me-no-dev and @tcflanag ! |
* Tasmota changes (espressif#123) * Initial S3 Support Just so we can compile and test! Some things might/will not work. SPI and UART baud detect need to be looked at. * Add S3 Toolchain * Update Esptool and add some missing adjustments * Add Dual-Core Support * Fix bootloop issue and enable DSP optimization * Run Arduino on Core1 * Rework USB selection * Update HWCDC.cpp * Update USB.cpp * Update esp32-hal-tinyusb.c * fix S3 flash image base (espressif#6208) * Added my new Unexpected Maker ESP32-S3 boards (espressif#6211) * Fixes UART_1 TX Pin setup When passing the PR to this branch, it seems that the change to this line was forgotten. * Initial SPI support and S3-Box variant * Bootloader is at 0x0000 for S3 (espressif#6215) * small adjustments for NVS and PSRAM init * WIP: Initial support for PSRAM (QSPI and OPI) * [FEATURE] Basic implementation of Arduino's I2S library (espressif#5304) Basic version of Arduino's I2S library. We currently support only 16bps + 16000 Hz sampling frequency. Other bitrates and sample rates will print warning and continue to operate, however the resulting audio quality may be poor. There will be further effort to fix these issues. * [I2S] Fix lib-builder error * Update idf_component.yml (espressif#6232) took me a while * Fixes RMT examples and adds ESP32-S3 config (espressif#6235) * WIP: Initial OPI support * Update Libs with the new lib-builder scripts * Update board menu for ESP32-S3 * fix ethernet clock runtime setting (espressif#6340) this was not possible anymore since the GPIO refactoring. This superseeds espressif/esp32-arduino-lib-builder#60 (which works only for clock on GPIO17). A PR will provided to revert this. @me-no-dev fyi The fix is done from @arendst Credits go to him! * Update IDF libs and fix missing BLE 4.2 features * Update CI scripts * script fixes * Add guard to USB examples * Disable some examples for ESP32-S3 * skip one more sketch and try again PIO * Fox SPI example and add proper esptool for PIO CI * Update ResetReason.ino * Update IDF, Add ESP-SR and RainMaker * Enable RainMaker on all chips * Enable hardware test on ESP32-S3 * Adjust build dir for tests and sketches * Update tests_build.sh * Send event also if tests fail * Add helper script for updating the core version * [Docs] Added/Updated Lib builder docs (espressif#6401) * [Docs] Added/Updated Lib builder docs * [Docs] Fixes according to the PR review * [Docs] Fixes according to the PR review * SD_MMC: add ESP32-S3 support * CmakeList + Rainmaker src files edit * remove Rainmaker * Tasmota change * Fix Unicore WDT on HTTP OTA update * Revert "ESP32-S3 SDMMC support" (#20) * Fix reboot into download from TinyUSB on ESP32-S3 Requires manual reboot back into the new firmware after flashing has finished * Fix psram crash pico d4 (espressif#110) * Fix reboot into download from TinyUSB on ESP32-S3 (espressif#111) Requires manual reboot back into the new firmware after flashing has finished Co-authored-by: me-no-dev <[email protected]> * Revert "Fix psram crash pico d4 (espressif#110)" (espressif#113) This reverts commit 56cf555. * Fix boot freeze when trying to init PSRAM on Pico D4 * revert tinyusb * hal/usb_serial_jtag_ll.h only C3, H2, S3 * Fix sd mmc * add wpa_supplicant as requirement * Update platform.txt * remove Rainmaker * Update boards.txt * Update HardwareSerial.h * Update USBCDC.cpp * Update esptool.py * Update platformio-build-esp32.py * Update platformio-build-esp32c3.py * Update platformio-build-esp32s2.py * Update platformio-build-esp32s3.py * fix merge errors * Reordering - HardwareSerial Constructor * Update platformio-build-esp32.py * Update platformio-build-esp32c3.py * Update platformio-build-esp32s2.py * Update platformio-build-esp32s3.py * Update pins_arduino.h * Update platformio-build-esp32.py * Update platformio-build-esp32c3.py * Update platformio-build-esp32s2.py * Update platformio-build-esp32s3.py Co-authored-by: me-no-dev <[email protected]> Co-authored-by: Unexpected Maker <[email protected]> Co-authored-by: Rodrigo Garcia <[email protected]> Co-authored-by: Tomáš Pilný <[email protected]> Co-authored-by: Me No Dev <[email protected]> Co-authored-by: Pedro Minatel <[email protected]> Co-authored-by: Ivan Grokhotkov <[email protected]> Co-authored-by: Jan Procházka <[email protected]> * Bugfix fs read+speed improvements (espressif#127) * Revert "Edited VFSFileImpl::read to use both read/fread (espressif#6456)" This reverts commit 7b89b39. * Added default file buffer size + function to change it by user Co-authored-by: Jan Procházka <[email protected]> Co-authored-by: me-no-dev <[email protected]> Co-authored-by: Unexpected Maker <[email protected]> Co-authored-by: Rodrigo Garcia <[email protected]> Co-authored-by: Tomáš Pilný <[email protected]> Co-authored-by: Me No Dev <[email protected]> Co-authored-by: Pedro Minatel <[email protected]> Co-authored-by: Ivan Grokhotkov <[email protected]> Co-authored-by: Jan Procházka <[email protected]>
Fix proc timeout
I have the NTP time client from https://github.com/esp8266/Arduino/blob/master/libraries/ESP8266WiFi/examples/NTPClient/NTPClient.ino working on an esp8266. I modified it slightly to run on an esp32 by changing ESP8266Wifi.h to Wifi.h A packet is only returned the first time through the loop. After that, I always get "no packet yet". I have tried increasing the delay(1000) to 10 seconds, 20 seconds, and get the same behavior. I added a debug print to the loop (this did not change the behavior) to verify that the IP lookup is working correctly each time.
modified loop:
WiFi.hostByName(ntpServerName, timeServerIP);
Serial.print("Time Server IP: "); /* added /
Serial.println(timeServerIP); / added */
Output:
WiFi connected
IP address:
10.0.0.31
Starting UDP
Time Server IP: 129.6.15.30
sending NTP packet...
packet received, length=48
Seconds since Jan 1 1900 = 3692108698
Unix time = 1483119898
The UTC time is 17:44:58
Time Server IP: 129.6.15.30
sending NTP packet...
no packet yet
Time Server IP: 129.6.15.30
sending NTP packet...
no packet yet
Time Server IP: 131.107.13.100
sending NTP packet...
no packet yet
Time Server IP: 132.163.4.103
sending NTP packet...
no packet yet
Time Server IP: 216.228.192.69
sending NTP packet...
no packet yet
Time Server IP: 216.228.192.69
sending NTP packet...
no packet yet
The text was updated successfully, but these errors were encountered: