Skip to content
You Start with one site
Amounts in Start with one site
Control, Measurement & Energy · Course

Timestamps, Buffering and Gaps

Lesson 9 of 10 24 min read
Found this useful?

A site reports that a new compressor schedule saved energy, and the auditor opens the record. The power trace is a flat line from 02:00 to 08:00 on three nights, and on another night the readings appear one hour later than the shift log says. Nobody can tell whether the flat line was measured or was drawn by software across a hole, so the auditor rejects the whole month. The meter was correct on every one of those nights. What failed was the record: the time of each reading, the storage during a network outage, and the honesty about what was missing. This lesson shows how a gateway keeps a record that can be trusted when the link fails. #Timestamps #StoreAndForward #DataIntegrity

Learning Objectives

By the end of this lesson, you will be able to:

  1. Explain why the time of a reading must be taken at the reading and stored in UTC
  2. Calculate the drift of a clock from its crystal tolerance
  3. Size a store-and-forward buffer for a stated poll plan and outage
  4. Describe how a receiver accepts replayed records without duplicates and without overwriting newer values
  5. Recover the energy used across a gap from a counter register, and state what cannot be recovered


The cold store of this course has four energy meters (addresses 5, 6, 7 and 8) and a variable speed drive (address 10) on one RS-485 bus. A gateway polls them as Modbus client and sends the readings upward over the site’s internet connection. The meter at address 5 is on the compressor feeder, and its readings are the evidence for the energy bill and for any saving that is claimed.

The bus is a cable inside one building. The uplink is a mobile or broadband connection that the site does not control, and over a year it fails many times: for seconds, for hours, and sometimes for a whole weekend. A gateway that only passes readings on loses everything it reads during those times.

So the gateway has three more tasks. It gives every reading a time from its own clock. It stores readings while the uplink is down and sends them later. It marks each reading with a quality, so that users of the record know which values were measured.

ClockBufferMeters5 to 8Drive10RS-485Gateway DModbusuplinkRTUXPlatform(down)always therestamps and storesreceives later
The gateway between a reliable bus and an unreliable uplink

Fundamental Theory: A record that can be trusted



A reading is a value, a time and a quality

The value 24.15 kW alone says little. It becomes evidence when it has three more parts: the point it belongs to (the total active power of meter 5), the time when it was true, and a quality that says how far it can be trusted. A record with no time cannot be compared with a shift log or a tariff period. A record with no quality cannot separate a measurement from a guess.

Take the time at the reading

A system could write two different moments beside a value: the moment the gateway received the response from the meter, or the moment the platform received the message from the gateway. In normal running they differ by a second or less. During an outage they differ by hours.

stored in the gateway, uplink is downReading taken at the meter14:0014:1014:20...19:5020:00all arrive at the platform at 20:01
Time of reading against time of arrival

If the platform stamps each record at arrival, six hours of readings all carry the time 20:01. The load profile of the afternoon becomes one spike in the evening. The rule is therefore fixed: the timestamp is taken by the gateway at the moment the response arrives from the meter, and it travels with the value and is never replaced. The platform may add its own arrival time as a second field.

The nine values of one Modbus response belong to one instant, so they share one timestamp.

Clock drift and NTP

The gateway’s clock counts the cycles of a quartz crystal. A crystal is never exactly at its nominal frequency. The error is given in parts per million (ppm), and a common tolerance is 20 ppm.

Clock drift

is the error that builds up over the elapsed time . For 20 ppm over one day of :

At 1.73 s per day the error is 51.8 s after 30 days and 10.5 minutes after a year. With a poll every 10 s, the timestamps are wrong by one whole poll interval after 5.8 days.

