How to Set the Clock Drift Rate for Satellite Retries on the ESP32-C6
When a Hubble device communicates with a satellite, it sends a burst of repeated transmissions when the board’s clock says the satellite is overhead. Every device’s clock runs a little fast or slow, so a device that has gone days without a time sync can accidentally start its burst early or late and miss the satellite. In this guide, you’ll learn how to set the clock drift rate for satellite retries on the ESP32-C6-DevKitC-1 and measure how and when retries occur.
Why the Drift Rate Matters
A satellite is overhead for only a few minutes, so the Hubble Device SDK transmits every satellite packet several times to maximize successful reception. The reliability mode in hubble_sat_packet_send() sets how many times a packet is sent and how frequently. For example, HUBBLE_SAT_RELIABILITY_NORMAL, the production default, sends each packet 8 times every 20 seconds, while HUBBLE_SAT_RELIABILITY_HIGH sends each packet 16 times every 10 seconds.
To ensure the burst starts when the satellite is actually overhead, the SDK relies on the current time, which it calculates using the initial time set with hubble_init() or hubble_time_set() and the onboard clock. Every clock runs slightly fast or slow, so every Hubble device needs regular time syncs to give the SDK accurate time. If a device doesn’t sync time for a week or more, it can mistime a satellite pass and miss it entirely.
The SDK guards against this possibility with extra transmissions. Specifically, it estimates how far the clock has drifted since the last sync and adds one transmission for every full retry interval of drift. To make that estimate, it needs to know how fast the clock drifts, which you set with CONFIG_HUBBLE_SAT_NETWORK_DEVICE_TDR, which defines the time drift rate (TDR) in parts per million (PPM).
TDR is a key factor in how well your device communicates with Hubble satellites. If you set it too low, the satellite will miss your packet bursts. However, if you set the TDR too high, your device will waste power transmitting many unnecessary packets.
Calculating the Drift Rate
To calculate the number of retries, the Hubble SDK scales the time since the last sync by the TDR, then divides the result by the retry interval and rounds down.
drift_ms = elapsed_ms_since_sync x TDR_ppm / 1,000,000
extra_retries = drift_ms / retry_interval_msFor HUBBLE_SAT_RELIABILITY_HIGH, where the retry interval is 10 seconds, the formula gives these results.
| TDR | Unsynced time before the first extra retry | Extra retries per send after one day unsynced |
|---|---|---|
| 10 PPM | 11.6 days | 0 |
| 5,000 PPM | 33 minutes | 43 |
Finding the TDR for the ESP32-C6
The TDR is the drift rate of whatever oscillator keeps the SDK’s time. On the ESP32-C6, that oscillator is the board’s 40 MHz crystal. The SDK measures elapsed time with the FreeRTOS tick, the tick comes from the systimer, and the systimer runs from the crystal by default, as the ESP32-C6 clock tree shows. Espressif’s schematic checklist requires a crystal rated at ±10 PPM. For a board that stays awake, set the TDR to 10, which is the table’s first row and the SDK’s default. If your board will be in sleep mode often, it will use the internal RC oscillator to keep time, and therefore needs a higher TDR. In this guide, you’ll test low and high TDR to simulate how your ESP32-C6 connects to Hubble Satellite when using the onboard crystal and the internal RC oscillator.
Modifying the Firmware
Before you begin, make sure you have ESP-IDF v6.1 or later installed on your PC. ESP-IDF v6.1 ships the satellite radio support the SDK needs, though you can use an older version if you follow Hubble SDK’s ESP-IDF integration guide.
Clone the Hubble Device SDK onto your PC and register a device key with AES-256-CTR encryption and the DEVICE UPTIME counter source on the Hubble dashboard. This guide works in the SDK’s samples/esp-idf/sat-continuous project, so open that folder as your project and set the target chip to esp32c6.
Open the project’s configuration menu, which is idf.py menuconfig from a terminal or the SDK Configuration Editor in the VS Code extension. Set the following four values as indicated and save.
| Search for | Setting | Value |
|---|---|---|
HUBBLE_DEVICE_KEY | Cryptography key in base64 | Your device key |
HUBBLE_SAT_NETWORK_DEVICE_TDR | Device time drift retry rate in PPM | 10 |
HUBBLE_SAT_NETWORK_PACKET_SENT_CB | Satellite packet sent callback | Checked |
LOG_MAXIMUM_LEVEL | Maximum log verbosity | Debug |
Next, edit main/main.c. Add the callback at file scope, above app_main(). The SDK declares it in hubble/sat.h and leaves the definition to you.
// Replace with the current Unix time in milliseconds
#define SYNC_UNIX_TIME_MS 1762387200000ULL
// The SDK calls this after each transmission succeeds. tx_count is the
// number of transmissions it planned for this send, so it already includes
// any retries the drift estimate added.
void hubble_sat_packet_sent_cb(const struct hubble_sat_packet *packet,
const struct hubble_sat_packet_frames *frames,
uint8_t tx_index, uint8_t tx_count)
{
// The SDK holds its transmission lock while this runs, so keep it to
// one log line. Anything slow here delays the next retry.
// The tick count is the same clock the SDK measures drift with.
uint32_t uptime_s = xTaskGetTickCount() / configTICK_RATE_HZ;
ESP_LOGI(APP_TAG, "tx %u of %u at uptime %lu s", (unsigned)tx_index + 1U,
(unsigned)tx_count, (unsigned long)uptime_s);
}Then insert this block inside app_main(), right after the hubble_init() call succeeds.
// Switch on debug lines for the SDK's log tag only, so its drift
// estimate prints before every send without flooding the console.
esp_log_level_set("hubblenetwork", ESP_LOG_DEBUG);
// Mark this moment as the last time sync. The SDK measures drift from
// here. Without this call hubble_time_get() returns 0, and the estimate
// stays at zero forever no matter what TDR you configure.
err = hubble_time_set(SYNC_UNIX_TIME_MS);
if (err != 0) {
ESP_LOGE(APP_TAG, "Failed to set Unix time, error: %d", err);
return;
}In the main loop, change HUBBLE_SAT_RELIABILITY_NONE to HUBBLE_SAT_RELIABILITY_HIGH, which gives the SDK a 10-second retry interval to add drift retries to. Then change SAT_TX_SLEEP_MS at the top of the file to 300000 so the board waits 5 minutes between sends.
Plug your ESP32-C6 board into your PC with the UART USB-C port. Then build, flash, and open the monitor from a terminal or with the VS Code extension’s Build, Flash and Monitor action.
After flashing, you should quickly see the bootloader’s startup lines scrolling in the monitor.
Measuring the Extra Retry
Each send prints the SDK’s estimate followed by one line per transmission. The SDK computes the estimate twice per send, so the two drift lines appear twice and always agree. At the send near 15 minutes of uptime, with the TDR at 10 PPM, you should see this in the serial monitor:

The drift line shows the arithmetic. The board has run about 916,000 ms, and 916,000 x 10 / 1,000,000 is 9 ms, far short of the 10,000 ms threshold for a retry. The tx 1 of 16 line proves the SDK planned the baseline 16 transmissions.
Now set the TDR to the RC oscillator figure, which is what this board would need if it went into sleep mode regularly. Close the monitor, open the configuration menu again, change the drift rate to 5000, save, and build, flash, and monitor once more. You should see the first retry around 38 minutes in the serial monitor:

At this point, the time drift was 11,326 ms. Because it exceeded the 10,000 ms threshold, the SDK sent 17 transmissions instead of the usual 16.
Next Steps
You now know how to set the drift rate based on the board clock and see how that influences when the Hubble SDK transmits additional retries. A good TDR helps your device reach the Hubble satellites consistently, but a better solution is to synchronize board time more often. Register a production device at dash.hubble.com today to get started.
Ready to connect your devices anywhere on Earth? Get started with Hubble Network for free →