fireindark707

fireindark707

I’m currently working on a project with Nerves(Nerves Livebook) on a Raspberry Pi Zero, and I’ve encountered a recurring issue where the device spontaneously shuts down. To better understand what’s happening behind the scenes and potentially pinpoint the cause, I’m looking to dive into the system-level logs.

Could anyone guide me on how to access these logs within the Nerves environment? Specifically, I’m interested in any logs that could shed light on system events or errors that might precede these unexpected shutdowns.

Showing Posts 4 to 1

fireindark707

fireindark707 OP

Thanks @fhunleth , I have figured out the problem. It relates to a problem of Kino. I have report the issue:

https://github.com/livebook-dev/kino/issues/416

fhunleth

fhunleth

Co-author of Nerves

I think the first thing to try is to just disable heart altogether. To do this, edit your project’s rel/vm.args.eex and comment out the -heart line:

## Enable heartbeat monitoring of the Erlang runtime system
#-heart -env HEART_BEAT_TIMEOUT 30

I really hope that gives you time to look at log, inspect your device or do whatever to see why Erlang isn’t telling heart that it’s ok, and therefore not petting the hardware watchdog.

As for changing the hardware watchdog timer, it’s already set to the longest time. If you trace through bcm2835_wdt.c, the max time looks like it’s just under 16 seconds and that due to truncation, it shows up as 15 seconds when asked.

Best bet is to comment out heart like above. I don’t know how 30 seconds could be too short on the heart timeout, but you could also update that.

Hope you find the issue.

fireindark707

fireindark707 OP

Hello @fhunleth, Thanks for your responses. I think they are really important. I have tried RingLogger but until now no error has been logged. I’m thinking the problem lies in the heart, here is my heart status after running pi zero for 24 hours:

%{
program_version: %Version{major: 2, minor: 3, patch: 0},
wdt_timeout: 15,
wdt_time_left: 11,
wdt_pre_timeout: 0,
wdt_pet_time_left: 3,
wdt_options: [:settimeout, :magicclose, :keepaliveping],
wdt_last_boot: :power_on,
wdt_identity: “Broadcom BCM2835 Watchdog timer”,
wdt_firmware_version: 0,
snooze_time_left: 0,
program_name: “nerves_heart”,
init_handshake_timeout: 0,
init_handshake_time_left: 0,
init_handshake_happened: true,
init_grace_time_left: 0,
heartbeat_timeout: 30,
heartbeat_time_left: 26
}

The wdt_pet_time_left becomes very small. I think it will trigger a reboot but dont know how to extend the timeout limit or fix this problem. Could you give me more hints? I have checked GitHub - nerves-project/nerves_heart: Erlang heartbeat support for Nerves · GitHub

fhunleth

fhunleth

Co-author of Nerves

Debugging spontaneous shutdowns can be hard since the key log message might not be logged.

There are a few options:

  1. If you’re using RingLogger, turn on persistence. RingLogger will write logs every so many minutes and then on graceful shutdown. Not sure if this will help given what you posted, but seems worth a try. In your config, do something like this:
config :logger, RingLogger,
  persist_path: "/data/ring_logger.log",
  persist_seconds: 300,
  1. Use RamoopsLogger. This backend logs to a special area of DRAM that survives reboots sometimes. Add the dependency and add RamoopsLogger to your :logger :backends in the config.exs.

  2. Enable the :console logger, connect to the UART, watch messages and hope.

  3. Enable an Elixir or Erlang file logger like you would for a non-Nerves project. Configure it to log to a file in /data. There might be a sync option to force writes more frequently. I don’t personally use this option, but I know people coming from non-embedded backgrounds sometimes are really comfortable with this one.

On Nerves, log messages from the Linux kernel and from C programs using syslog are all routed through the Elixir logger. Hopefully these aren’t your issue.

Some of the hardest bugs, imho, to debug are the ones that kill heart. If this is your issue, then try running Nerves.Runtime.Heart.status to see if wdt_time_left or heartbeat_time_left count down to 0. When they hit 0, heart thinks that something is really wrong with the BEAM or something else on the device and triggers a reboot.

Hope this helps.

— All posts loaded —

Where Next? Top

Trending in Questions Top

katta
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
achenet
Hello, I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind. However, when I launch mix phx.server, I get an error...
New
bradley
I really like the adapter patterns that ecto, nebulex, waffle, etc. use and would love find something similar for a key management servic...
New
Cxx-mlr
I’m working on a small exercise involving update_in/3, and I came up with this solution: data = %{ name: "Periodic Table", category:...
New
ChrisAmelia
I’ve got trouble wrapping my head around the order in which functions are called in this snippet (from Phoenix’s authentication): toke...
New
unaware8150
Hello folks! So at work, we are seeing some situations where we have to define some “fixed” strings that are used across the codebase in...
New
dillonoconnor
Is there any way to avoid the Hologram compiler running when using iex? It seems like the front-end code could potentially be disregarded...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New
KristerV
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
georgeguimaraes
Just published claude-code-elixir, a plugin marketplace for Claude Code with Elixir support. These are the plugins I’ve been using for my...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews