solved! my mistake! TERM environment variable not set. Metern on buster

Talks about metering
metus88
Posts: 7
Joined: Tue Nov 05, 2019 3:14 pm

solved! my mistake! TERM environment variable not set. Metern on buster

Post by metus88 » Tue Nov 05, 2019 3:41 pm

Good day,
I migrated all my programs (123solar + metern + home assistant + ramlog + webserver apache + ....) from a raspberry pi 3 raspian stretch lite to a raspberry pi 3 raspian buster lite.
99% are ok.
The only problem that i have is with metern.
Image

In the log file i read:

Code: Select all

TERM environment variable not set.
If I search in all the files inside var/www/metern the word TERM with notpad++ I don't find a result.
If I check on terminal:

Code: Select all

echo $TERM 
I receive

Code: Select all

xterm
I checked in /var/www/metern/config/config_main.php and I can read

Code: Select all

$DISTRO='raspbian_ARM';
I tryed to modify debian but with not succeed.



Inside the folder /dev/shm I can found all the files and all of them are with permission 777. The file with all the data is metern2.txt with all the information that they are updated in real time from a smd630 modbus.
BUT the 2 files: mN_ILIVEMEMORY.json mN_LIVEMEMORY.json are null or 0 values.
So in the metern GUI are not able to read any data. [exluding history data]

Also in the GUI admin tab -> Meter(s)&sensor(s) if I push the button "Test command" (for both "Command" and "Live command") I recived

Code: Select all

TERM environment variable not set.TERM environment variable not set.TERM environment variable not set.TERM environment variable not set.TERM environment variable not set.TERM environment variable not set.TERM environment variable not set.TERM environment variable not set.TERM environment variable not set.TERM environment variable not set.TERM environment variable not set.TERM environment variable not set.TERM environment variable not set.TERM environment variable not set.TERM environment variable not set.TERM environment variable not set.TERM environment variable not set.TERM environment variable not set.TERM environment variable not set.TERM environment variable not set.TERM environment variable not set.TERM environment variable not set.TERM environment variable not set.TERM environment variable not set.TERM environment variable not set.TERM environment variable not set.TERM environment variable not set.TERM environment variable not set.TERM environment variable not set.TERM environment variable not set.TERM environment variable not set.TERM environment variable not set.TERM environment variable not set.TERM environment variable not set.TERM environment variable not set.TERM environment variable not set.TERM environment variable not set.TERM environment variable not set.TERM environment variable not set.TERM environment variable not set.TERM environment variable not set.TERM environment variable not set.TERM environment variable not set.TERM environment variable not set.TERM environment variable not set.TERM environment variable not set.TERM environment variable not set.TERM environment variable not set.TERM environment variable not set.TERM environment variable not set.TERM environment variable not set.TERM environment variable not set.TERM environment variable not set.TERM environment variable not set.TERM environment variable not set.TERM environment variable not set.TERM environment variable not set.TERM environment variable not set.TERM environment variable not set.TERM environment variable not set.TERM environment variable not set.TERM environment variable not set.TERM environment variable not set.TERM environment variable not set.TERM environment variable not set.TERM environment variable not set.TERM environment variable not set.TERM environment variable not set.TERM environment variable not set.TERM environment variable not set.TERM environment variable not set.TERM environment variable not set.TERM environment variable not set.TERM environment variable not set.TERM environment variable not set.TERM environment variable not set.TERM environment variable not set.TERM environment variable not set.TERM environment variable not set.TERM environment variable not set.TERM environment variable not set.TERM environment variable not set.TERM environment variable not set.TERM environment variable not set.TERM environment variable not set.TERM environment variable not set.TERM environment variable not set.TERM environment variable not set.TERM environment variable not set.TERM environment variable not set.1(3343868*Wh) is not valid, the correct format is 1(1234.5*Wh)
Any idea how I can fix the problem? Where I can check/look?

Thanks for any advice
Last edited by metus88 on Wed Nov 06, 2019 4:24 pm, edited 1 time in total.

jeanmarc
Posts: 1866
Joined: Thu Aug 29, 2013 7:16 am

Re: TERM environment variable not set. Metern on buster

Post by jeanmarc » Tue Nov 05, 2019 4:52 pm

Hi,
That come from one of your com. apps. Turn mN off and try each them alone to get further hints.

BTW i have :
[root@i3 ~]# echo $TERM
xterm-256color

metus88
Posts: 7
Joined: Tue Nov 05, 2019 3:14 pm

Re: TERM environment variable not set. Metern on buster

Post by metus88 » Wed Nov 06, 2019 11:52 am

Thanks Jeanmarc,
I follow your advice.
However if in my terminal I run every comapps, all it's fine!
All my comapps are .php
Big mystery... :?: :?:

jeanmarc
Posts: 1866
Joined: Thu Aug 29, 2013 7:16 am

Re: TERM environment variable not set. Metern on buster

Post by jeanmarc » Wed Nov 06, 2019 12:31 pm

That's odd :crazy: maybe try this test.php

Code: Select all

<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

exec('ls -a',$output);
var_dump($output);
?>

jeanmarc
Posts: 1866
Joined: Thu Aug 29, 2013 7:16 am

Re: TERM environment variable not set. Metern on buster

Post by jeanmarc » Wed Nov 06, 2019 12:41 pm

Maybe also make a phpinfo file, you should see "Environment Variables"

Code: Select all

<?php
phpinfo();
?>
Check your php.ini then https://www.php.net/manual/en/configuration.file.php

metus88
Posts: 7
Joined: Tue Nov 05, 2019 3:14 pm

Re: TERM environment variable not set. Metern on buster

Post by metus88 » Wed Nov 06, 2019 12:43 pm

I did it and this is the result.

Code: Select all

  [0]=>
  string(1) "."
  [1]=>
  string(2) ".."
  [2]=>
  string(11) "cleanlog.sh"
  [3]=>
  string(19) "com_daemon_loop.php"
  [4]=>
  string(14) "com_daemon.php"
  [5]=>
  string(11) "comtest.log"
  [6]=>
  string(13) "eflowlive.php"
  [7]=>
  string(9) "eflow.php"
  [8]=>
  string(15) "houseenergy.php"
  [9]=>
  string(9) "index.php"
  [10]=>
  string(7) "monitor"
  [11]=>
  string(12) "monitor.conf"
  [12]=>
  string(19) "monitor.conf.sample"
  [13]=>
  string(15) "pool123sdue.php"
  [14]=>
  string(12) "pool123s.php"
  [15]=>
  string(15) "pool123stre.php"
  [16]=>
  string(15) "pool123suno.php"
  [17]=>
  string(12) "pooler485.sh"
  [18]=>
  string(16) "poolerboiler.php"
  [19]=>
  string(17) "poolerconsumi.php"
  [20]=>
  string(10) "pooler.php"
  [21]=>
  string(20) "poolerproduzione.php"
  [22]=>
  string(21) "pooltotANDAVABENE.php"
  [23]=>
  string(11) "pooltot.php"
  [24]=>
  string(10) "reqsdm.php"
  [25]=>
  string(13) "reqsubmet.php"
  [26]=>
  string(14) "testamento.php"
  [27]=>
  string(11) "testcom.php"
  [28]=>
  string(24) "virtmeter_ANDAVABENE.php"
  [29]=>
  string(13) "virtmeter.php"
}
A lot of this scripts I don't use them

And i run also info php and the result is:

Code: Select all

phpinfo()
PHP Version => 7.3.11-1~deb10u1
.....
.....
Additional Modules

Module Name

Environment

Variable => Value
SHELL => /bin/bash
NO_AT_BRIDGE => 1
PWD => /var/www/comapps
LOGNAME => root
XDG_SESSION_TYPE => tty
HOME => /root
LANG => en_GB.UTF-8
SSH_CONNECTION => XXXXXXXXXXXXXXXXXXXX
XDG_SESSION_CLASS => user
TERM => xterm
USER => root
SHLVL => 1
XDG_SESSION_ID => c2
XDG_RUNTIME_DIR => /run/user/0
SSH_CLIENT => XXXXXXXXXXXXXXXXX
PATH => /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
MAIL => /var/mail/root
SSH_TTY => /dev/pts/0
TEXTDOMAIN => Linux-PAM
_ => /usr/bin/php
OLDPWD => /root

PHP Variables

Variable => Value
$_SERVER['SHELL'] => /bin/bash
$_SERVER['NO_AT_BRIDGE'] => 1
$_SERVER['PWD'] => /var/www/comapps
$_SERVER['LOGNAME'] => root
$_SERVER['XDG_SESSION_TYPE'] => tty
$_SERVER['HOME'] => /root
$_SERVER['LANG'] => en_GB.UTF-8
$_SERVER['SSH_CONNECTION'] => XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
$_SERVER['XDG_SESSION_CLASS'] => user
$_SERVER['TERM'] => xterm
$_SERVER['USER'] => root
$_SERVER['SHLVL'] => 1
$_SERVER['XDG_SESSION_ID'] => c2
$_SERVER['XDG_RUNTIME_DIR'] => /run/user/0
$_SERVER['SSH_CLIENT'] => XXXXXXXXXXXXXXXXXXXXXXXXX
$_SERVER['PATH'] => /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
$_SERVER['MAIL'] => /var/mail/root
$_SERVER['SSH_TTY'] => /dev/pts/0
$_SERVER['TEXTDOMAIN'] => Linux-PAM
$_SERVER['_'] => /usr/bin/php
$_SERVER['OLDPWD'] => /root
$_SERVER['PHP_SELF'] => testamento.php
$_SERVER['SCRIPT_NAME'] => testamento.php
$_SERVER['SCRIPT_FILENAME'] => testamento.php
$_SERVER['PATH_TRANSLATED'] => testamento.php
$_SERVER['DOCUMENT_ROOT'] =>
$_SERVER['REQUEST_TIME_FLOAT'] => 1573040732.4926
$_SERVER['REQUEST_TIME'] => 1573040732
$_SERVER['argv'] => Array
.....
.....
Inside file php.ini located in /etc/php/7.3/apache2 there is no TERM variable...
I readed from your link