The Network Time Protocol (NTP) corrects this. The gateway asks a time server for the time at intervals, estimates the network delay, and adjusts its clock. Over the internet this usually holds a clock within some tens of milliseconds, far better than a 10 s poll needs. Three practical points follow.

  • NTP needs the network. During an uplink outage the clock runs free, so a 72-hour outage at 20 ppm adds about 5.2 s of error.
  • After a loss of power, a gateway without a battery-backed clock starts at a default date such as 1970. Readings taken before the first time correction must be flagged, not stamped with a false date.
  • When NTP corrects a clock that was fast, the time steps backward and two readings can carry the same time. A sequence number, described below, keeps the true order.

UTC and time zones

Local time is not a safe timestamp. Where clocks change for summer, one hour of each year occurs twice and one hour does not occur at all. A site, its head office and its platform may be in three time zones.

Coordinated Universal Time (UTC) has no summer change and no zone. Store and send every timestamp in UTC, for example as a count of milliseconds since 1970-01-01 00:00:00 UTC, or as text in the ISO 8601 form 2026-03-14T02:00:00Z, where the Z means UTC. Convert to local time only on the screen, for the person who reads it.

Store and forward

Store and forward means that the gateway writes each record to its own memory first and sends it upward second. A record leaves the store only after the platform has confirmed it. When the uplink is down the store grows, and when the uplink returns the gateway sends the stored records, oldest first.

The store is finite, so it is built as a circular buffer: when it is full, the newest record replaces the oldest.

free23222120191817freefreeoldest unsentnewestsent and confirmednext write goes here
A circular buffer: the newest record replaces the oldest when full

The size follows from the poll plan.

Buffer size

is the number of records per second, is the size of one record in bytes, and is the longest outage the buffer must cover, in seconds. is the buffer size in bytes.

The outage to design for is a decision, not a calculation. A long weekend with nobody on site is about 72 hours. When an outage lasts longer than the buffer, the oldest readings are lost, and the gateway must report it.

Ordering and duplicates on replay

Replay is the sending of stored records after the uplink returns. Two things go wrong unless the design prevents them.

Duplicates. The gateway sends a record and waits for a confirmation. If the link fails after the platform received the record and before the confirmation came back, the gateway sends the record again. Nothing is lost, and some records arrive twice.

Order. A gateway may send the newest reading first, so that the screen shows the present state at once, and then send the backlog. Old records then arrive after new ones.

The answer is in the record and in the receiver. Each record carries its own timestamp and a sequence number: a counter that the gateway raises by one for every record it stores. The receiver follows two rules.

  • In the history, the key of a record is the point and its timestamp. A record whose key is already stored is the same record again, and it is ignored. A record with a new key is inserted at its own time, however late it arrives.
  • The present value of a point is replaced only by a record with a newer timestamp. An old record that arrives late goes into the history and does not touch the present value.

The sequence number has a second use. A receiver that holds numbers 101 to 104 with none missing knows that it has everything. A step from 104 to 230 proves that 125 records were lost, for example because the buffer overflowed.

The two rules above use the time in the key, and they are safe only while no two genuine records of a point share a time. After NTP steps a fast clock backward, they can. Then use the point and the sequence number as the key, and keep the timestamp for the order of the history. For this the gateway must keep its counter through a restart, in flash, so that a number is never used twice.

Quality flags

A quality flag is a small field stored with each value. This course uses three states.

FlagMeaningExample
GoodA fresh reading, received with a valid CRCThe meter answered this poll
StaleThe last known value, with no fresh reading behind itThe meter did not answer, and the gateway still holds the earlier value
SubstitutedA value that was not measured: entered by a person or calculatedAn average power derived later from the energy counter

A stale value with no flag is the most dangerous. A gateway that sends “24.15 kW” every 10 s after the meter has stopped answering produces a record that looks perfect.

A gap is shown as a gap

When no reading exists for a period, the record must say so. Software that joins the two sides of a gap with a line, or that repeats the last value, invents data.

Honest: the gap is visiblekWno data02:0008:00Filled: the last value is repeatedkW02:0008:00
The same six hours, shown honestly and filled

