Yocto Light
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 chmod 777 /usr/bin/light_level 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 pattern matching [[ $output =~ [0-9]+ ]] && whole_number=${BASH_REMATCH[0]} # Print the whole number echo "Light level: $whole_number"