From bdbd851e294339a5d9641fe49aeb78d207d4ece7 Mon Sep 17 00:00:00 2001 From: Sjef Verhoeven PE5PVB Date: Wed, 6 Sep 2023 16:54:07 +0200 Subject: [PATCH] Reduced UDP traffic on WiFi --- TEF6686_ESP32.ino | 10 ++++++---- src/rds.cpp | 24 +++++++++++++----------- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/TEF6686_ESP32.ino b/TEF6686_ESP32.ino index dfbb343..5cf7e3c 100644 --- a/TEF6686_ESP32.ino +++ b/TEF6686_ESP32.ino @@ -328,6 +328,7 @@ unsigned long rtplustickerhold; unsigned long rtticker; unsigned long rttickerhold; unsigned long tuningtimer; +unsigned long udptimer; TEF6686 radio; TFT_eSprite sprite = TFT_eSprite(&tft); @@ -2203,11 +2204,11 @@ void ShowFreq(int mode) { if (wifi) { Udp.beginPacket(remoteip, 9030); if (band == BAND_FM) { - Udp.print("from=TEF_tuner " + String(stationlistid, DEC) + ";RcvLevel=" + String(SStatus / 10) + ";bandwidth=-1;freq=" + String(frequency) + "0000"); + Udp.print("from=TEF_tuner " + String(stationlistid, DEC) + ";freq=" + String(frequency) + "0000"); } else if (band == BAND_OIRT) { - Udp.print("from=TEF_tuner " + String(stationlistid, DEC) + ";RcvLevel=" + String(SStatus / 10) + ";bandwidth=-1;freq=" + String(frequency_OIRT) + "0000"); + Udp.print("from=TEF_tuner " + String(stationlistid, DEC) + ";freq=" + String(frequency_OIRT) + "0000"); } else { - Udp.print("from=TEF_tuner " + String(stationlistid, DEC) + ";RcvLevel=" + String(SStatus / 10) + ";bandwidth=-1;freq=" + String(frequency_AM) + "000"); + Udp.print("from=TEF_tuner " + String(stationlistid, DEC) + ";freq=" + String(frequency_AM) + "000"); } Udp.endPacket(); } @@ -2274,7 +2275,8 @@ void ShowSignalLevel() { SStatusold = SStatusprint; } } - if (wifi) { + if (wifi && millis() >= udptimer + 2000) { + udptimer = millis(); Udp.beginPacket(remoteip, 9030); Udp.print("from=TEF_tuner " + String(stationlistid, DEC) + ";RcvLevel=" + String(SStatus / 10)); Udp.endPacket(); diff --git a/src/rds.cpp b/src/rds.cpp index e685b44..699a3ef 100644 --- a/src/rds.cpp +++ b/src/rds.cpp @@ -287,11 +287,11 @@ void doAF() { Udp.print(String((radio.af[af_scan].frequency - 8750) / 10, HEX)); } } - af_counterold = radio.af_counter; for (int i = 0; i < 25 - radio.af_counter; i++) Udp.print("00"); Udp.endPacket(); } + af_counterold = radio.af_counter; } } @@ -772,17 +772,19 @@ void showRadioText() { } if (wifi) { - Udp.beginPacket(remoteip, 9030); - Udp.print("from=TEF_tuner " + String(stationlistid, DEC) + ";RT1="); - char RThex[65]; - radio.rds.stationText.toCharArray(RThex, 65); - for (int i = 0; i < 64; i++) - { - if (RThex[i] < 0x10) Udp.print("0"); - if (RThex[i] == ' ') RThex[i] = '_'; - Udp.print(String(RThex[i], HEX)); + if (RTold != (radio.rds.stationText + " " + radio.rds.stationText32)) { + Udp.beginPacket(remoteip, 9030); + Udp.print("from=TEF_tuner " + String(stationlistid, DEC) + ";RT1="); + char RThex[65]; + radio.rds.stationText.toCharArray(RThex, 65); + for (int i = 0; i < 64; i++) + { + if (RThex[i] < 0x10) Udp.print("0"); + if (RThex[i] == ' ') RThex[i] = '_'; + Udp.print(String(RThex[i], HEX)); + } + Udp.endPacket(); } - Udp.endPacket(); } RTold = radio.rds.stationText + " " + radio.rds.stationText32; }