Server Devices
Language
- Elixir.
Runtime Context
- Server context and Ash resource layer.
Purpose
- Manages device registration, listing, approval, remote-access flags, pending command queueing, command delivery, command acknowledgement, command payload retrieval, and SSH terminal process support.
Key Files
packages/server/lib/nixstasis/devices.expackages/server/lib/nixstasis/devices/device.expackages/server/lib/nixstasis/devices/pending_command.expackages/server/lib/nixstasis/devices/schema_validator.expackages/server/lib/nixstasis/devices/ssh_key_manager.expackages/server/lib/nixstasis/devices/ssh_client.expackages/server/lib/nixstasis_web/controllers/device_controller.expackages/server/lib/nixstasis_web/controllers/heartbeat_controller.expackages/server/lib/nixstasis_web/controllers/device_command_controller.expackages/server/lib/nixstasis_web/live/device_live/index.expackages/server/lib/nixstasis_web/live/device_live/show.ex
Public Interfaces
- Context functions:
Nixstasis.Devices.count_all/0Nixstasis.Devices.count_by_status/1Nixstasis.Devices.count_pending_approvals/0Nixstasis.Devices.register_device/1Nixstasis.Devices.update_last_seen/1Nixstasis.Devices.list_pending_devices/0Nixstasis.Devices.approve_device/1Nixstasis.Devices.list_devices/1Nixstasis.Devices.requesting_remote_access?/1Nixstasis.Devices.approve_devices/1Nixstasis.Devices.reject_devices/1Nixstasis.Devices.set_remote_access/2Nixstasis.Devices.get_device!/1Nixstasis.Devices.create_device/1Nixstasis.Devices.update_device/2Nixstasis.Devices.delete_device/1Nixstasis.Devices.change_device/2Nixstasis.Devices.queue_command/2Nixstasis.Devices.pop_pending_commands/1Nixstasis.Devices.acknowledge_command_results/2Nixstasis.Devices.get_command_payload/2Nixstasis.Devices.online?/1
- GenServer/process interfaces:
Nixstasis.Devices.SshClient.start_link/1Nixstasis.Devices.SshClient.send_data/2Nixstasis.Devices.SshClient.ssh_host/1
Dependencies
Internal
Nixstasis.DomainNixstasis.RepoNixstasis.Devices.DeviceNixstasis.Devices.PendingCommandNixstasis.Devices.SchemaValidator
External
- Ash
- AshPhoenix
- Ecto/PostgreSQL
- Elixir Port for
ssh ncatthrough SSHProxyCommand
Client-Server Interaction Details
POST /api/v1/devices/registercallsDevices.register_device/1.POST /api/v1/devices/:device_id/heartbeatcallsMonitoring.heartbeat/2, which updates last seen and returns pending commands.POST /api/v1/devices/:device_id/command_resultscallsDevices.acknowledge_command_results/2.GET /api/v1/devices/:device_id/command_payloads/:refcallsDevices.get_command_payload/2.- Device detail LiveView queues
ssh_authorizecommands before terminal session startup. - Device detail is reached through
/devices/:id; opening remote-access tabs may setremote_access_requested, and close/cleanup paths must clear stale remote access intent. - PCP metrics, Cockpit links, and terminal sessions are detail-view concerns and should degrade gracefully when FRP, SSH, or device data is unavailable.
Data Model Notes
- Device records carry stable identity and operational fields such as MAC address, product/product name, account number, approval status, schema definition, last-seen/last-polled timestamps, metadata, and remote-access intent.
- Telemetry and schema data intentionally remain dynamic JSON structures so product-specific Stary scripts can evolve without one relational table per product payload.
- Detailed historical product requirements live in IoT Device Monitoring and Device Detail Page; runtime API payloads live in Client-Server Interface.
Traceable references:
packages/server/lib/nixstasis/devices.ex:1-360packages/server/lib/nixstasis_web/controllers/device_controller.ex:31-65packages/server/lib/nixstasis_web/controllers/heartbeat_controller.ex:7-27packages/server/lib/nixstasis_web/controllers/device_command_controller.ex:6-39packages/server/lib/nixstasis_web/live/device_live/show.ex:57-80