Self Check

By defining the on_self_check() function, you can specify a custom routine that is executed during a self-check, which can be triggered via the serial console.

This feature allows you to verify connections with peripheral devices even without an internet connection. It is highly effective for performing final wiring checks or assembly inspections during the manufacturing or setup process.

Function Overview

  • Purpose: To provide a standalone diagnostic routine for hardware validation.
  • Trigger: Called manually through the serial console.
  • Advantage: Works offline, making it ideal for factory testing or field maintenance.

Example Code

The following example demonstrates how to check the status of a digital input and log the result to the console.

-- This function runs when a self-check is initiated from the serial console.
function on_self_check()
  -- Check the state of digital input 1
  if io.input(1) then
    -- Log success if the input is detected
    os.log(" - self check ok");
  else
    -- Log failure if the input is not detected
    os.log(" - self check failed");
  end
end

Usage Tips

  • Offline Validation: Use this function to ensure that sensors and actuators are correctly wired before deploying the device to a network-restricted environment.
  • Detailed Logging: You can add multiple checks within this function to verify all connected components at once. Each os.log() output will be visible via the serial monitor.