A visible gap keeps the trust in every other point. If a report needs a value in the gap, the value carries the substituted flag and the method is recorded.

Counters against instantaneous values

An instantaneous value, such as power or current, describes one moment. If it is not read at that moment, it is gone. A counter, such as active energy, is a running total that the meter keeps itself. If nobody reads it for six hours, it still holds the total at the next read.

Energy across a gap

and are the raw counts of the energy register before and after the gap, is the scaling in kWh per count, and , are the times of the two readings. is the average power in the gap. The keeps the result correct if a 32-bit counter passed its end and began again from zero.

The total is recovered exactly. Its distribution inside the gap is not.

Application 1: Size the buffer for a 72-hour outage



Step 1: Records and bytes per day

Click to reveal the daily volume
  1. Record size. bytes. The sequence number needs no bytes in the store: the records have a fixed size, so the gateway’s count of records written gives each record its number, and the number is added when the record is sent. ✅

  2. Values in the fast group. values every 10 s. ✅

  3. Fast records per day. One day has polls.

    The fast group gives 345,600 records per day. ✅

  4. Slow records per day. Four energy values each minute: records per day. ✅

  5. Total.

    The gateway stores 5.27 MB each day. ✅

Step 2: Storage for 72 hours and the flash size

Click to reveal the buffer size
  1. Records in the outage. 72 hours is three days: records. ✅

  2. Bytes in the outage.

    A 72-hour outage needs 15.8 MB. ✅

  3. Compare the two flash sizes. 16 MB holds hours, a margin of less than one hour. 32 MB holds 145.7 hours, which is six days. ✅

  4. Choice. 32 MB. It covers the 72 hours twice. ✅

Step 3: Flash wear

Click to reveal the wear estimate
  1. Passes through the buffer. If every record is written to the circular log, the gateway writes 5.27 MB a day into 32 MB.

    Each block is erased once in about six days. ✅

  2. Best case. With writes spread evenly and one erase for each pass, 10,000 cycles last days, about 166 years. ✅

  3. A poor case. If the software commits each record alone, the flash may rewrite a whole page and its bookkeeping for 15 bytes of data. Take a write amplification of 50 as an example: years. ✅

  4. What limits the amplification. One page of 4,096 bytes holds records, which is 67 s of readings. Collecting records in memory and writing one full page at a time keeps the amplification near 1. The price is that a loss of power can lose up to the last 67 s. ✅

Flash wear is an estimate. The endurance differs between flash types by a factor of ten or more, and the real amplification depends on the file system and on how often the software forces a write. The honest conclusion is a range, from a few years to far longer than the life of the gateway. The design decision is firm all the same: write in full pages and spread the writes over the whole buffer.

Step 4: Check the answer a second way

Click to reveal the check by rate
  1. Records per second. records per second. ✅

  2. Bytes per second. bytes per second. ✅

  3. Bytes in 72 hours. 72 hours is 259,200 s.

    The same 15.8 MB as in Step 2. The Python script below prints both. ✅

Check it at commissioning. Disconnect the uplink for one hour while the gateway polls, then reconnect. For each fast value the platform must receive 360 records for that hour (3,600 s divided by 10 s), each stamped inside the hour and not at the moment of reconnection, with sequence numbers that have no step. A count below 360 means lost records. Records stamped at the reconnection time mean that the time is taken in the wrong place.

Application 2: Recover the energy across a six-hour gap



Step 1: The two counter values

Click to reveal the counts
  1. Before the gap. and .

    The counter stood at 123,456.78 kWh. ✅

  2. After the gap. .

    The counter stood at 123,541.31 kWh. ✅

Step 2: Energy and average power in the gap

Click to reveal the energy
  1. Difference. counts. The result is positive and small, so the counter did not pass its end. ✅

  2. Energy.

    The compressor feeder used 84.53 kWh between 02:00 and 08:00. ✅

  3. Average power.

    The average power in the gap was 14.09 kW. ✅

Step 3: Test the result and state the limits

Click to reveal the test and the limits
  1. Test against the machine. At 24.15 kW, an energy of 84.53 kWh is hours of running, which is 58.3 percent of the six hours. A compressor that runs 14 hours in 24 runs 58.3 percent of the time, and its daily mean power is . The recovered value fits the machine. ✅

  2. What a repeated value would have given. If the last power reading, 24.15 kW, had been repeated through the gap, the record would show . That is 60.37 kWh too much, an error of 71 percent. ✅

  3. What cannot be recovered. The load profile inside the gap: when the compressor started and stopped, and how many times. The peak power and its time, which a demand charge (a charge on the highest power drawn in a billing period) depends on. Every power factor, voltage, current and frequency reading. ✅

  4. How to record it. Store the two energy readings as good, with their own times. Leave the power trace empty from 02:00 to 08:00. If a report needs a number for those hours, enter 14.09 kW with the substituted flag and the note “average from the energy counter”. The time 08:00 of the second reading can be trusted only if the gateway’s clock survived the loss of supply (a clock with its own battery) or NTP corrected it before that reading. If not, the reading is flagged, and the average power is uncertain by the error of the clock. ✅

  5. Check with the script. The Python script joins the same words, takes the difference modulo and prints 84.53 kWh, 14.09 kW and 3.50 h. ✅

Verify It in Python



The script calculates the buffer in two ways, the flash life, the clock drift and the energy across the gap. It then replays four stored records in the wrong order with one duplicate, using the two rules of the receiver. It saves a plot of the buffer fill and of the energy register on both sides of the gap.

