Yocto Light

From csn
Jump to navigation Jump to search

Install the GPG key of our server with the following command:

wget -q -O - https://www.yoctopuce.com/apt/KEY.gpg | gpg --dearmor  | sudo tee -a /usr/share/keyrings/yoctopuce.gpg > /dev/null

Add the repo:

echo "deb [signed-by=/usr/share/keyrings/yoctopuce.gpg] https://www.yoctopuce.com/ apt/stable/" | sudo tee /etc/apt/sources.list.d/yoctopuce.list

Install the VirtualHub

Thanks to this repository, it is possible to install the VirtualHub more easily. Indeed you just need execute the following commands:

sudo apt-get update
sudo apt-get install virtualhub

Install the command line library

sudo apt-get update
sudo apt-get install yoctolib-cmdlines

Test

You can now test the module with:

sudo YLightSensor any get_currentValue

Ok, so lets package that up into a bash script:

sudo touch /usr/bin/light_level
sudo chmod 777 /usr/bin/light_level
sudo vim /usr/bin/light_level
#!/bin/bash

# Execute the command and capture the output
output=$(sudo YLightSensor any get_currentValue)

# Extract the whole number using awk
whole_number=$(awk -F' ' '{print int($NF)}' <<< "$output")

# Print the whole number
echo "$whole_number"