README.rst
1.. zephyr:code-sample:: sensor_shell
2 :name: Sensor shell
3 :relevant-api: sensor_interface
4
5 Interact with sensors using the shell module.
6
7Overview
8********
9This is a simple shell module to get data from sensors presented in the system.
10
11Building and Running
12********************
13
14Build the sample app by choosing the target board that has sensors drivers
15enabled, for example:
16
17.. zephyr-app-commands::
18 :zephyr-app: samples/sensor/sensor_shell
19 :board: reel_board
20 :goals: build flash
21
22For boards that do not have a sensor, a simple fake sensor driver is provided and can enabled by
23adding the following overlay:
24
25.. zephyr-app-commands::
26 :zephyr-app: samples/sensor/sensor_shell
27 :board: qemu_riscv64
28 :goals: run
29 :gen-args: -DEXTRA_DTC_OVERLAY_FILE=fake_sensor.overlay
30
31Shell Module Command Help
32=========================
33
34.. code-block:: console
35
36 sensor - Sensor commands
37 Subcommands:
38 get :Get sensor data. Channel names are optional. All channels are read when
39 no channels are provided. Syntax:
40 <device_name> <channel name 0> .. <channel name N>
41 info :Get sensor info, such as vendor and model name, for all sensors.
42
43
44**get**: prints all the sensor channels data for a given sensor device name.
45Optionally, a single channel name or index can be passed to be printed out. The
46device name and channel name are autocompleted.
47
48Output example (reel_board):
49
50.. code-block:: console
51
52 uart:~$ sensor get mma8652fc@1d
53 channel idx=0 accel_x = 0.000000
54 channel idx=1 accel_y = 0.268150
55 channel idx=2 accel_z = 9.959878
56 channel idx=3 accel_xyz x = 0.000000 y = 0.268150 z = 9.959878
57
58 uart:~$ sensor get mma8652fc@1d accel_z
59 channel idx=2 accel_z = 9.959878
60
61 uart:~$ sensor get mma8652fc@1d 2
62 channel idx=2 accel_z = 9.959878
63
64.. note::
65 A valid sensor device name should be passed otherwise you will get an
66 undefined behavior like hardware exception. This happens because the shell
67 subsystem runs in supervisor mode where API callbacks are not checked before
68 being called.
69
70**info**: prints vendor, model, and friendly name information for all sensors.
71This command depends on enabling :kconfig:option:`CONFIG_SENSOR_INFO`.
72
73.. code-block:: console
74
75 uart:~$ sensor info
76 device name: apds9960@39, vendor: Avago Technologies, model: apds9960, friendly name: (null)
77 device name: mma8652fc@1d, vendor: NXP Semiconductors, model: fxos8700, friendly name: (null)
78 device name: ti_hdc@43, vendor: Texas Instruments, model: hdc, friendly name: (null)
79 device name: temp@4000c000, vendor: Nordic Semiconductor, model: nrf-temp, friendly name: (null)
80