buffer_and_gap.py
"""Gateway D: buffer size for an outage, clock drift, energy across a gap, replay."""
import struct
from datetime import datetime, timedelta, timezone
import numpy as np
import matplotlib.pyplot as plt
# ---------- Part 1: the poll plan and the record ----------
N_METERS = 4
FAST_VALUES = N_METERS * 9 + 4 # nine values per meter and four from the drive
FAST_PERIOD = 10.0 # s
SLOW_VALUES = N_METERS * 1 # one energy value per meter
SLOW_PERIOD = 60.0 # s
RECORD = struct.Struct(">qHIB") # time in ms (8), point (2), raw value (4), quality (1)
DAY = 86400.0
OUTAGE_H = 72.0
fast_per_day = FAST_VALUES * DAY / FAST_PERIOD
slow_per_day = SLOW_VALUES * DAY / SLOW_PERIOD
records_per_day = fast_per_day + slow_per_day
bytes_per_day = records_per_day * RECORD.size
records_outage = records_per_day * OUTAGE_H / 24.0
bytes_outage = records_outage * RECORD.size
print("Buffer for gateway D")
print(f" record size: {RECORD.size} bytes")
print(f" fast group: {fast_per_day:,.0f} records per day, "
f"energy group: {slow_per_day:,.0f} records per day")
print(f" total: {records_per_day:,.0f} records per day = {bytes_per_day:,.0f} bytes "
f"({bytes_per_day / 1e6:.2f} MB)")
print(f" {OUTAGE_H:.0f} h outage: {records_outage:,.0f} records = {bytes_outage:,.0f} bytes "
f"({bytes_outage / 1e6:.2f} MB)")
rate = FAST_VALUES / FAST_PERIOD + SLOW_VALUES / SLOW_PERIOD
print(f" check by rate: {rate:.4f} records/s x {RECORD.size} bytes = "
f"{rate * RECORD.size:.1f} bytes/s, x {OUTAGE_H * 3600:,.0f} s = "
f"{rate * RECORD.size * OUTAGE_H * 3600:,.0f} bytes")
for size_mb in (16, 32):
print(f" {size_mb} MB holds {size_mb * 1e6 / bytes_per_day * 24:.1f} h")
# ---------- Part 2: flash wear (an estimate) ----------
BUFFER = 32e6 # bytes
ENDURANCE = 10_000 # erase cycles per block, from the data sheet
PAGE = 4096 # bytes
cycles_per_day = bytes_per_day / BUFFER
print("Flash wear, 32 MB circular log")
print(f" full passes per day: {cycles_per_day:.3f}")
for amplification in (1, 50):
years = ENDURANCE / (cycles_per_day * amplification) / 365.0
print(f" write amplification {amplification:>2}: about {years:.1f} years to "
f"{ENDURANCE:,} cycles")
print(f" one {PAGE} byte page holds {PAGE // RECORD.size} records, "
f"{PAGE // RECORD.size / rate:.0f} s of readings")
# ---------- Part 3: clock drift ----------
PPM = 20e-6
print("Clock drift at 20 parts per million")
print(f" per day {PPM * DAY:.3f} s, per 30 days {PPM * DAY * 30:.1f} s, "
f"per year {PPM * DAY * 365 / 60:.1f} min")
print(f" days to drift one 10 s poll interval: {FAST_PERIOD / (PPM * DAY):.1f}")
# ---------- Part 4: energy across the gap ----------
SCALE = 0.01 # kWh per count (and kW per count for the power register)
P_RUN = 24.15 # kW when the compressor runs
t_before = datetime(2026, 3, 14, 2, 0, 0, tzinfo=timezone.utc)
t_after = datetime(2026, 3, 14, 8, 0, 0, tzinfo=timezone.utc)
words_before = (0x00BC, 0x614E)
words_after = (0x00BC, 0x8253)
def counts(words):
return (words[0] << 16) | words[1]
gap_h = (t_after - t_before).total_seconds() / 3600.0
delta = (counts(words_after) - counts(words_before)) % 2**32
energy = delta * SCALE
print("Energy across the gap")
print(f" before {t_before.isoformat()}: {counts(words_before) * SCALE:,.2f} kWh")
print(f" after {t_after.isoformat()}: {counts(words_after) * SCALE:,.2f} kWh")
print(f" gap {gap_h:.1f} h, {delta} counts = {energy:.2f} kWh")
print(f" average power {energy / gap_h:.2f} kW")
print(f" equal to {energy / P_RUN:.2f} h at {P_RUN} kW "
f"({100 * energy / P_RUN / gap_h:.1f} % of the gap)")
held = P_RUN * gap_h
print(f" last power value held for the gap: {held:.2f} kWh, "
f"{held - energy:.2f} kWh too much ({100 * (held / energy - 1):.1f} %)")
print(f" fourteen hours a day gives a daily mean of {P_RUN * 14 / 24:.2f} kW")
# ---------- Part 5: replay with a duplicate and a late record ----------
GOOD, STALE, SUBSTITUTED = 0, 1, 2
POINT = 507 # meter 5, total active power
t0 = datetime(2026, 3, 17, 11, 30, 0, tzinfo=timezone.utc)
stored = {seq: (t0 + timedelta(seconds=10 * (seq - 101)), raw)
for seq, raw in ((101, 2390), (102, 2402), (103, 2387), (104, 2415))}
arrival_order = [104, 101, 102, 102, 103] # live value first, 102 sent twice
history = {} # key: (point, time). The same key is the same record.
latest = None # (time, value) shown as the present value
duplicates = 0
print("Replay")
for seq in arrival_order:
stamp, raw = stored[seq]
packed = RECORD.pack(int(stamp.timestamp() * 1000), POINT, raw, GOOD)
ms, point, raw, quality = RECORD.unpack(packed)
key = (point, ms)
if key in history:
duplicates += 1
action = "duplicate, ignored"
else:
history[key] = (seq, raw, quality)
action = "stored"
if latest is None or ms > latest[0]:
latest = (ms, raw)
action += ", present value updated"
print(f" seq {seq} {stamp.strftime('%H:%M:%S')}Z {raw * SCALE:5.2f} kW: {action}")
shown = datetime.fromtimestamp(latest[0] / 1000, tz=timezone.utc)
print(f" history holds {len(history)} records, {duplicates} duplicate ignored")
print(f" present value {latest[1] * SCALE:.2f} kW from {shown.strftime('%H:%M:%S')}Z")
seqs = sorted(s for s, _, _ in history.values())
missing = sorted(set(range(seqs[0], seqs[-1] + 1)) - set(seqs))
print(f" sequence {seqs[0]} to {seqs[-1]}, missing: {missing if missing else 'none'}")
# ---------- Plot ----------
hours = np.linspace(0.0, 160.0, 400)
fig, ax = plt.subplots(1, 2, figsize=(10, 4))
ax[0].plot(hours, hours / 24.0 * bytes_per_day / 1e6)
for size_mb in (16, 32):
ax[0].axhline(size_mb, color="gray", linestyle="--", linewidth=0.8)
ax[0].text(2, size_mb + 0.5, f"{size_mb} MB")
ax[0].axvline(OUTAGE_H, color="black", linestyle=":", linewidth=0.8)
ax[0].set_xlabel("length of the outage (h)")
ax[0].set_ylabel("stored readings (MB)")
ax[0].set_title("Buffer fill during an outage")
t_axis = [-2, -1, 0, 6, 7, 8] # hours from 02:00 UTC
e_axis = [counts(words_before) * SCALE - 2 * 14.09, counts(words_before) * SCALE - 14.09,
counts(words_before) * SCALE, counts(words_after) * SCALE,
counts(words_after) * SCALE + 14.09, counts(words_after) * SCALE + 2 * 14.09]
ax[1].plot(t_axis[:3], e_axis[:3], "o-", color="tab:blue")
ax[1].plot(t_axis[3:], e_axis[3:], "o-", color="tab:blue")
ax[1].axvspan(0, 6, color="tab:gray", alpha=0.2)
ax[1].text(3, e_axis[2] + 10, f"gap: {energy:.2f} kWh\nprofile unknown", ha="center")
ax[1].ticklabel_format(useOffset=False, style="plain", axis="y")
ax[1].set_xlabel("hours after 02:00 UTC")
ax[1].set_ylabel("energy register (kWh)")
ax[1].set_title("The counter gives the total across the gap")
fig.tight_layout()
fig.savefig("buffer_and_gap.png", dpi=120)
print("Saved buffer_and_gap.png")

