dashPi: a self-hosted home dashboard, its sync server and phone app
The dashboard (Raspberry Pi 3.5" screen + web pages), the end-to-end encrypted sync mailbox (PHP + SQLite) and the Android companion app (Flutter), with docs, clean-install checks and screenshots made from demo data. Built mostly with an AI coding assistant; not yet reviewed line by line by a human (see README and SECURITY.md). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
fb3c01cdd7
333 changed files with 45151 additions and 0 deletions
39
app/lib/sync/kick.dart
Normal file
39
app/lib/sync/kick.dart
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
// "Sync now" to the dashboard over the home network (the dashboard's sync.kick): right after the
|
||||
// band's rows went out, the Pi pulls them, imports them, rewrites the Health summaries and pushes
|
||||
// them at once — then the app pulls again. Away from home the Pi doesn't answer and nothing changes
|
||||
// (the usual 5-minute / hourly rhythm). The message is sealed with the data key, so only a device
|
||||
// of this account can send one.
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:http/io_client.dart';
|
||||
|
||||
import 'client.dart';
|
||||
import 'crypto.dart';
|
||||
import 'store.dart';
|
||||
|
||||
/// The dashboard on the home network, e.g. http://192.168.1.50:8080: the Sync page (store meta pi_url),
|
||||
/// else the build's --dart-define=PI_URL=… (tool/publish.env); empty = no "sync now", the usual rhythm only.
|
||||
String piUrl(SyncStore store) =>
|
||||
(store.metaText('pi_url') ?? const String.fromEnvironment('PI_URL')).trim().replaceAll(RegExp(r'/+$'), '');
|
||||
const _connect = Duration(seconds: 3); // not home → give up quickly
|
||||
const _answer = Duration(minutes: 3); // the Pi 3: import + summaries ≈ 1 min
|
||||
|
||||
/// → true when the Pi sent something back (pull now).
|
||||
Future<bool> kickPi(SyncSettings s, SyncStore store, SyncCrypto crypto) async {
|
||||
final pi = piUrl(store);
|
||||
if (pi.isEmpty) return false;
|
||||
final blob = crypto.sealBatch(s.key, {'kick': DateTime.now().millisecondsSinceEpoch}, s.account);
|
||||
final client = IOClient(HttpClient()..connectionTimeout = _connect);
|
||||
try {
|
||||
final r = await client
|
||||
.post(Uri.parse('$pi/api/sync/kick'), headers: {'Content-Type': 'application/octet-stream'}, body: blob)
|
||||
.timeout(_answer);
|
||||
if (r.statusCode != 200) return false;
|
||||
return ((jsonDecode(r.body) as Map<String, dynamic>)['pushed'] ?? 0) > 0;
|
||||
} catch (_) {
|
||||
return false;
|
||||
} finally {
|
||||
client.close();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue