Send Sensor Data

This tutorial shows how to post the value of Raspberry Pi CPU internal Temperature Sensor to a value element of the MONITOR™, by reason of convenience of no need to prepare additional sensor device.
As mentioned at section "MONITOR Display" on Introduction, all Value Elements are Inactive as default, so You need to change one of these to change Active. Then, setup your device to get data, and send it to the MONITOR service with a "value_id" which you changed to Active.

Change one of your hidden Value Elements to Active on the MONITOR.

1. Open Elements Menu.

Open Elements Menu from Mobile Collapse Button or Menu Bar.

As default, only one View Element is active

2. Change to Active

Change one of your Value Element to Active and Save this setting.

Then, blank Value Element will soon open.

3. Keep value_id

Keep this "value_id" to use as address for posting the Sensor Data to this.

Setting device to take & send data automatically.

Following 2 type of steps are available, one is for "by yourself", and the other is for "useing prepared software".

Settup with useing prepared software

The "cputemp" software, which take & send it to the MONITOR automatically, is available at https://github.com/UedaTakeyuki/cputemp/releases.

1. Download "zip" or "tar.gz" on your device and expand it as follows:

pi@raspberrypi:~ $ wget https://github.com/UedaTakeyuki/cputemp/archive/v_1.0.0.zip

...

v_1.0.0.zip             [ <=>                ]   2.96K  --.-KB/s    in 0.1s

2018-09-03 18:12:44 (22.1 KB/s) - ‘v_1.0.0.zip’ saved [3028]

pi@raspberrypi:~ $ unzip v_1.0.0.zip
Archive:  v_1.0.0.zip
78d2dc9ddd52936c8dfa2cb918a12879f260f9d7
   creating: cputemp-v_1.0.0/
  inflating: cputemp-v_1.0.0/LICENSE
  inflating: cputemp-v_1.0.0/autostart.sh
  inflating: cputemp-v_1.0.0/cputemp.service
  inflating: cputemp-v_1.0.0/cputemp.sh
  inflating: cputemp-v_1.0.0/loop.sh
  inflating: cputemp-v_1.0.0/setid.sh
  inflating: cputemp-v_1.0.0/setup.sh
pi@raspberrypi:~ $

2. cd to the expanded cputemp folder

pi@raspberrypi:~ $ cd cputemp-v_1.0.0/
pi@raspberrypi:~/cputemp-v_1.0.0 $ ls
autostart.sh  cputemp.service  cputemp.sh  LICENSE  loop.sh  setid.sh  setup.sh
  • install depending softwares by setup.sh, with press all Y when get asked as [y/n].
pi@raspberrypi:~/cputemp-v_1.0.0 $ ./setup.sh

...

Setting up bc (1.06.95-9) ...

3. set "value_id" with setid.sh command with parameter your view_id as follows.

pi@raspberrypi:~/cputemp-v_1.0.0 $ ./setid.sh bzglvygr

4. test cputemp.sh command.

pi@raspberrypi:~/cputemp-v_1.0.0 $ ./cputemp.sh
{"ok":true}pi@raspberrypi:~/cputemp-v_1.0.0 $

Data sending is succeeded when {"ok":true} returned, then MONITOR display will be soon updated by sent data.

If {"ok":false}, with error reson as follows:

{"ok":false,"reason":"ValueID not valid"}

In case, most possible cause is set wrong value_id with setid.sh command mentioned above, so please make sure if you are using correct value_id.

5. set run automatically at 5 minute interval after device startup with autostart.sh command

autostart.sh command with parameter --onsetup device to run cputemp.sh script automatically at 5 minute interval after deivce startup.

pi@raspberrypi:~/cputemp-v_1.0.0 $ ./autostart.sh --on
Removed /etc/systemd/system/multi-user.target.wants/cputemp.service.
Created symlink /etc/systemd/system/multi-user.target.wants/cputemp.service → /home/pi/cputemp-v_1.0.0/cputemp.service.
pi@raspberrypi:~/cputemp-v_1.0.0 $ sudo systemctl status cputemp.service
● cputemp.service - Get cpu temperature data & Post to the monitor
   Loaded: loaded (/home/pi/cputemp-v_1.0.0/cputemp.service; enabled; vendor pre
   Active: active (running) since Mon 2018-09-03 16:55:44 JST; 1h 41min ago
 Main PID: 2140 (loop.sh)
   CGroup: /system.slice/cputemp.service
           ├─2140 /bin/bash /home/pi/cputemp/loop.sh
           └─3040 sleep 5m

Sep 03 18:06:08 raspberrypi loop.sh[2140]:                                  Dloa
Sep 03 18:06:14 raspberrypi loop.sh[2140]: [632B blob data]
Sep 03 18:11:14 raspberrypi loop.sh[2140]: {"ok":false,"reason":"no valueid"}  %
Sep 03 18:11:14 raspberrypi loop.sh[2140]:                                  Dloa
Sep 03 18:11:21 raspberrypi loop.sh[2140]: [711B blob data]
Sep 03 18:16:21 raspberrypi loop.sh[2140]: {"ok":false,"reason":"no valueid"}/ho
pi@raspberrypi:~/cputemp-v_1.0.0 $ ./autostart.sh --off
Removed /etc/systemd/system/multi-user.target.wants/cputemp.service.
Removed /etc/systemd/system/cputemp.service.
pi@raspberrypi:~/cputemp-v_1.0.0 $ sudo systemctl status cputemp.service
Unit cputemp.service could not be found.

Settup by your self

Syntax of API is as follows:

[url]       https://monitor3.uedasoft.com/postvalue.php
[method]    post
[parameter] valueid: your value_id.
            value:   value

Limitations are as follows:

  • Upload interval shoud be greater than 1 minuts.

For example, assume your valueid is abcdefgh, following script file can be work for your reference of take CPU temperature and post it to the API.

your_value_id=bzglvygr

value=`cat /sys/class/thermal/thermal_zone0/temp`
value=`echo "scale=3; $value / 1000" | bc -l`
curl https://monitor3.uedasoft.com/postvalue.php -F valueid=$your_value_id -F value=$value

There are several manner of periodical running. One is set it on cron. The other is put it into while loop , like as follows, named loop.sh

your_view_id=abcdefgh

while true; do
  value=`cat /sys/class/thermal/thermal_zone0/temp`
  value=`echo "scale=3; $value / 1000" | bc -l`
  curl https://monitor3.uedasoft.com/postvalue.php -F valueid=$your_value_id -F value=$value
    sleep 5m;

then, set as service, put following file to /etc/systemd/system/cputemp.service. You need to replace /path/to/loop.sh with your path which you've put loop.sh on.

[Unit]
Description=Get cpu temperature data & Post to the monitor
After=rc-local.service
[Service]
ExecStart=/path/to/loop.sh
Restart=always
#RestartSec=90
RestartSec=30
Type=simple
PIDFile=/var/run/cputemp.pid
[Install]
WantedBy=multi-user.target

Then, start service with followning systemctl command.

sudo systemctl daemon-reload
sudo systemctl enable view.service
sudo systemctl start view.service

For your reference, you can stop view service as follow.

sudo systemctl stop view.service

Also you can disabled, means set not to auto start it with system restart, as follows.

sudo systemctl disable view.service

Show CPU Temperature chart on the MONITOR display

The Posted data from your device will soon updated at the chart of the View Element on the MONITOR display.

results matching ""

    No results matching ""