Expected output

Buffer for gateway D
record size: 15 bytes
fast group: 345,600 records per day, energy group: 5,760 records per day
total: 351,360 records per day = 5,270,400 bytes (5.27 MB)
72 h outage: 1,054,080 records = 15,811,200 bytes (15.81 MB)
check by rate: 4.0667 records/s x 15 bytes = 61.0 bytes/s, x 259,200 s = 15,811,200 bytes
16 MB holds 72.9 h
32 MB holds 145.7 h
Flash wear, 32 MB circular log
full passes per day: 0.165
write amplification 1: about 166.3 years to 10,000 cycles
write amplification 50: about 3.3 years to 10,000 cycles
one 4096 byte page holds 273 records, 67 s of readings
Clock drift at 20 parts per million
per day 1.728 s, per 30 days 51.8 s, per year 10.5 min
days to drift one 10 s poll interval: 5.8
Energy across the gap
before 2026-03-14T02:00:00+00:00: 123,456.78 kWh
after 2026-03-14T08:00:00+00:00: 123,541.31 kWh
gap 6.0 h, 8453 counts = 84.53 kWh
average power 14.09 kW
equal to 3.50 h at 24.15 kW (58.3 % of the gap)
last power value held for the gap: 144.90 kWh, 60.37 kWh too much (71.4 %)
fourteen hours a day gives a daily mean of 14.09 kW
Replay
seq 104 11:30:30Z 24.15 kW: stored, present value updated
seq 101 11:30:00Z 23.90 kW: stored
seq 102 11:30:10Z 24.02 kW: stored
seq 102 11:30:10Z 24.02 kW: duplicate, ignored
seq 103 11:30:20Z 23.87 kW: stored
history holds 4 records, 1 duplicate ignored
present value 24.15 kW from 11:30:30Z
sequence 101 to 104, missing: none
Saved buffer_and_gap.png

In the replay, record 104 arrives first and sets the present value. Records 101 to 103 arrive later and go into the history at their own times. The second copy of record 102 has the same point and time as the first, so it is ignored.

Common Mistakes



  • Stamping a reading with the time it arrived at the server. After an outage, hours of readings then carry the same minute. Take the time in the gateway when the meter answers.
  • Storing local time, or a time with no zone. Store UTC and convert only for display.
  • Repeating the last value when a device stops answering, with no flag. Mark it stale, or store nothing and show the gap.
  • Letting a replayed old record replace the present value. Compare timestamps first.
  • Sizing the buffer for the usual outage of a few minutes. Size it for the long one, and make the gateway report when the buffer overflows.

Summary



  • A reading is a value with a point, a time and a quality. The time is taken by the gateway when the reading is taken, in UTC, and it is never replaced by the arrival time.
  • A 20 ppm crystal drifts 1.73 s per day. NTP corrects it while the network is present.
  • The buffer size is the record rate times the record size times the outage: 15.8 MB for 72 hours of the cold store bus, so 32 MB was chosen.
  • On replay, a record with a known point and time is a duplicate, and only a newer timestamp may replace the present value.
  • Quality flags separate good, stale and substituted values. A gap is shown as a gap.
  • A counter survives a gap and an instantaneous value does not. The energy register gave 84.53 kWh and an average of 14.09 kW for six missing hours, but not the profile, the peak or the power factor.

Exercises



1. A low-cost gateway has a crystal with a tolerance of 50 ppm and no time correction. Find its drift per day and per week. After how many days is the clock wrong by 5 s?

Answer

, and . It reaches 5 s after days.

2. A gateway reads nine values from each of two meters every 5 s. Each record is 19 bytes, because a 4-byte sequence number is stored in it. How many hours of outage does an 8 MB buffer ( bytes) cover?

Answer

values polls per day records per day, which is bytes per day. The buffer covers days, which is 32.5 hours.

3. An energy counter (uint32, 0.01 kWh per count) reads 4,294,967,000 counts before a gap and 704 counts after it. Find the energy used in the gap.

Answer

The counter passed its end at and began again. counts, so the energy is 10.00 kWh. A plain subtraction would give a large negative number.

4. A meter reads 2,340.50 kWh at 22:15 UTC and 2,396.90 kWh at 01:45 UTC on the next day, with no readings between. The load takes 24 kW when it runs. Find the energy, the average power, and the part of the gap for which the load would run at 24 kW to use that energy.

Answer

The gap is 3.5 hours. , and . As a part of full running, percent. The real pattern of running inside the gap is not known.

5. A receiver holds no records for a point. These records then arrive in this order, each as sequence number, time and value: (120, 14:00:30, 18.2), (117, 14:00:00, 17.5), (118, 14:00:10, 17.9), (118, 14:00:10, 17.9), (119, 14:00:20, 18.0). How many records does the history hold at the end, what is the present value, and is any record missing?

Answer

Four records are stored: 117, 118, 119 and 120. The second copy of 118 has the same point and time, so it is ignored. The present value is 18.2 from 14:00:30, because none of the later arrivals has a newer timestamp. The sequence runs from 117 to 120 with no step, so nothing is missing.