Code: Select all

Example #1 php.ini Environment Variables
; PHP_MEMORY_LIMIT is taken from environment
memory_limit = ${PHP_MEMORY_LIMIT}
But i don't know how to adjust for TERM variable...

metus88
Posts: 7
Joined: Tue Nov 05, 2019 3:14 pm

Re: TERM environment variable not set. Metern on buster

Post by metus88 » Wed Nov 06, 2019 1:54 pm

There are other extensions to active in php.ini other the curl extension that I activated time ago?

Code: Select all

;extension=bz2
extension=curl
;extension=fileinfo
;extension=gd2
;extension=gettext
;extension=gmp
;extension=intl
;extension=imap
;extension=interbase
;extension=ldap
;extension=mbstring
;extension=exif      ; Must be after mbstring as it depends on it
;extension=mysqli
;extension=oci8_12c  ; Use with Oracle Database 12c Instant Client
;extension=odbc
;extension=openssl
;extension=pdo_firebird
;extension=pdo_mysql
;extension=pdo_oci
;extension=pdo_odbc
;extension=pdo_pgsql
;extension=pdo_sqlite
;extension=pgsql
;extension=shmop

jeanmarc
Posts: 1866
Joined: Thu Aug 29, 2013 7:16 am

Re: TERM environment variable not set. Metern on buster

Post by jeanmarc » Wed Nov 06, 2019 2:56 pm

You need to enable Json, Calendar and Curl extensions.
Could you try the test script with a com. apps command insteed of ls ?
I am out of idea :roll:

metus88
Posts: 7
Joined: Tue Nov 05, 2019 3:14 pm

Re: TERM environment variable not set. Metern on buster

Post by metus88 » Wed Nov 06, 2019 3:23 pm

About extension it's all ok.
It was all green (so this is not a problem).
Image
I tested two indicator(s):
Image

Temp CPU command reqsdm cpu-temp and it works if i push the botton "Test command".
the reqsdm.php is:

Code: Select all

#!/usr/bin/php
<?php
// This script will output a meterN compatible format for the main or live command
// You'll need to setup correct permission
// chmod +x reqsdm.php
// then 
// ln -s /var/www/comapps/reqsdm.php /usr/local/bin/reqsdm
// Request command with 'reqsdm tensione' or 'reqsdm corrente' or ......

if (isset($_SERVER['REMOTE_ADDR'])) {
    die('Direct access not permitted');
}
if (!isset($argv[1])) {
	die("Abording: no valid argument given.\n");
		} elseif ($argv[1] == 'tensione') {
			$outstr =  exec('cat /dev/shm/metern2.txt | egrep "^2_1\(" | grep "*V)"');
		} elseif ($argv[1] == 'corrente') {
			$outstr =  exec('cat /dev/shm/metern2.txt | egrep "^2_2\(" | grep "*A)"');
		} elseif ($argv[1] == 'freq') {
			$outstr =  exec('cat /dev/shm/metern2.txt | egrep "^2_3\(" | grep "*Hz)"');
		} elseif ($argv[1] == 'cospi') {
			$outstr =  exec('cat /dev/shm/metern2.txt | egrep "^2_4\(" | grep "*F)"');
		} elseif ($argv[1] == 'cpu-temp') {
			$outstr =  exec('cat /sys/class/thermal/thermal_zone0/temp');
			$outstr = $outstr/1000;
			$outstr = "cpu($outstr*°C)";
		// and so on ....
	} else {
    die("Usage: reqsdm (tensione|corrente|freq|cospi|cpu-temp)\n");
	}
echo "$outstr";
?>
The second inficator
Tensione command reqsubmet 2 AVN and it doesn't work if i push the botton "Test command".

Code: Select all

#!/usr/bin/php
<?php
// This script will output a meterN compatible format for the main or live command
// You'll need to setup correct permission chmod +x 
// then ln -s /var/www/comapps/reqsubmet.php /usr/bin/reqsubmet
// Request command with 'reqsubmet metnum submetnum' like 'reqsubmet 2 1' for request Volt

if (isset($_SERVER['REMOTE_ADDR'])) {
    die('Direct access not permitted');
}

if (!isset($argv[1],$argv[2])) {
	die("Abording: no valid argument given.\n");
}

