Skip to content
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

ENF: RSSI 0 dBm #1655

Closed
transistortim opened this issue Jan 30, 2022 · 2 comments · Fixed by #1656
Closed

ENF: RSSI 0 dBm #1655

transistortim opened this issue Jan 30, 2022 · 2 comments · Fixed by #1656

Comments

@transistortim
Copy link
Contributor

Hey,

I'm using microG included in CCTG. On 2022-01-27 in the evening, I upgraded CCTG to 2.14.1.2, which according to the info screen uses microG version 18214816000.
As can be seen in the plot below, after the update there are many encounters with an RSSI of 0 dBm in exposure.db. In the days before the upgrade everything seems fine.

Looking at recent changes to the ENF code, I stumbled upon 110157d and marked durations of 0 as x and durations unequal 0 as o. The plot indicates only encounters with a duration of 0 are stored with a valid RSSI.
2022-01-30 exposuredb

Device: Motorola Moto G7 Play (channel) with stock Android 10 (Google Play services are installed)

Can anybody reproduce this? Python code to create the plot:

import datetime

import matplotlib.pyplot as plt
import matplotlib.dates as md
from matplotlib.lines import Line2D
import sqlite3


file_name = "2022-01-30 exposure.db"

plt.figure()
plt.ylabel("RSSI / dBm")
ax=plt.gca()
xfmt = md.DateFormatter("%Y-%m-%d %H:%M:%S")
ax.xaxis.set_major_formatter(xfmt)
plt.grid()

with sqlite3.connect(file_name) as db_conn:
    data = db_conn.execute("SELECT timestamp, rssi, duration FROM advertisements ORDER BY timestamp;")
    for entry in data:
        x = datetime.datetime.fromtimestamp(int(entry[0]/1000))
        y = entry[1]
        if entry[2] == 0:
            plt.plot(x, y, marker="x")
        else:
            plt.plot(x, y, marker="o")

legend_elements = [Line2D([], [], linestyle="None", color="k", marker="x", label="duration == 0"),
                   Line2D([], [], linestyle="None", color="k", marker="o", label="duration $\\neq$ 0",)]
ax.legend(handles=legend_elements)
plt.show()
@transistortim
Copy link
Contributor Author

In my opinion the error is caused by the introduction of MIN in 110157d.
We have rssi = (a + r*b)/c.
c is MAX(duration, t-timestamp).
If t < timestamp (“timestamps in database are newer than reported system time”) => t-timestamp < duration. So MAX correctly yields duration as fallback.
b is MIN(0, t-timestamp-duration).
As t-timestamp < duration (see above), t-timestamp-duration evaluates to a negative number, which is smaller than 0 and hence yielded by MIN. This causes r*b to have a different sign then a and may finally lead to 0 in the numerator.
Using MAX instead would yield 0 and discard the new rssi reading r, which corresponds to the intention of "ignoring new measurements of the same RPI when they are seemingly older than a previous measurement".

So MIN should be changed to MAX.

transistortim added a commit to transistortim/GmsCore that referenced this issue Jan 31, 2022
Correctly discard new measurements when the reported timestamp is older
than the timestamp in the database.
Fixes microg#1655.
@mar-v-in
Copy link
Member

mar-v-in commented Feb 1, 2022

Thanks for looking into this. Your assessment is 100% correct. This unfortunately leads to wrong risk calculations (see https://codeberg.org/corona-contact-tracing-germany/cwa-android/issues/223#issuecomment-364044). I'll prepare and push an update today.

@mar-v-in mar-v-in added this to the 0.2.24 milestone Feb 1, 2022
mar-v-in pushed a commit that referenced this issue Feb 1, 2022
Correctly discard new measurements when the reported timestamp is older
than the timestamp in the database.
Fixes #1655.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants