From abae3f6c29ba4030b3db71698779e227730524dc Mon Sep 17 00:00:00 2001 From: Jason Milldrum Date: Sat, 28 Nov 2026 17:48:53 +0000 Subject: [PATCH 1/8] Fix FCR macro collision with Renesas device headers (v1.4.1) The dead #define FCR (rs->fcr) in src/int.h expanded the FCR hardware register name in the RA4M1 device header (R7FA4M1AB.h) and broke compilation on the Arduino UNO R4 WiFi (and other Renesas targets). The macro was never used (the struct field is accessed directly), so it was removed. Bump version to 1.4.1 and document in the changelog. --- .gitignore | 2 ++ README.md | 8 ++++++++ library.properties | 2 +- src/int.h | 1 - 4 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1766a68 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +# WiFi credentials for the WSPR beacon example — never commit these. +arduino_secrets.h diff --git a/README.md b/README.md index 222c49e..97d46be 100644 --- a/README.md +++ b/README.md @@ -315,6 +315,14 @@ Also, a big thank you to Murray Greenman, ZL1BPU for working allowing me to pick Changelog --------- +* v1.4.1 + + * Fix FCR macro collision with Renesas RA4M1 device header (R7FA4M1AB.h): + the dead `#define FCR (rs->fcr)` in src/int.h expanded the `FCR` hardware + register name and broke compilation on the Arduino UNO R4 WiFi (and other + Renesas targets). The macro was never used (the struct field is accessed + directly), so it was removed. + * v1.4.0 * Added test harness (17 checks) covering memory-safety and output-correctness bugs diff --git a/library.properties b/library.properties index 8a9e23b..8ead7bc 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Etherkit JTEncode -version=1.4.0 +version=1.4.1 author=Jason Milldrum maintainer=Jason Milldrum sentence=Generate JT65, JT9, JT4, FT8, WSPR, and FSQ symbols on your Arduino. diff --git a/src/int.h b/src/int.h index bb18f3e..7e00148 100644 --- a/src/int.h +++ b/src/int.h @@ -18,7 +18,6 @@ typedef uint8_t data_t; #define INDEX_OF (rs->index_of) #define GENPOLY (rs->genpoly) #define NROOTS (rs->nroots) -#define FCR (rs->fcr) #define PRIM (rs->prim) #define IPRIM (rs->iprim) #define PAD (rs->pad) From b7d86a3464bc5fe931db420f13efa517e1bdf70f Mon Sep 17 00:00:00 2001 From: Jason Milldrum Date: Sat, 28 Nov 2026 17:48:58 +0000 Subject: [PATCH 2/8] Add sanitized WSPR_Beacon_UnoR4WiFi example A WSPR beacon for the Arduino Uno R4 WiFi that transmits a packet every 10 minutes on 30 m using the ESP32-S3 module for NTP time sync. The sketch is sanitized (generic callsign/grid, placeholder credentials via arduino_secrets.h.example) and compiles without credentials. --- .../WSPR_Beacon_UnoR4WiFi.ino | 413 ++++++++++++++++++ .../arduino_secrets.h.example | 7 + 2 files changed, 420 insertions(+) create mode 100644 examples/WSPR_Beacon_UnoR4WiFi/WSPR_Beacon_UnoR4WiFi.ino create mode 100644 examples/WSPR_Beacon_UnoR4WiFi/arduino_secrets.h.example diff --git a/examples/WSPR_Beacon_UnoR4WiFi/WSPR_Beacon_UnoR4WiFi.ino b/examples/WSPR_Beacon_UnoR4WiFi/WSPR_Beacon_UnoR4WiFi.ino new file mode 100644 index 0000000..b80c158 --- /dev/null +++ b/examples/WSPR_Beacon_UnoR4WiFi/WSPR_Beacon_UnoR4WiFi.ino @@ -0,0 +1,413 @@ +// ============================================================================ +// WSPR Beacon for Arduino Uno R4 WiFi +// ---------------------------------------------------------------------------- +// Sanitized example: transmits a WSPR packet every 10 minutes on 30 meters, +// using the Uno R4 WiFi's ESP32-S3 module for NTP time sync (accurate timing, +// no GPS needed). Edit the configuration block below with your own callsign, +// grid, and power level, and create "arduino_secrets.h" for WiFi credentials +// (see the note in that block). +// +// Hardware: +// - Arduino Uno R4 WiFi (Renesas RA4M1 + ESP32-S3 WiFi) +// - Si5351A clock generator (Etherkit Si5351A Breakout) wired over I2C +// - A 25 MHz crystal (or 27 MHz) on the Si5351 +// +// Libraries (install via Arduino Library Manager): +// - Etherkit Si5351Arduino (si5351.h) +// - Etherkit JTEncode (JTEncode.h) +// +// Wiring: +// Si5351 -> Uno R4 WiFi +// VIN -> 5V (or 3.3V per your Si5351 breakout) +// GND -> GND +// SDA -> A4 (Qwiic SDA) +// SCL -> A5 (Qwiic SCL) +// The Si5351 output is fed to your transmitter (e.g. via a buffer/driver). +// +// Timing: +// WSPR transmissions start 2 seconds into an even UTC minute (hh:XX:02), +// so this sketch waits until the top of the next 10-minute slot + 2 s, +// then transmits the 162-symbol packet (~110.6 s). Time comes from an +// NTP query over WiFi, re-synced every 60 s to correct drift. +// +// Credentials: +// Create a file "arduino_secrets.h" (next to this sketch) with: +// #define SECRET_SSID "your-network-ssid" +// #define SECRET_PASS "your-network-password" +// See arduino_secrets.h.example in this directory. The file is git-ignored +// by default; never commit it. +// +// Notes: +// - The 30 m WSPR dial frequency is 10.1387 MHz; the signal sits ~1.5 kHz +// above the dial, so this sketch transmits at 10.1402 MHz (the center of +// the 10.1401-10.1403 MHz Tx window). +// - WSPR Type 1 messages encode a 4-character grid locator (the first 4 +// characters of a 6-character Maidenhead grid). +// - A 10-minute interval keeps you well inside the ~20% even-minute +// etiquette for a WSPR beacon. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the Software) +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. +// ============================================================================ + +#include +#include +#include +#include "Wire.h" + +// Credentials — create "arduino_secrets.h" next to this sketch (see the +// arduino_secrets.h.example template in this directory). If the file is +// missing, placeholder credentials are used (the beacon will not connect, +// but the sketch still compiles). +#if __has_include("arduino_secrets.h") + #include "arduino_secrets.h" +#else + #warning "arduino_secrets.h not found; using placeholder credentials (see arduino_secrets.h.example)" + #define SECRET_SSID "your-ssid" + #define SECRET_PASS "your-password" +#endif + +// ---- Configuration ---------------------------------------------------------- +#define CALL_SIGN "N0CALL" // your callsign (Type 1, no slash/brackets) +#define GRID_LOCATOR "AA00" // 4-char grid; reduce your 6-char grid to its first 4 characters +#define POWER_DBM 10 // +10 dBm (valid WSPR levels: -30..+60) +#define FREQ_HZ 10140200ULL // 30 m WSPR, center of the 10.1401-10.1403 MHz window +#define TONE_SPACING 146 // ~1.46 Hz per symbol (WSPR) +#define SYMBOL_DELAY 683 // ms per symbol (WSPR) +#define TX_INTERVAL 600 // seconds between transmissions (10 minutes) +#define SYMBOL_COUNT 162 // WSPR_SYMBOL_COUNT (from JTEncode) +#define LED_PIN LED_BUILTIN + +// NTP / time sync +#define NTP_PACKET_SIZE 48 +#define NTP_PORT 123 +#define SEVENTY_YEARS 2208988800UL // seconds between 1900-01-01 and 1970-01-01 +#define TIME_REFRESH 60000UL // re-sync NTP every 60 seconds + +// ---- Objects ---------------------------------------------------------------- +Si5351 si5351; +JTEncode jtencode; + +uint8_t tx_buffer[SYMBOL_COUNT]; + +// Last good NTP sync (epoch seconds) and the millis() at that moment +unsigned long last_sync_epoch = 0; +unsigned long last_sync_millis = 0; +bool time_valid = false; +bool si5351_ok = false; + +// WiFiUDP is declared here and begun in setup() +WiFiUDP Udp; + +// ---- NTP --------------------------------------------------------------------- +// Sends an NTP request to pool.ntp.org and waits up to 5 s for a reply. +// Returns the current epoch seconds, or 0 if the query failed. +unsigned long getNTPTime() +{ + byte packet[NTP_PACKET_SIZE]; + memset(packet, 0, NTP_PACKET_SIZE); + // LI=0, version=3, mode=3 (client) + packet[0] = 0b11100011; + packet[1] = 0; // Stratum / type of clock + packet[2] = 6; // Polling interval + packet[3] = 0xEC; // Peer clock precision + packet[12] = 49; // NTP ID: 'P' + packet[13] = 0x4E; // 'N' + packet[14] = 49; // 'P' + packet[15] = 52; // 'R' + + Udp.beginPacket("pool.ntp.org", NTP_PORT); + Udp.write(packet, NTP_PACKET_SIZE); + Udp.endPacket(); + + // Wait for a reply (bounded, so a network hiccup can't hang the beacon) + unsigned long deadline = millis() + 5000UL; + while (millis() < deadline) + { + if (Udp.parsePacket()) + { + Udp.read(packet, NTP_PACKET_SIZE); + // Timestamp starts at byte 40: highWord << 16 | lowWord + unsigned long highWord = word(packet[40], packet[41]); + unsigned long lowWord = word(packet[42], packet[43]); + unsigned long secsSince1900 = highWord << 16 | lowWord; + unsigned long epoch = secsSince1900 - SEVENTY_YEARS; + if (epoch > 0) + { + return epoch; + } + } + delay(100); + } + return 0; +} + +// Re-sync the local clock from NTP. On failure, leaves the previous +// (still ticking) clock in place. +void syncTime() +{ + unsigned long t = getNTPTime(); + if (t > 0) + { + last_sync_epoch = t; + last_sync_millis = millis(); + time_valid = true; + } + else + { + time_valid = false; + } +} + +// Current time in epoch seconds (derived from the last good NTP sync). +unsigned long now() +{ + if (!time_valid) + { + return 0; + } + return last_sync_epoch + (millis() - last_sync_millis) / 1000UL; +} + +// ---- WiFi ------------------------------------------------------------------- +bool connectWiFi() +{ + Serial.print("Connecting to WiFi: "); + Serial.println(SECRET_SSID); + + if (WiFi.status() == WL_NO_MODULE) + { + Serial.println("WiFi module not detected!"); + return false; + } + + WiFi.begin(SECRET_SSID, SECRET_PASS); + + unsigned long start = millis(); + while (WiFi.status() != WL_CONNECTED && (millis() - start) < 60000UL) + { + delay(500); + } + + if (WiFi.status() == WL_CONNECTED) + { + Serial.print("Connected, IP: "); + Serial.println(WiFi.localIP()); + Serial.print("Signal strength: "); + Serial.print(WiFi.RSSI()); + Serial.println(" dBm"); + return true; + } + + Serial.println("WiFi connection failed"); + return false; +} + +// ---- Time formatting --------------------------------------------------------- +// Prints "HH:MM:SS" (UTC) for an epoch time. +void printTime(unsigned long epoch) +{ + if (epoch == 0) + { + Serial.print("--:--:--"); + return; + } + unsigned long hh = (epoch % 86400UL) / 3600UL; + unsigned long mm = (epoch % 3600UL) / 60UL; + unsigned long ss = epoch % 60UL; + if (hh < 10) Serial.print('0'); + Serial.print(hh); + Serial.print(':'); + if (mm < 10) Serial.print('0'); + Serial.print(mm); + Serial.print(':'); + if (ss < 10) Serial.print('0'); + Serial.print(ss); +} + +// ---- Transmission ----------------------------------------------------------- +void transmit() +{ + Serial.print("Transmitting WSPR at "); + printTime(now()); + Serial.print(" ("); + Serial.print(FREQ_HZ / 1000000.0, 6); + Serial.println(" MHz)"); + + digitalWrite(LED_PIN, HIGH); + si5351.output_enable(SI5351_CLK0, 1); + + for (uint8_t i = 0; i < SYMBOL_COUNT; i++) + { + si5351.set_freq((uint64_t)FREQ_HZ * 100ULL + (uint64_t)tx_buffer[i] * TONE_SPACING, SI5351_CLK0); + delay(SYMBOL_DELAY); + } + + si5351.output_enable(SI5351_CLK0, 0); + digitalWrite(LED_PIN, LOW); + + Serial.print("Done. Packet took "); + Serial.print((SYMBOL_COUNT * SYMBOL_DELAY) / 1000.0, 1); + Serial.println(" s"); +} + +// ---- Setup ------------------------------------------------------------------ +void setup() +{ + Serial.begin(115200); + unsigned long start = millis(); + while (!Serial && (millis() - start) < 5000UL) + { + delay(100); + } + + Serial.println(); + Serial.println("=== WSPR Beacon for Uno R4 WiFi ==="); + Serial.println("Callsign: " CALL_SIGN); + Serial.println("Grid: " GRID_LOCATOR); + Serial.print("Power: +"); + Serial.print(POWER_DBM); + Serial.println(" dBm"); + Serial.print("Freq: "); + Serial.print(FREQ_HZ / 1000000.0, 6); + Serial.println(" MHz (30 m)"); + Serial.print("Interval: "); + Serial.print(TX_INTERVAL / 60); + Serial.println(" minutes"); + + pinMode(LED_PIN, OUTPUT); + digitalWrite(LED_PIN, LOW); + + // Initialize the Si5351 (25 MHz reference crystal, no frequency correction) + si5351_ok = si5351.init(SI5351_CRYSTAL_LOAD_8PF, 0, 0); + if (!si5351_ok) + { + Serial.println("WARNING: Si5351 not found on the I2C bus!"); + Serial.println("Check the Si5351 wiring (SDA/SCL) and that the Si5351 is powered."); + } + else + { + si5351.drive_strength(SI5351_CLK0, SI5351_DRIVE_8MA); + si5351.output_enable(SI5351_CLK0, 0); + Serial.println("Si5351 initialized."); + } + + // Encode the WSPR message once (it is fixed for this beacon) + jtencode.wspr_encode(CALL_SIGN, GRID_LOCATOR, POWER_DBM, tx_buffer); + Serial.println("WSPR message encoded."); + + // Begin the UDP socket (once) for the NTP queries + Udp.begin(2390); + + // Connect to WiFi (retried in loop() if it drops) + connectWiFi(); +} + +// ---- Loop ------------------------------------------------------------------- +void loop() +{ + // 0. Ensure the Si5351 is available (retry init every 60 s) + if (!si5351_ok) + { + static unsigned long last_retry = 0; + if (millis() - last_retry >= 60000UL) + { + last_retry = millis(); + si5351_ok = si5351.init(SI5351_CRYSTAL_LOAD_8PF, 0, 0); + if (si5351_ok) + { + si5351.drive_strength(SI5351_CLK0, SI5351_DRIVE_8MA); + si5351.output_enable(SI5351_CLK0, 0); + Serial.println("Si5351 initialized on retry."); + } + } + } + + // 1. Ensure WiFi is connected + if (WiFi.status() != WL_CONNECTED) + { + if (!connectWiFi()) + { + Serial.println("Retrying in 30 s..."); + delay(30000); + return; + } + } + + // 2. Sync the clock (and keep it fresh in the wait loop) + syncTime(); + if (!time_valid) + { + Serial.println("NTP time sync failed; retrying in 30 s..."); + delay(30000); + return; + } + + // 3. Compute the next 10-minute slot and the transmit instant + // (2 seconds into the even minute, per the WSPR spec) + unsigned long next_slot = (last_sync_epoch / TX_INTERVAL + 1) * TX_INTERVAL; + unsigned long next_transmit = next_slot + 2; + + Serial.print("Next WSPR slot: "); + printTime(next_transmit); + Serial.print(" UTC (in "); + unsigned long wait = next_transmit - now(); + if (wait > 3600) + { + Serial.print(wait / 60); + Serial.print(" min"); + } + else + { + Serial.print(wait); + Serial.print(" s"); + } + Serial.println(")"); + + // 4. Wait for the slot, re-syncing time every TIME_REFRESH ms + for (;;) + { + if (now() >= next_transmit) + { + break; + } + if (millis() - last_sync_millis >= TIME_REFRESH) + { + syncTime(); + } + if (WiFi.status() != WL_CONNECTED) + { + // WiFi dropped: reconnect, re-sync, and recompute the slot + connectWiFi(); + syncTime(); + if (!time_valid) + { + Serial.println("Time sync lost; retrying in 30 s..."); + delay(30000); + return; + } + next_slot = (last_sync_epoch / TX_INTERVAL + 1) * TX_INTERVAL; + next_transmit = next_slot + 2; + continue; + } + delay(100); + } + + // 5. Transmit the packet + transmit(); +} diff --git a/examples/WSPR_Beacon_UnoR4WiFi/arduino_secrets.h.example b/examples/WSPR_Beacon_UnoR4WiFi/arduino_secrets.h.example new file mode 100644 index 0000000..c743d16 --- /dev/null +++ b/examples/WSPR_Beacon_UnoR4WiFi/arduino_secrets.h.example @@ -0,0 +1,7 @@ +// WiFi credentials for the WSPR Beacon example. +// +// Copy this file to "arduino_secrets.h" (next to the sketch) and edit the +// two defines below with your real network credentials. The real file is +// git-ignored and must never be committed. +#define SECRET_SSID "your-network-ssid" +#define SECRET_PASS "your-network-password" From 490445cbf7e757996e0018070d824ca187f47b2a Mon Sep 17 00:00:00 2001 From: Jason Milldrum Date: Sat, 28 Nov 2026 18:09:29 +0000 Subject: [PATCH 3/8] Clarify WiFi signal strength readout The connectWiFi() status line printed 'Signal strength: ', which could be confused with the WSPR message power level. It now prints 'WiFi signal strength: ' to distinguish the two. --- examples/WSPR_Beacon_UnoR4WiFi/WSPR_Beacon_UnoR4WiFi.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/WSPR_Beacon_UnoR4WiFi/WSPR_Beacon_UnoR4WiFi.ino b/examples/WSPR_Beacon_UnoR4WiFi/WSPR_Beacon_UnoR4WiFi.ino index b80c158..d782896 100644 --- a/examples/WSPR_Beacon_UnoR4WiFi/WSPR_Beacon_UnoR4WiFi.ino +++ b/examples/WSPR_Beacon_UnoR4WiFi/WSPR_Beacon_UnoR4WiFi.ino @@ -208,7 +208,7 @@ bool connectWiFi() { Serial.print("Connected, IP: "); Serial.println(WiFi.localIP()); - Serial.print("Signal strength: "); + Serial.print("WiFi signal strength: "); Serial.print(WiFi.RSSI()); Serial.println(" dBm"); return true; From 0ae1c128d395ec6153931f38e3fa783ac81572fd Mon Sep 17 00:00:00 2001 From: Jason Milldrum Date: Sat, 28 Nov 2026 18:26:53 +0000 Subject: [PATCH 4/8] Pick a random frequency in the WSPR window per transmit Each transmit now picks a random frequency inside the 30 m WSPR Tx window (10.1401-10.1403 MHz, 200 Hz wide), per the WSPR spec's 'choose a transmission frequency somewhere in the 200 Hz-wide standard WSPR bands'. Uses the Uno R4 WiFi's hardware TRNG via random() (do NOT seed it with randomSeed(), which would disable the TRNG). --- .../WSPR_Beacon_UnoR4WiFi.ino | 47 +++++++++++++++---- 1 file changed, 38 insertions(+), 9 deletions(-) diff --git a/examples/WSPR_Beacon_UnoR4WiFi/WSPR_Beacon_UnoR4WiFi.ino b/examples/WSPR_Beacon_UnoR4WiFi/WSPR_Beacon_UnoR4WiFi.ino index d782896..2048a9c 100644 --- a/examples/WSPR_Beacon_UnoR4WiFi/WSPR_Beacon_UnoR4WiFi.ino +++ b/examples/WSPR_Beacon_UnoR4WiFi/WSPR_Beacon_UnoR4WiFi.ino @@ -38,9 +38,11 @@ // by default; never commit it. // // Notes: -// - The 30 m WSPR dial frequency is 10.1387 MHz; the signal sits ~1.5 kHz -// above the dial, so this sketch transmits at 10.1402 MHz (the center of -// the 10.1401-10.1403 MHz Tx window). +// - The 30 m WSPR dial frequency is 10.1387 MHz; the 200 Hz Tx window is +// 10.1401-10.1403 MHz (~1.4 kHz above the dial). Each transmit picks a +// random frequency inside that window (via the Uno R4 WiFi's hardware +// TRNG), per the WSPR spec's "choose a transmission frequency somewhere +// in the 200 Hz-wide standard WSPR bands". // - WSPR Type 1 messages encode a 4-character grid locator (the first 4 // characters of a 6-character Maidenhead grid). // - A 10-minute interval keeps you well inside the ~20% even-minute @@ -86,7 +88,11 @@ #define CALL_SIGN "N0CALL" // your callsign (Type 1, no slash/brackets) #define GRID_LOCATOR "AA00" // 4-char grid; reduce your 6-char grid to its first 4 characters #define POWER_DBM 10 // +10 dBm (valid WSPR levels: -30..+60) -#define FREQ_HZ 10140200ULL // 30 m WSPR, center of the 10.1401-10.1403 MHz window +// 30 m WSPR Tx window: 10.140100-10.140300 MHz (200 Hz wide, per the WSPR +// spec — a beacon picks a transmission frequency inside this window). +// Each transmit picks a random frequency in the window. +#define WSPR_WINDOW_MIN_HZ 10140100L +#define WSPR_WINDOW_MAX_HZ 10140300L #define TONE_SPACING 146 // ~1.46 Hz per symbol (WSPR) #define SYMBOL_DELAY 683 // ms per symbol (WSPR) #define TX_INTERVAL 600 // seconds between transmissions (10 minutes) @@ -114,6 +120,25 @@ bool si5351_ok = false; // WiFiUDP is declared here and begun in setup() WiFiUDP Udp; +// Frequency used for this transmit (picked randomly per transmit) +long tx_freq = (WSPR_WINDOW_MIN_HZ + WSPR_WINDOW_MAX_HZ) / 2; + +// Pick a random frequency inside the 30 m WSPR window (10.1401-10.1403 MHz). +// The Uno R4 WiFi's core implements random() with the hardware TRNG +// (SCE_TRNG_SUPPORT), so each call returns a genuinely random value — do NOT +// seed it with randomSeed(), which would disable the TRNG and fall back to a +// weak PRNG. random() can return -1 if the TRNG init fails, so fall back to +// the center of the window in that case. +void pickTxFrequency() +{ + long f = random(WSPR_WINDOW_MIN_HZ, WSPR_WINDOW_MAX_HZ + 1L); + if (f < WSPR_WINDOW_MIN_HZ || f > WSPR_WINDOW_MAX_HZ) + { + f = (WSPR_WINDOW_MIN_HZ + WSPR_WINDOW_MAX_HZ) / 2; + } + tx_freq = f; +} + // ---- NTP --------------------------------------------------------------------- // Sends an NTP request to pool.ntp.org and waits up to 5 s for a reply. // Returns the current epoch seconds, or 0 if the query failed. @@ -243,10 +268,12 @@ void printTime(unsigned long epoch) // ---- Transmission ----------------------------------------------------------- void transmit() { + pickTxFrequency(); + Serial.print("Transmitting WSPR at "); printTime(now()); Serial.print(" ("); - Serial.print(FREQ_HZ / 1000000.0, 6); + Serial.print(tx_freq / 1000000.0, 6); Serial.println(" MHz)"); digitalWrite(LED_PIN, HIGH); @@ -254,7 +281,7 @@ void transmit() for (uint8_t i = 0; i < SYMBOL_COUNT; i++) { - si5351.set_freq((uint64_t)FREQ_HZ * 100ULL + (uint64_t)tx_buffer[i] * TONE_SPACING, SI5351_CLK0); + si5351.set_freq((uint64_t)tx_freq * 100ULL + (uint64_t)tx_buffer[i] * TONE_SPACING, SI5351_CLK0); delay(SYMBOL_DELAY); } @@ -283,9 +310,11 @@ void setup() Serial.print("Power: +"); Serial.print(POWER_DBM); Serial.println(" dBm"); - Serial.print("Freq: "); - Serial.print(FREQ_HZ / 1000000.0, 6); - Serial.println(" MHz (30 m)"); + Serial.print("Window: "); + Serial.print(WSPR_WINDOW_MIN_HZ / 1000000.0, 6); + Serial.print("-"); + Serial.print(WSPR_WINDOW_MAX_HZ / 1000000.0, 6); + Serial.println(" MHz (30 m, random per transmit)"); Serial.print("Interval: "); Serial.print(TX_INTERVAL / 60); Serial.println(" minutes"); From b17aac4cbda3e06f7ee60f98a166e87980c86cda Mon Sep 17 00:00:00 2001 From: Jason Milldrum Date: Sat, 28 Nov 2026 18:29:45 +0000 Subject: [PATCH 5/8] Start transmits 1 second into the even minute, per the WSPR spec WSPR transmissions start at hh:XX:01 (1 second after the start of each even UTC minute), not hh:XX:02. Update both the transmit instant and the comments. --- .../WSPR_Beacon_UnoR4WiFi/WSPR_Beacon_UnoR4WiFi.ino | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/WSPR_Beacon_UnoR4WiFi/WSPR_Beacon_UnoR4WiFi.ino b/examples/WSPR_Beacon_UnoR4WiFi/WSPR_Beacon_UnoR4WiFi.ino index 2048a9c..dbfd4a0 100644 --- a/examples/WSPR_Beacon_UnoR4WiFi/WSPR_Beacon_UnoR4WiFi.ino +++ b/examples/WSPR_Beacon_UnoR4WiFi/WSPR_Beacon_UnoR4WiFi.ino @@ -25,8 +25,8 @@ // The Si5351 output is fed to your transmitter (e.g. via a buffer/driver). // // Timing: -// WSPR transmissions start 2 seconds into an even UTC minute (hh:XX:02), -// so this sketch waits until the top of the next 10-minute slot + 2 s, +// WSPR transmissions start 1 second into an even UTC minute (hh:XX:01), +// so this sketch waits until the top of the next 10-minute slot + 1 s, // then transmits the 162-symbol packet (~110.6 s). Time comes from an // NTP query over WiFi, re-synced every 60 s to correct drift. // @@ -388,9 +388,9 @@ void loop() } // 3. Compute the next 10-minute slot and the transmit instant - // (2 seconds into the even minute, per the WSPR spec) + // (1 second into the even minute, per the WSPR spec) unsigned long next_slot = (last_sync_epoch / TX_INTERVAL + 1) * TX_INTERVAL; - unsigned long next_transmit = next_slot + 2; + unsigned long next_transmit = next_slot + 1; Serial.print("Next WSPR slot: "); printTime(next_transmit); @@ -431,7 +431,7 @@ void loop() return; } next_slot = (last_sync_epoch / TX_INTERVAL + 1) * TX_INTERVAL; - next_transmit = next_slot + 2; + next_transmit = next_slot + 1; continue; } delay(100); From 538bf7a487d5b8fcdeb7366f5c5335f5f465aa9c Mon Sep 17 00:00:00 2001 From: Jason Milldrum Date: Sat, 28 Nov 2026 19:28:14 +0000 Subject: [PATCH 6/8] Add build-matrix CI: verify the library builds on AVR, ATSAMD, ESP32, ESP8266, Renesas Adds a hardware-independent smoke sketch (tests/build-smoke) that exercises every encode path, and a build-matrix workflow that compiles it against the repo library (not an installed copy) for each core. The verbose-log guard fails the job if the repo library is not what was compiled, catching arduino-cli's silent fallback to an installed copy. --- .github/workflows/build-matrix.yml | 64 ++++++++++++++++++++++++++++++ tests/build-smoke/build-smoke.ino | 35 ++++++++++++++++ 2 files changed, 99 insertions(+) create mode 100644 .github/workflows/build-matrix.yml create mode 100644 tests/build-smoke/build-smoke.ino diff --git a/.github/workflows/build-matrix.yml b/.github/workflows/build-matrix.yml new file mode 100644 index 0000000..e5851a7 --- /dev/null +++ b/.github/workflows/build-matrix.yml @@ -0,0 +1,64 @@ +name: Build matrix + +# Verifies that the library builds and links on the major Arduino +# architectures. Uses a hardware-independent smoke sketch (tests/build-smoke) +# that exercises every encode path, built against the repo library (not an +# installed copy) so PRs are validated against their exact content. + +on: + push: + branches: [master, main] + pull_request: + +jobs: + build: + name: ${{ matrix.name }} + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + include: + - name: AVR (Arduino UNO) + fqbn: arduino:avr:uno + core: arduino:avr + - name: ATSAMD (MKR 1000) + fqbn: arduino:samd:mkr1000 + core: arduino:samd + - name: ESP32 (Dev Module) + fqbn: esp32:esp32:esp32 + core: esp32:esp32 + - name: ESP8266 (NodeMCU 1.0) + fqbn: esp8266:esp8266:nodemcuv2 + core: esp8266:esp8266 + - name: Renesas (UNO R4 WiFi) + fqbn: arduino:renesas_uno:unor4wifi + core: arduino:renesas_uno + + steps: + - uses: actions/checkout@v4 + + - name: Set up arduino-cli + uses: arduino/setup-arduino-cli@v2 + with: + version: "1.x" + + - name: Add ESP8266 board manager URL + if: matrix.core == 'esp8266:esp8266' + run: arduino-cli config add board_manager.additional_urls https://arduino.esp8266.com/stable/package_esp8266com_index.json + + - name: Install core ${{ matrix.core }} + run: arduino-cli core install ${{ matrix.core }} + + - name: Compile smoke sketch against the repo library + run: | + set -o pipefail + arduino-cli compile --fqbn ${{ matrix.fqbn }} --library "$GITHUB_WORKSPACE" --verbose tests/build-smoke 2>&1 | tee build.log + + - name: Verify the repo library (not an installed copy) is used + run: | + # arduino-cli silently falls back to an installed copy if the library + # is not found — fail loudly instead. The verbose log's compile + # commands must reference the repo's own sources. + grep -q "src/JTEncode.cpp" build.log + grep -q "src/crc14.c" build.log + grep -q "src/nhash.c" build.log diff --git a/tests/build-smoke/build-smoke.ino b/tests/build-smoke/build-smoke.ino new file mode 100644 index 0000000..f02dddb --- /dev/null +++ b/tests/build-smoke/build-smoke.ino @@ -0,0 +1,35 @@ +/* + * JTEncode build smoke test — no hardware required. + * + * Exercises every encode path so the library is compiled and linked + * against whatever core the sketch is built for. Used by the build-matrix + * CI workflow (.github/workflows/build-matrix.yml) to verify the library + * builds on the major Arduino architectures (AVR, ATSAMD, ESP32, ESP8266, + * Renesas). + */ +#include + +JTEncode enc; + +void setup() +{ + Serial.begin(115200); + // JT4 is the largest symbol buffer (207) + uint8_t symbols[JT4_SYMBOL_COUNT]; + + enc.jt65_encode("NT7S", symbols); + enc.jt9_encode("NT7S", symbols); + enc.jt4_encode("NT7S", symbols); + enc.ft8_encode("NT7S", symbols); + enc.wspr_encode("NT7S", "CN84", 10, symbols); + enc.fsq_encode("NT7S", "HELLO", symbols); + enc.fsq_dir_encode("NT7S", "CN84", ' ', "TEST", symbols); + + char grid[7]; + enc.latlon_to_grid(44.5, -122.5, grid); + + Serial.print("JTEncode built OK; symbols[0]="); + Serial.println(symbols[0]); +} + +void loop() {} From 0bc0ffd914dfd5fd56f0e47a0f144fd466bcdeb1 Mon Sep 17 00:00:00 2001 From: Jason Milldrum Date: Sat, 28 Nov 2026 19:32:14 +0000 Subject: [PATCH 7/8] Generate build smoke sketch in CI instead of committing it The arduino-lint library-spec rule (LD003) requires sketches to live in examples/ or extras/, so the committed tests/build-smoke sketch failed lint. The workflow now generates the sketch via a heredoc at build time (untracked), keeping the library spec valid while still compiling the repo library against AVR, ATSAMD, ESP32, ESP8266 and Renesas. --- .github/workflows/build-matrix.yml | 44 +++++++++++++++++++++++++++--- tests/build-smoke/build-smoke.ino | 35 ------------------------ 2 files changed, 40 insertions(+), 39 deletions(-) delete mode 100644 tests/build-smoke/build-smoke.ino diff --git a/.github/workflows/build-matrix.yml b/.github/workflows/build-matrix.yml index e5851a7..4fb60c0 100644 --- a/.github/workflows/build-matrix.yml +++ b/.github/workflows/build-matrix.yml @@ -1,9 +1,10 @@ name: Build matrix # Verifies that the library builds and links on the major Arduino -# architectures. Uses a hardware-independent smoke sketch (tests/build-smoke) -# that exercises every encode path, built against the repo library (not an -# installed copy) so PRs are validated against their exact content. +# architectures. A hardware-independent smoke sketch is generated at build +# time (kept out of the repo so the library spec stays valid) and exercises +# every encode path, built against the repo library (not an installed copy) +# so PRs are validated against their exact content. on: push: @@ -49,10 +50,45 @@ jobs: - name: Install core ${{ matrix.core }} run: arduino-cli core install ${{ matrix.core }} + - name: Generate build smoke sketch + run: | + mkdir -p build-smoke + cat > build-smoke/build-smoke.ino <<'SKELETON' + /* JTEncode build smoke test — no hardware required. + Exercises every encode path so the library is compiled and + linked against whatever core the sketch is built for. */ + #include + + JTEncode enc; + + void setup() + { + Serial.begin(115200); + // JT4 is the largest symbol buffer (207) + uint8_t symbols[JT4_SYMBOL_COUNT]; + + enc.jt65_encode("NT7S", symbols); + enc.jt9_encode("NT7S", symbols); + enc.jt4_encode("NT7S", symbols); + enc.ft8_encode("NT7S", symbols); + enc.wspr_encode("NT7S", "CN84", 10, symbols); + enc.fsq_encode("NT7S", "HELLO", symbols); + enc.fsq_dir_encode("NT7S", "CN84", ' ', "TEST", symbols); + + char grid[7]; + enc.latlon_to_grid(44.5, -122.5, grid); + + Serial.print("JTEncode built OK; symbols[0]="); + Serial.println(symbols[0]); + } + + void loop() {} + SKELETON + - name: Compile smoke sketch against the repo library run: | set -o pipefail - arduino-cli compile --fqbn ${{ matrix.fqbn }} --library "$GITHUB_WORKSPACE" --verbose tests/build-smoke 2>&1 | tee build.log + arduino-cli compile --fqbn ${{ matrix.fqbn }} --library "$GITHUB_WORKSPACE" --verbose build-smoke 2>&1 | tee build.log - name: Verify the repo library (not an installed copy) is used run: | diff --git a/tests/build-smoke/build-smoke.ino b/tests/build-smoke/build-smoke.ino deleted file mode 100644 index f02dddb..0000000 --- a/tests/build-smoke/build-smoke.ino +++ /dev/null @@ -1,35 +0,0 @@ -/* - * JTEncode build smoke test — no hardware required. - * - * Exercises every encode path so the library is compiled and linked - * against whatever core the sketch is built for. Used by the build-matrix - * CI workflow (.github/workflows/build-matrix.yml) to verify the library - * builds on the major Arduino architectures (AVR, ATSAMD, ESP32, ESP8266, - * Renesas). - */ -#include - -JTEncode enc; - -void setup() -{ - Serial.begin(115200); - // JT4 is the largest symbol buffer (207) - uint8_t symbols[JT4_SYMBOL_COUNT]; - - enc.jt65_encode("NT7S", symbols); - enc.jt9_encode("NT7S", symbols); - enc.jt4_encode("NT7S", symbols); - enc.ft8_encode("NT7S", symbols); - enc.wspr_encode("NT7S", "CN84", 10, symbols); - enc.fsq_encode("NT7S", "HELLO", symbols); - enc.fsq_dir_encode("NT7S", "CN84", ' ', "TEST", symbols); - - char grid[7]; - enc.latlon_to_grid(44.5, -122.5, grid); - - Serial.print("JTEncode built OK; symbols[0]="); - Serial.println(symbols[0]); -} - -void loop() {} From 3739ed3640aac6e08c1fb9df988fb18e2f690df0 Mon Sep 17 00:00:00 2001 From: Jason Milldrum Date: Sat, 28 Nov 2026 19:38:15 +0000 Subject: [PATCH 8/8] Document the example sketch and build-matrix CI in the v1.4.1 changelog --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.md b/README.md index 97d46be..a22a3e9 100644 --- a/README.md +++ b/README.md @@ -322,6 +322,15 @@ Changelog register name and broke compilation on the Arduino UNO R4 WiFi (and other Renesas targets). The macro was never used (the struct field is accessed directly), so it was removed. + * Add a sanitized `WSPR_Beacon_UnoR4WiFi` example: a WSPR beacon for the + Uno R4 WiFi that transmits every 10 minutes on 30 m. Each transmission + picks a random frequency inside the 200 Hz WSPR window (10.1401-10.1403 MHz) + via the hardware TRNG, starts 1 second into the even UTC minute, and syncs + time over WiFi/NTP. Credentials come from a gitignored `arduino_secrets.h` + (never committed). + * Add a build-matrix CI workflow that compiles a hardware-independent smoke + sketch against the repo library on AVR, ATSAMD, ESP32, ESP8266 and Renesas, + verifying the library builds and links on the major Arduino architectures. * v1.4.0