References



  • D. Mills, J. Martin, J. Burbank and W. Kasch, Network Time Protocol Version 4: Protocol and Algorithms Specification, RFC 5905, Internet Engineering Task Force, 2010.
  • International Organization for Standardization, ISO 8601-1:2019, Date and time: Representations for information interchange, Part 1: Basic rules.
  • OASIS, MQTT Version 3.1.1, OASIS Standard, 2014.
  • Modbus Organization, MODBUS Application Protocol Specification V1.1b3, 2012.


© 2021-2026 SiliconWit®. All rights reserved.
Meters5 to 8Drive 10RS-485Modbus RTUGateway DClockBufferuplinkdownPlatformalways therestamps and storesreceives later
The gateway between a reliable bus and an unreliable uplink
Reading taken at the meter14:0015:0016:0017:0018:0019:0020:00stored in the gateway, uplink is downall arrive at the platform at 20:01One mark for each reading, every 10 minutes.
Time of reading against time of arrival
freefree17181920212223freeoldest unsentnewestsent and confirmed, free againnext write goes herewhen full, the next write wraps to the start
A circular buffer: the newest record replaces the oldest when full
Honest: the gap is visiblekWno data02:0008:00Filled: the last value is repeatedkWlast value repeated for 6 h02:0008:00
The same six hours, shown honestly and filled
Predict first

A gateway stores six hours of power readings while its uplink is down, then sends them all when the link returns at 20:01. The platform writes the time of arrival beside each record. What does the afternoon look like on the platform?

stamped on arrivalstamped at the reading 14:0020:0114:0020:00 nothing Same readings, same arrival at 20:01
See it: the buffer of gateway D through an outage

Stored per second
The buffer holds
Needed for this outage
Oldest readings overwritten
Replay at 50 kB/s takes
Clock drift at 20 ppm

The poll plan of Application 1: 40 values every 10 s and the 4 energy counters every 60 s, 15 bytes a record, 1 MB = 106 bytes. The uplink fails 2 hours into the picture. A full buffer overwrites its oldest record, so a long outage loses its first hours, not its last. The replay rate of 50 kB/s is an assumption of the figure; the new readings keep arriving while the backlog is sent. The clock runs free while the link is down, so its error grows at 1.73 s a day.

power: one momentenergy counter: a running total ? 02:00 to 08:00: lost 02:00123,456.7808:00123,541.31 84.53 kWh, 14.09 kW average The total is exact. The shape inside the gap is not.

Check yourself

Three questions. Each wrong choice is a mistake people really make, so read the note after you answer.

1. Gateway D keeps the 16 MB flash. During an outage it stores the fast group every 60 s instead of every 10 s, and the energy counters every 60 s as before. How long does the buffer last now?

2. Before a gap the energy registers of a meter (uint32, high word first, 0.01 kWh per count) read 0xFFFF, 0xFF00. After the gap they read 0x0000, 0x2000. How much energy was used in the gap?

3. After an outage the present power of meter 5 shows its reading of 20:00. Then a replayed record of the same point, stamped 14:10, arrives. What should the receiver do?

Watch it build: a replay the receiver can trust
arrives history present 101102103104waiting 101102102again 104101102102103 230104 → 230: 125 records lost 14:00 101 14:10 102 14:20 103 14:30 104 103, 14:20 (older) 104, 14:30
  1. Records 101 to 104, taken at 14:00 to 14:30, wait in the gateway for the uplink.
  2. A confirmation is lost, so 102 is sent again. Nothing is lost, but 102 arrives twice.
  3. Newest first: 104, then the backlog. A simple receiver lets the late 103 replace the present value.
  4. The key is the point and its time. The second 102 is ignored; each record goes in at its own time.
  5. Only a newer time replaces the present value. It stays 104, taken at 14:30.
  6. The sequence number proves completeness: a step from 104 to 230 means 125 records were lost.
Found this useful?

Discussion

    Comments show your name. Be kind, stay on the topic.