{% extends "base.html" %} {% import "macros.html" as ui %} {% block title %}Device{% endblock %} {% block content %} {% if new_token %}

Token for {{ new_device.name }}

Copy it now: it is shown only once. If you lose it, rotate it to get a new one.

{{ new_token }}

Put it in the firmware's secrets.h, next to the Wi-Fi credentials:

#define MAMADACHI_SYNC_URL "{{ base_url }}/api/v1/device/sync"
#define MAMADACHI_TOKEN    "{{ new_token }}"

Or test it from your computer, pretending to be the device:

python tools/fake_device.py --url {{ base_url }} --token {{ new_token }} press 6
python tools/fake_device.py --url {{ base_url }} --token {{ new_token }} sync
{% endif %} {% for c in cards %} {% set dev = c.dev %}

{{ dev.name }}

{{ 'Active' if dev.active else 'Revoked' }}
Last sync
{% if dev.last_seen_at %}{{ f.ago(dev.last_seen_at, now) }}{% else %}never{% endif %}
Battery
{% if dev.battery_mv %}{{ c.battery_pct }}% {{ '%.2f' % (dev.battery_mv / 1000) }} V{% if dev.charging %} · charging{% endif %}{% else %}–{% endif %}
Wi-Fi signal
{% if dev.rssi is not none %}{{ c.signal }} {{ dev.rssi }} dBm{% else %}–{% endif %}
Firmware
{{ dev.firmware or '–' }}
Clock
{% if dev.clock_skew_s is none %}–{% elif dev.clock_skew_s|abs <= 120 %}in sync {{ dev.clock_skew_s }} s{% else %}off by {{ f.duration(dev.clock_skew_s|abs) }}{% endif %}
Presses received
{{ c.presses }}
Boots
{{ dev.boot_count if dev.boot_count is not none else '–' }}
Token
mmd_…{{ dev.token_hint }}

Battery, last {{ battery_days }} days

{{ ui.battery_chart(c.chart) }} {% if c.log %}

Recent syncs

{% for r in c.log %} {% endfor %}
WhenPressesBatterySignalClockServer time
{{ f.when(r.received_at) }} {{ r.events_new }}{% if r.events_received != r.events_new %} ({{ r.events_received - r.events_new }} repeat){% endif %} {{ '%.2f V' % (r.battery_mv / 1000) if r.battery_mv else '–' }} {{ r.rssi if r.rssi is not none else '–' }} {{ '%+d s' % r.clock_skew_s if r.clock_skew_s is not none else '–' }} {{ r.duration_ms if r.duration_ms is not none else '–' }} ms
{% endif %}
{% if dev.active %}
{% endif %}
{% endfor %}

{{ 'Add a device' if cards else 'Connect your Mamadachi' }}

Each device gets its own secret token. It sends it with every sync, so the server knows the presses are really from your Mamadachi.

How the device syncs

For firmware work
  1. Every press is queued on the device with a seq (a counter kept in NVS, +1 per press), the time from the RV-3028 (UNIX seconds, UTC) and the button number (1–8).
  2. When it's time to sync (every {{ profile.sync_interval_min }} min, or after a press if you like), it joins Wi-Fi and makes one HTTPS request:
POST {{ base_url }}/api/v1/device/sync
Authorization: Bearer mmd_…
Content-Type: application/json

{"device_time": 1760630400, "firmware": "0.1.0", "battery_mv": 3987,
 "charging": false, "rssi": -61, "boot_count": 42, "queue_len": 0,
 "events": [{"seq": 101, "time": 1760620000, "button": 6},
            {"seq": 102, "time": 1760627000, "button": 6}]}
  1. HTTP 200: every event sent is stored. Delete them from the queue. Anything else (no Wi-Fi, timeout, 5xx): keep them and try again later. Resending is safe: the server skips presses it already has.
  2. The response carries server_time (set the RTC if it drifted), tz_offset_s (to show local time), the buttons layout with short labels for the e-paper, and a status block: last feed, next side, ongoing sleep, today's counts.
  3. Send at most 500 events per request. If more are queued, sync again right away.

Current layout: {% for n, k in buttons.items() %}{{ n }}: {{ k.short if k else '–' }} {% endfor %}

Full field reference: API docs.

{% endblock %}