Let's consider an example that will allow you to monitor the temperature of the processor of your Server, PC or Mining farm on Linux.
Required materials:
Device adding and setting:
Setting up programs.
We will use «cURL» to send data, and we will use the «lm_sensors» package to get data about the processor temperature.
Typically, the packages "cURL" and "lm_sensors" are already preinstalled on most systems and configured to work. But if your system does not have them, then the programs are not that difficult to install.
sudo yum install lm_sensors curl
sudo apt-get install lm-sensors curl
When the installation is complete, we need to perform a setup to identify all the sensors connected to the system. To do:
> sudo sensors-detect
The sensors-detect utility tries to find all installed hardware and load the recommended kernel modules for it. In most cases, you will only need to press the Enter button in response to all program questions, thereby giving the default answers.
The setting is complete and now you can go to view the available temperature. To do this:
> sudo sensors
In response, you will receive something like this:
coretemp-isa-0000 Adapter: ISA adapter Physical id 0: +29.0°C (high = +80.0°C, crit = +100.0°C) Core 0: +23.0°C (high = +80.0°C, crit = +100.0°C) Core 1: +26.0°C (high = +80.0°C, crit = +100.0°C) Core 2: +24.0°C (high = +80.0°C, crit = +100.0°C) Core 3: +24.0°C (high = +80.0°C, crit = +100.0°C)
Test the commands
In order to send a value to the server, we first need to extract the desired value from these lines, for this we use the grep command to filter the values of the sensors command. Example of a command to get the temperature "Core 0":
sensors | grep -Eo '^Core 0: +\+[0-9]+\.[0-9]+' | grep -Eo '\+[0-9]+\.[0-9]+'
We will use CURL to send HTTP GET requests. Example command with a request:
curl --silent "https://VizIoT.com/update?key=______________&pass=______________&temp=28" > /dev/null
Now let's write a script that will send information about the temperature of the processor and its cores to the server.
Script creation.
Let's create a script using a text editor
> nano /var/viziot.sh
Script content:
key='_____________' pass='_________________' phys0=$(sensors | grep -Eo '^Physical id 0: +\+[0-9]+\.[0-9]+' | grep -Eo '[0-9]+\.[0-9]+') core0=$(sensors | grep -Eo '^Core 0: +\+[0-9]+\.[0-9]+' | grep -Eo '[0-9]+\.[0-9]+') core1=$(sensors | grep -Eo '^Core 1: +\+[0-9]+\.[0-9]+' | grep -Eo '[0-9]+\.[0-9]+') core2=$(sensors | grep -Eo '^Core 2: +\+[0-9]+\.[0-9]+' | grep -Eo '[0-9]+\.[0-9]+') core3=$(sensors | grep -Eo '^Core 3: +\+[0-9]+\.[0-9]+' | grep -Eo '[0-9]+\.[0-9]+') curl --silent "https://viziot.com/update?key=$key&pass=$pass&phys0=$phys0&core0=$core0&core1=$core1&core2=$core2&core3=$core3" > /dev/null
Give the right to execute
> chmod +x /var/viziot.sh
We'll use the cron daemon to send every minute. Let's start the cron editor
> crontab -e
And at the very end, add a line that will run the script "/var/viziot.sh" every minute:
0-59 * * * * /var/viziot.sh
Adding widgets:
Now the setup is complete and you have to wait until your device connected to the server.