Closed prawnz closed 2 years ago
Hi there,
you can find the color configuration in the ./examples/FanshimService.c
on line 117 (color_temp_lo_rgb
= cold) and 124 (color_temp_hi_rgb
= hot). Just change the numbers in front of the / 255
and re-compile the project.
The first number is the "red"-portion, the second one the "green"-portion and the third one the "blue"-portion (with ranges from 0..255). Different color picker tools are available online.
Best regards
do I have to recompile once this is done?
Yes, you have to recompile the project after you make changes. I'm probably going to add some kind of configuration file or make the service configurable by command-line arguments ... maybe ... 😛
I'd have to agree that it is not clear how to use this program.
I've used the following command... gcc FanshimService.c
...and got the following output. FanshimService.c:30:10: fatal error: RaspiAPA102/APA102.h: No such file or directory
^~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
Google is saying something about apt-get python-mote (I guess for the LED) but it still does not work. Would appreciate the help is solving this.
Hi there, all the commands you need are written down in the readme: https://github.com/flobernd/raspi-fanshim#build
You probably forgot the --recursive
when cloning the repository.
Hi flobernd,
Firstly thanks for replying.
My .bash_history has the following.
sudo systemctl disable pimoroni-fanshim sudo systemctl stop pimoroni-fanshim sudo apt install wiringpi git clone --recursive 'https://github.com/flobernd/raspi-fanshim.git' cd raspi-fanshim mkdir build && cd build; cmake ..; make sudo make install
I can't find the RaspiAPA102/APA102.h or the RaspiAPA102/ColorConversion.h dependency. Any google returns me to this projects github page.
This is as close as I could find. https://github.com/chafos/apa102 I may remove the functions for the Led to see if it compiles then.
Hi there, sorry for late reply. I just did a quick test and it definitely works for me:
username@RASPBERRY:~ $ git clone --recursive 'https://github.com/flobernd/raspi-fanshim.git'
Cloning into 'raspi-fanshim'...
remote: Enumerating objects: 33, done.
remote: Counting objects: 100% (33/33), done.
remote: Compressing objects: 100% (14/14), done.
remote: Total 33 (delta 9), reused 33 (delta 9), pack-reused 0
Unpacking objects: 100% (33/33), done.
Submodule 'dependencies/raspi-apa102' (https://github.com/flobernd/raspi-apa102.git) registered for path 'dependencies/raspi-apa102'
Cloning into '/home/username/raspi-fanshim/dependencies/raspi-apa102'...
remote: Enumerating objects: 47, done.
remote: Counting objects: 100% (47/47), done.
remote: Compressing objects: 100% (24/24), done.
remote: Total 47 (delta 19), reused 39 (delta 13), pack-reused 0
Submodule path 'dependencies/raspi-apa102': checked out '67946aab668c03a9eee917d66ee98287d12bff6f'
username@RASPBERRY:~ $ cd raspi-fanshim
username@RASPBERRY:~/raspi-fanshim $ mkdir build && cd build
username@RASPBERRY:~/raspi-fanshim/build $ cmake ..
-- The C compiler identification is GNU 8.3.0
-- The CXX compiler identification is GNU 8.3.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Performing Test COMPILER_HAS_HIDDEN_VISIBILITY
-- Performing Test COMPILER_HAS_HIDDEN_VISIBILITY - Success
-- Performing Test COMPILER_HAS_HIDDEN_INLINE_VISIBILITY
-- Performing Test COMPILER_HAS_HIDDEN_INLINE_VISIBILITY - Success
-- Performing Test COMPILER_HAS_DEPRECATED_ATTR
-- Performing Test COMPILER_HAS_DEPRECATED_ATTR - Success
-- Configuring done
-- Generating done
-- Build files have been written to: /home/username/raspi-fanshim/build
username@RASPBERRY:~/raspi-fanshim/build $ make
Scanning dependencies of target RaspiAPA102
[ 20%] Building C object dependencies/raspi-apa102/CMakeFiles/RaspiAPA102.dir/src/APA102.c.o
[ 40%] Building C object dependencies/raspi-apa102/CMakeFiles/RaspiAPA102.dir/src/ColorConversion.c.o
[ 60%] Linking C static library libRaspiAPA102.a
[ 60%] Built target RaspiAPA102
Scanning dependencies of target RaspiFanshim
[ 80%] Building C object CMakeFiles/RaspiFanshim.dir/src/Fanshim.c.o
[100%] Linking C static library libRaspiFanshim.a
[100%] Built target RaspiFanshim
username@RASPBERRY:~/raspi-fanshim/build $
Could you maybe start from scratch (delete the directory and execute the commands again) and paste me the complete log?
This is where I've need able to get up to. How do I run the code?
pi@retropie:~ $ rm -rf raspi-fanshim pi@retropie:~ $ git clone --recursive 'https://github.com/flobernd/raspi-fanshim.git' Cloning into 'raspi-fanshim'... remote: Enumerating objects: 33, done. remote: Counting objects: 100% (33/33), done. remote: Compressing objects: 100% (14/14), done. remote: Total 33 (delta 9), reused 33 (delta 9), pack-reused 0 Unpacking objects: 100% (33/33), done. Submodule 'dependencies/raspi-apa102' (https://github.com/flobernd/raspi-apa102.git) registered for path 'dependencies/raspi-apa102' Cloning into '/home/pi/raspi-fanshim/dependencies/raspi-apa102'... remote: Enumerating objects: 47, done. remote: Counting objects: 100% (47/47), done. remote: Compressing objects: 100% (24/24), done. remote: Total 47 (delta 19), reused 39 (delta 13), pack-reused 0 Submodule path 'dependencies/raspi-apa102': checked out '67946aab668c03a9eee917d66ee98287d12bff6f' pi@retropie:~ $ cd raspi-fanshim pi@retropie:~/raspi-fanshim $ mkdir build && cd build pi@retropie:~/raspi-fanshim/build $ cmake .. -- The C compiler identification is GNU 8.3.0 -- The CXX compiler identification is GNU 8.3.0 -- Check for working C compiler: /usr/bin/cc -- Check for working C compiler: /usr/bin/cc -- works -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Detecting C compile features -- Detecting C compile features - done -- Check for working CXX compiler: /usr/bin/c++ -- Check for working CXX compiler: /usr/bin/c++ -- works -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Detecting CXX compile features -- Detecting CXX compile features - done -- Performing Test COMPILER_HAS_HIDDEN_VISIBILITY -- Performing Test COMPILER_HAS_HIDDEN_VISIBILITY - Success -- Performing Test COMPILER_HAS_HIDDEN_INLINE_VISIBILITY -- Performing Test COMPILER_HAS_HIDDEN_INLINE_VISIBILITY - Success -- Performing Test COMPILER_HAS_DEPRECATED_ATTR -- Performing Test COMPILER_HAS_DEPRECATED_ATTR - Success -- Configuring done -- Generating done -- Build files have been written to: /home/pi/raspi-fanshim/build pi@retropie:~/raspi-fanshim/build $ make Scanning dependencies of target RaspiAPA102 [ 20%] Building C object dependencies/raspi-apa102/CMakeFiles/RaspiAPA102.dir/src/APA102.c.o [ 40%] Building C object dependencies/raspi-apa102/CMakeFiles/RaspiAPA102.dir/src/ColorConversion.c.o [ 60%] Linking C static library libRaspiAPA102.a [ 60%] Built target RaspiAPA102 Scanning dependencies of target RaspiFanshim [ 80%] Building C object CMakeFiles/RaspiFanshim.dir/src/Fanshim.c.o [100%] Linking C static library libRaspiFanshim.a [100%] Built target RaspiFanshim
Do I compile and run the program like this?
`cd ~/raspi-fanshim/examples
gcc FanshimService.c
FanshimService.c:30:10: fatal error: RaspiAPA102/APA102.h: No such file or directory
^~~~~~~~~~~~~~~~~~~~~~
compilation terminated. `
(This is where I am getting error from and where more direction is needed)
Ah now I see what's your problem. This project is a library for other developers in the first place, so the example is not built automatically.
You can build it like this:
sudo apt install cmake-curses-gui
cd ~/raspi-fanshim/build
ccmake ..
Then set the RASPI_FANSHIM_BUILD_EXAMPLES
option to ON
, press c
then g
. When done execute once again:
cmake ..
make
and run the compiled program using:
cd examples
./FanshimService
I will add this to the documentation as it seems most people only come for the service replacement 😄
Thank you, I was able to work out the other steps.
cmake didn't compile the c program for me but sudo make install did, also I didn't have to cd to the example folder. A file called FanshimService appeared in the build folder. Running this turned on the green led and stopped the fan spinning.
I will run something on my pi to see if the fan come on. :)
Thank you for the further instructions but now i need more help with the service 🙈
I successfully compiled the FanshimService
example and it seems to run fine when i run ./FanshimService
.
But i couldn't figure out how to run it as a systemd service.
My systemd service runs fine, but it seems like FanshimService
is not running because the fan doesn't stop.
Maybe someone could help me out with this 😁
I created a unit-file in /etc/systemd/system/c-fanshim.service
with the following
[Unit]
Description=Fan Shim Service (in C)
After=multi-user.target
[Service]
Type=simple
WorkingDirectory=/home/pi/coding/raspi-fanshim/build
ExecStart=/home/pi/coding/raspi-fanshim/build/FanshimService
Restart=on-failure
[Install]
WantedBy=multi-user.target
$ sudo systemctl daemon-reload
to make the unit-file visible
$ sudo systemctl enable c-fanshim.service
to enable the service for auto-start on boot
$ sudo systemctl start c-fanshim.service
to start the service
When i run $ systemctl status c-fanshim.service
, the service seems to run fine:
🟢 c-fanshim.service - Fan Shim Service (in C)
Loaded: loaded (/etc/systemd/system/c-fanshim.service; enabled; vendor preset: enabled)
Active: active (running) since Sat 2021-10-23 19:27:57 CEST; 13min ago
Main PID: 788 (FanshimService)
Tasks: 1 (limit: 4915)
CGroup: /system.slice/c-fanshim.service
└─788 /home/pi/coding/raspi-fanshim/build/FanshimService
Okt 23 19:27:57 raspberrypi systemd[1]: Started Fan Shim Service (in C).
The fan is constantly running, even though the c-fanshim.service
seems to be fine.
But when i manually run the executable ./FanshimService
the fan goes off and the LED goes on.
@Blackwidow-sudo Sadly, I currently don't have a Pi with the Fan Shim module available for testing.
You could add basic log message printing to the FanshimService to see if everything initializes correctly when run as a system service.
What catches my eye: Your service binary is under your home directory (and probably not chowned by root). Could be worth a try to move it and set the owner/group to root (or whatever user/group combination your systemd uses).
@flobernd thank you for your suggestions. Sadly im even more confused now🤣 I did some testing and my results make no sense.
first i added some code to log FanshimService.c
from inside main(void)
:
// FanshimService.c
// ...
int main(void)
{
FILE *logFile = fopen("/home/pi/coding/raspi-fanshim/fanshim-log.txt", "w");
if (logFile == NULL) return 1;
time_t curtime;
time(&curtime);
fprintf(logFile, "%s : Main Function running.\n", ctime(&curtime));
// ...
// Variable assignment and Init-stuff
// ...
fprintf(logFile, "%s : Going into while loop.\n", ctime(&curtime));
fclose(logFile);
while(true)
{
// ...
// program loop
// ...
}
return 0;
}
$ chown root:root FanshimService
(mode is -rwxr-xr-x
)$ sudo cp FanshimService /usr/bin/
/etc/systemd/system/c-fanshim.service
:
[Unit]
Description=Fan Shim Service (in C)
After=multi-user.target
[Service] Type=simple WorkingDirectory=/usr/bin ExecStart=/usr/bin/FanshimService Restart=on-failure
[Install] WantedBy=multi-user.target
- and finally i started the service again:
`$ sudo systemctl daemon-reload`
`$ sudo systemctl enable c-fanshim.service`
`$ sudo systemctl restart c-fanshim.service`
### Results
- `$ systemctl status c-fanshim.service` is fine (running)
- `htop` shows the process running
- `/home/pi/coding/raspi-fanshim/fanshim-log.txt` gets written
**BUT**
The fan wont stop 🤯
(btw i restarted the system after all my modifications)
So i would assume there is a problem with the program logic, but i dont think so because when i manually run `./FanshimService` the fan immediatly stops. Very weird behavior...i dont get it.
Maybe it's worth to log the return values of the FanshimIsFanEnabled and GrtCPUTemperature functions inside the loop.
Did you test changing the owner/group and moving the binary to a non home directory?
What happens if you start the binary as root btw? Does that work?
I kept this simple by putting the following before exit 0 using sudo nano /etc/rc.local
su - pi -c 'cd /home/pi/coding/raspi-fanshim/build; ./FanshimService &' &
Then save.
For the system service method I used the full path.
WorkingDirectory =/home/pi/coding/raspi-fanshim/build ExecStart=/home/pi/coding/raspi-fanshim/build/FanshimServic
I've got it compiled however need more instructions on how to get the commands to work. I want to change the color from green to blue to better reflect cool to hot colors.