$metnum = $argv[1]; // Meter ID
$submetnum = $argv[2]; // Sub Meter ID

$outstr =  exec("more /dev/shm/metern$metnum.txt | egrep \"^" . $metnum . "_" . $submetnum . "\(\" | grep \")\"") ; 
$outstr = "$outstr \n";

The two file are very similar!
And both of them if I run from terminal they work great!

Code: Select all

root@raspberrypi:/var/www/comapps# php reqsdm.php cpu-temp
cpu(46.16*°C)
root@raspberrypi:/var/www/comapps# php reqsubmet.php 2 AVN
2_AVN(221.16*V)
I check the permission file of /dev/shm/metern2.txt (that is the file with all the update data in real-time that it works) and is set 777.
It's incredible!

BUT I discover that:
If from terminal I run:

Code: Select all

reqsdm cpu-temp
it's ok.
If from terminal I run:

Code: Select all

reqsubmet 2 AVN
the output is strange:

Code: Select all

Testing in progress (1)
Array
(
    [0] => 228.45 237.99 0.84 49.96 2613265 0 OK
    [1] => 228.42 237.43 0.84 49.95 2613265 0 OK
    [2] => 228.74 238.21 0.85 49.94 2613265 0 OK
    [3] => 228.39 246.91 0.84 49.94 2613265 0 OK
    [4] => 228.15 250.79 0.85 49.93 2613265 0 OK
    [5] => 228.11 247.28 0.86 49.93 2613265 0 OK
    [6] => 228.52 244.65 0.85 49.93 2613265 0 OK
    [7] => 228.71 241.82 0.84 49.92 2613265 0 OK
    [8] => 228.51 249.06 0.85 49.92 2613265 0 OK
    [9] => 228.67 250.05 0.86 49.93 2613265 0 OK
)
06/11/2019 15:19:44 : sdm120c -a2 -b9600 -z10 -j10 -w10 -PN -qpievfg -d0 /dev/ttyUSB1
Result : best 175.4451 ms - worst 675.4789 ms - 0 error(s)

root@raspberrypi:/var/www/comapps#
I don't use sdm120c to take the data! I have a file call metern2.txt located in /dev/shm/ that in real-time have the value of the sdm630 modbus. I used it for al least 1 years without problem in the old raspberry with raspian stretch.

EDIT:
I understand that the cause of message: sdm120c -a2 -b9600 -z10 -j10 -w10 -PN -qpievfg -d0 /dev/ttyUSB1 is by testcom.php. I thinks is not important.

metern2.txt

Code: Select all

2_VR(228.32*V)
2_VS(213.69*V)
2_VT(222.29*V)
2_CR(1.02*A)
2_CS(0.48*A)
2_CT(0.36*A)
2_PR(143.93*W)
2_PS(66.15*W)
2_PT(76.29*W)
2_APR(230.32*VA)
2_APS(102.00*VA)
2_APT(81.65*VA)
2_RPR(-180.07*VAR)
2_RPS(-77.26*VAR)
2_RPT(-22.91*VAR)
2_PFR(0.62*PF)
2_PFS(0.65*PF)
2_PFT(0.96*PF)
2_PAR(-51.75*°)
2_PAS(-48.51*°)
2_PAT(-17.15*°)
2_AVN(221.46*V)
2_ALC(0.61*A)
2_SLC(1.83*A)
2_TP(280.98*W)
2_TAP(398.87*VA)
2_TRP(-283.11*VAE)
2_TPF(0.71*PF)
2_TPA(-45.17*°)
2_F(49.92*Hz)
2_IE(2613*Wh)
2_EE(0*Wh)
2_RIE(351*VARh)
2_REE(799*VARh)
2_VRS(385.06*V)
2_VST(377.82*V)
2_VTR(389.56*V)
2_AVLL(384.12*V)
2_NC(0.63*V)
2_TE(2613326*Wh)
2_TRE(1150194*VARh)
however thanks for your help! If you have any advice I'm here :?
Last edited by metus88 on Wed Nov 06, 2019 3:54 pm, edited 2 times in total.

metus88
Posts: 7
Joined: Tue Nov 05, 2019 3:14 pm

Re: TERM environment variable not set. Metern on buster

Post by metus88 » Wed Nov 06, 2019 3:35 pm

I writed a file testamento.php

Code: Select all

<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

exec('pooltot energy',$output);
var_dump($output);
?>
In terminal i run

Code: Select all

root@raspberrypi:/var/www/comapps# php testamento.php
the output is correct:

Code: Select all

root@raspberrypi:/var/www/comapps# php testamento.php
array(1) {
  [0]=>
  string(13) "1(3343868*Wh)"
}
root@raspberrypi:/var/www/comapps#
I think that it's something related to a configuration of bash or php or permission.... :cry:

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests