MPVSUN

L'utilisation de api.eedomus.com et de l'eedomus toolbox

Re: MPVSUN

Messagepar flc85 » 06 Fév 2023 11:25

Concernant la commande de sortie des routages j'ai trouvé une info sur un forum:
S1 auto S2 OFF = parS=2;0;0;0;0;0;0;2;
S1 manu S2 OFF = parS=1;0;0;0;0;0;0;2;

S1 OFF S2 auto = parS=8;0;0;0;0;0;0;2;
S1 OFF S2 Manu = parS=4;0;0;0;0;0;0;2;

S1 OFF S2 OFF = parS=0;0;0;0;0;0;0;2;
S1 auto S2 auto = parS=10;0;0;0;0;0;0;2;
S1 manu S2 manu = parS=5;0;0;0;0;0;0;2;

S1 manu S2 AUTO = parS=9?;0;0;0;0;0;0;2;
S1 AUTO S2 manu = parS=6?;0;0;0;0;0;0;2;

ça complique la donne :o ou pas cmd1 devra avoir la bonne valeur suivant la configuration souhaitée ci dessus (d'autres doivent exister mais il faudra tester), et pas besoins de cmd2
Dernière édition par flc85 le 06 Fév 2023 12:44, édité 2 fois.
flc85
 
Messages : 70
Inscription : 17 Jan 2019

Re: MPVSUN

Messagepar opa95 » 06 Fév 2023 11:47

Bonjour
flc85 a écrit:Concernant la commande de sortie des routages j'ai trouvé une info sur un forum:
S1 auto S2 OFF = parS=2;0;0;0;0;0;0;2;
S1 manu S2 OFF = parS=1;0;0;0;0;0;0;2;

S1 OFF S2 auto = parS=8;0;0;0;0;0;0;2;
S1 OFF S2 Manu = parS=4;0;0;0;0;0;0;2;

S1 OFF S2 OFF = parS=0;0;0;0;0;0;0;2;
S1 auto S2 auto = parS=10;0;0;0;0;0;0;2;
S1 manu S1 manu = parS=5;0;0;0;0;0;0;2;

ça complique la donne :o ou pas cmd1 devra avoir la bonne valeur suivant la configuration souhaitée ci dessus, et pas besoins de cmd2

C'est prévu dans le logiciel que tu as, tu peux modifier indépendamment les commandes de routage.
cmd1 modifie routage_1 et cmd2 modifie routage_2 pour refabriquer la bonne valeur globale. Si la valeur vaut 10, il faut d'ailleurs la remplacer par 'a' (10 en hexadécimal).
Donc quand tu modifies cmd1, on récupère la valeur qui correspond au routage_2 pour fabriquer la bonne valeur et inversement.
J'ai tenu compte de ton info sur cmdPos[v7] et je refabrique la chaine de commande avec cette valeur, je ne sais pas si c'est nécessaire.
Voici la dernière version
Code : Tout sélectionner
<?php
/****************************************************************************
* optimisateur de production solaire MSUNPV.php
* V1.0 : opa95 2023-02-03 niveaux instantanes
* V1.1 : opa95 2023-02-05 généralisation tests par flc85 et Scalaire
* V1.2 : opa95 2023-02-06 modification des commandes
* ligne decommande http://localhost/script/?exec=MSUNPV.php&url=[VAR1]
* ligne decommande http://localhost/script/?exec=MSUNPV&php&url=[VAR1]&cmd1=a
* ligne decommande http://localhost/script/?exec=MSUNPV&php&url=[VAR1]&cmd2=b
* ligne decommande http://localhost/script/?exec=MSUNPV&php&url=[VAR1]&cmd1=a&cmd2=b
* avec VAR1 : adresse ip du MSUNPV
* avec a et b = 0 ou off, 1 ou manuel, 2 ou auto
*Récupération des valeurs dans XPATHpar //champ/@vi (i de 0 à 15)
* //rtcc/@v0
* //paramSys/@v0 à //paramSys/@v11
* //<inAns/@v0 à //<inAns/@v15
* //<survMm/@v0 à //<survMm/@v15
* //<cmdPos/@v0 à //<cmdPos/@v7
* //<outStat/@v0 à //<outStat/@v15
* //<cptVals/@v0 à //<cptVals/@v7
* //<chOutVal/@v0 à //<chOutVal/@v7
*Récuperations ciblées
* //time //timestamp //conso //production> //routage_1 //routage_2 //tension
* //powbal1 //powbal2 //enConso //enProd //enPV_J //enPV_P
* //heure //date //etat //intervalle //nom //version //sn //cmd1 //cmd2 //test_routeur
*Contenu du xml renvoyé (exemple)
<?xml version="1.0" encoding="UTF-8"?>
 <root>
   <time>2023-02-05 14:16:45</time>
   <timestamp>1675603005</timestamp>
   <current>
     <conso>-1957.3</conso> <production>-5953.5</production> <routage_1>400</routage_1>
     <routage_2>400</routage_2> <tension>227.5</tension> <powbal1>1.1</powbal1>
     <powbal2>2917.7</powbal2> <enConso>9042.6</enConso> <enProd>-118.1</enProd>
     <enPV_J>-7772.8</enPV_J> <enPV_P>-1416199.2</enPV_P> <heure>14:16:45</heure>
     <date>05/02/2023</date> <etat>On</etat> <intervalle>01:00</intervalle>
     <nom>MS_PV4_2</nom> <version>5.0.1</version> <sn>dl0420a</sn>
     <cmd1>auto</cmd1> <cmd2>auto</cmd2> <test_routeur>2</test_routeur>
   </current>
   <rtcc v0="14:16:44 DI" />
   <paramSys v0="14:16:45" v1="05/02/2023" v2="On" v3="01:00" v4="0.0" v5="MS_PV4_2" v6="5.0.1"
     v7="dl0420a" v8="102e" v9="102c" v10="00:00" v11="00:00" />
   <inAns v0="-1957.3" v1="-5953.5" v2="400" v3="400" v4="227.5" v5="1.1" v6="2917.7" v7="0.0"
     v8="0.0" v9="0.0" v10="0.0" v11="0.0" v12="0.0" v13="0.0" v14="0.0" v15="0.0" />
   <survMm v0="0" v1="0" v2="0" v3="0" v4="0" v5="0" v6="0" v7="0" v8="0" v9="0"
     v10="0" v11="0" v12="0" v13="0" v14="0" v15="0" />
   <cmdPos v0="10" v1="0" v2="0" v3="0" v4="0" v5="0" v6="0" v7="2" />
   <outStat v0="100" v1="100" v2="0" v3="0" v4="0" v5="0" v6="0" v7="0"
     v8="0" v9="0" v10="0" v11="0" v12="0" v13="0" v14="0" v15="0" />
   <cptVals v0="90426" v1="-118.1" v2="-7772.8" v3="-1416199.2" v4="0" v5="0" v6="0" v7="0" />
   <chOutVal v0="0" v1="0" v2="0" v3="255" v4="0" v5="0" v6="0" v7="0" />
 </root>
**************************************************************************/
function sdk_set_command($cmd1,$cmd2) {//$command 0,1,2)
  $cmd1 = min($cmd1%4,2);
  $cmd2 = min($cmd2%4,2);
  $command = $cmd1 + 4*$cmd2;
  if ($command == 10) $command = 'a';
  return $command;//nombre entre 0 et 10
}

function sdk_get_command($command) {//$command entre 0 et 10, select 0 ou 1
  if (strtolower($command) == 'a') $command = 10;
  $command = min($command,10);
  $arrCmd[1] = $command%4;
  $arrCmd[2] = round(($command - $arrCmd[1])/4);
  return $arrCmd;
}

function sdk_num_command($cmd) {//$cmd off, manuel, auto
  $cmd = trim(strtolower($cmd));
  switch ($cmd) {
    case '0' :
    case 'off'    : $cmd = 0;
                    break;
    case '1' :
    case 'manuel' : $cmd = 1;
                    break;
    case '2' :
    case 'auto'   : $cmd = 2;
                    break;
    default :       $cmd = '*';
  }
  return $cmd;               
}

$hexa = array('cmdPos','cptVals','chOutVal');//Champ hexa
$inAns = array('conso','production','routage_1','routage_2','tension','powbal1','powbal2');
$cptVals = array('enConso','enProd','enPV_J','enPV_P');
$paramSys = array('heure','date','etat','intervalle','','nom','version','sn');
$cmdPos = array('cmd0','','','','','','','test_routeur');
$cmdArr = array('off','manuel','auto');
$max_int_pos = 0X100000000;
$max_int = ($max_int_pos+1)*2;
$url_  = getArg('url');
$url  = $url_.'/status.xml';
$url_cmd  = $url_.'/index.xml';
$cmd1_  = sdk_num_command(getArg('cmd1',false,''));
$cmd2_  = sdk_num_command(getArg('cmd2',false,''));
$response = httpQuery($url, 'GET', '','', $header);
$response1 = xpath($response,'cmdPos');
$old_command = explode(';',$response1);
$old_cmds = sdk_get_command($old_command[0]);
if ($cmd1_ === '*') $new_cmds[1] = $old_cmds[1];
else {$new_cmds[1] = $cmd1_; }
if ($cmd2_ === '*') $new_cmds[2] = $old_cmds[2];
else {$new_cmds[2] = $cmd2_;}
$is_new_command = ($new_cmds[1] != $old_cmds[1]) || ($new_cmds[1] != $old_cmds[1]) ;
$cmd = sdk_set_command($new_cmds[1],$new_cmds[2]);
if ($is_new_command){
  $parS=$cmd.';';
  foreach ($old_command as $key => $item){
    if ($key == 0) continue;
    $parS .= $item.';';
  }
  $parS = str_replace(';;',';',$parS);
  $url1 = $url_cmd.'?parS='.$parS;
  $response = httpQuery($url1, 'POST', '','', $header);
}

$response = xpath($response,"concat('rtcc=',//rtcc,'@paramSys=',//paramSys,'@inAns=',//inAns,'@survMm=',//survMm,'@cmdPos=',//cmdPos,'@outStat=',//outStat,'@cptVals=',//cptVals,'@chOutVal=',//chOutVal)");
$response = trim(str_replace(';@','@',$response));
$response = str_replace(',','.',$response);
$arr_response = explode('@',$response);
foreach ($arr_response as $field) {
  list($key,$values) = explode('=',$field);
  $arrValue = array();
  $arr_values = explode(';',$values);
  if (in_array($key,$hexa)) {
    foreach ($arr_values as $value){
      $value = trim($value);
      if ($value != '') {$result[$key][] = hexdec($value);}
    }
  }
  else {
    foreach ($arr_values as $value){
      $value = trim($value);
      if ($value != '') $result[$key][] = $value;
    }
  }
}
$cmds = sdk_get_command($result['cmdPos'][0]);
$heure = $result['paramSys'][0];
list($day,$month,$year) = explode('/',$result['paramSys'][1]);
$date = $year.'-'.$month.'-'.$day;
$timestamp = strtotime($date.' '.$heure);
$time = date('Y-m-d H:i:s',$timestamp);
@sdk_header('text/xml');
$xml = '<?xml version="1.0" encoding="UTF-8"?>'.PHP_EOL;
$xml .= ' <root>'.PHP_EOL;
$xml .= '   <time>'.$time.'</time> '.PHP_EOL;;
$xml .= '   <timestamp>'.$timestamp.'</timestamp>'.PHP_EOL;;
$xml .= '   <current>'.PHP_EOL.'     '; 
$key = 'inAns';
$ind = 0;
foreach ($inAns as $item){
  if ($item != '') $xml .= '<'.$item.'>'.$result[$key][$ind].'</'.$item.'> ';
  $ind++;
}
$key = 'cptVals';
$ind = 0;
foreach ($cptVals as $item){
  if ($item != '') {
    if ($result[$key][$ind]<=$max_int_pos) {
      $xml .= '<'.$item.'>'.($result[$key][$ind]/10).'</'.$item.'> ';
    }
    else {
      $result[$key][$ind] = ($result[$key][$ind]-$max_int)/10;
      $xml .= '<'.$item.'>'.$result[$key][$ind].'</'.$item.'> ';
    }
  $ind++;}
}
$key = 'paramSys';
$ind = 0;
foreach ($paramSys as $item){
  if ($item != '') $xml .= '<'.$item.'>'.$result[$key][$ind].'</'.$item.'> ';
    $ind++;
}
$xml .= '<cmd1>'.$cmdArr[$cmds[1]].'</cmd1> '.'<cmd2>'.$cmdArr[$cmds[2]].'</cmd2> ';
$key = 'cmdPos';$ind = 7;
$xml .= '<'.$cmdPos[$ind].'>'.$result[$key][$ind].'</'.$cmdPos[$ind].'>';
$xml .= PHP_EOL.'   </current>'.PHP_EOL;
foreach ($result as $key => $value){
  $xml .= '   <'.$key.' ';
  foreach ($result[$key] as $key1 => $value1){
    $xml .= 'v'.$key1.'="'.$value1.'" ';
  }
  $xml .= '/>'.PHP_EOL;
}
$xml .= ' </root>'.PHP_EOL;
echo $xml;
?>

Peux-tu essayer avec un actionneur HTTP avec ces valeurs :)
MSUNactionneur.png
MSUNactionneur.png (27.22 Kio) Consulté 3434 fois
eedomus+, Zibase V1, RFP1000, RFXcom, RadioDriver CPL 630 X2D, capteurs puissance OWL, thermometres Oregon, téléinfo (USB Linky), detecteurs ouverture X2D, pilotage chauffage X2D, Ecoflow River PRO, PAC Shogun (Atlantic-Cozytouch)
opa95
 
Messages : 723
Inscription : 04 Fév 2019
Localisation : Val d'Oise

Re: MPVSUN

Messagepar flc85 » 06 Fév 2023 11:57

J'ai déjà testé cela fonctionne pour cmd1.
Dernière édition par flc85 le 06 Fév 2023 13:05, édité 2 fois.
flc85
 
Messages : 70
Inscription : 17 Jan 2019

Re: MPVSUN

Messagepar flc85 » 06 Fév 2023 11:59

par contre pour cmd2 si je tape ça:
http://localhost/script/?exec=MSUNPV.ph ... 247&cmd2=2

il ne se passe rien
Dernière édition par flc85 le 06 Fév 2023 13:05, édité 1 fois.
flc85
 
Messages : 70
Inscription : 17 Jan 2019

Re: MPVSUN

Messagepar flc85 » 06 Fév 2023 12:06

j'ai testé également pour avoir 1 et 2 en auto avec:
http://localhost/script/?exec=MSUNPV.ph ... 1=2&cmd2=2
ça ne fonctionne pas non plus

si j'ai bien compris la logique pour avoir cmd1 en auto et cmd2 en manu il faut que :
parS=6;0;0;0;0;0;0;2;
flc85
 
Messages : 70
Inscription : 17 Jan 2019

Re: MPVSUN

Messagepar opa95 » 06 Fév 2023 13:15

Bonjour
flc85 a écrit:j'ai testé également pour avoir 1 et 2 en auto avec:
http://localhost/script/?exec=MSUNPV.ph ... 1=2&cmd2=2
ça ne fonctionne pas non plus

si j'ai bien compris la logique pour avoir cmd1 en auto et cmd2 en manu il faut que :
parS=6;0;0;0;0;0;0;2;

Corrige la ligne
Code : Tout sélectionner
$is_new_command = ($new_cmds[1] != $old_cmds[1]) || ($new_cmds[1] != $old_cmds[1]) ;

par
Code : Tout sélectionner
$is_new_command = ($new_cmds[1] != $old_cmds[1]) || ($new_cmds[2] != $old_cmds[2]) ;

desolé :oops:
eedomus+, Zibase V1, RFP1000, RFXcom, RadioDriver CPL 630 X2D, capteurs puissance OWL, thermometres Oregon, téléinfo (USB Linky), detecteurs ouverture X2D, pilotage chauffage X2D, Ecoflow River PRO, PAC Shogun (Atlantic-Cozytouch)
opa95
 
Messages : 723
Inscription : 04 Fév 2019
Localisation : Val d'Oise

Re: MPVSUN

Messagepar flc85 » 06 Fév 2023 13:22

TOP ça fonctionne nickel.
Je regarde si je trouve des infos pour la commande de V7
Merci beaucoup
flc85
 
Messages : 70
Inscription : 17 Jan 2019

Re: MPVSUN

Messagepar opa95 » 06 Fév 2023 14:21

OK
flc85 a écrit:TOP ça fonctionne nickel.
Je regarde si je trouve des infos pour la commande de V7
Merci beaucoup

Voici donc la version V1.2 à jour du 2023-02-06 :)
Code : Tout sélectionner
<?php
/****************************************************************************
* optimisateur de production solaire MSUNPV.php
* V1.0 : opa95 2023-02-03 niveaux instantanes
* V1.1 : opa95 2023-02-05 généralisation tests par flc85 et Scalaire
* V1.2 : opa95 2023-02-06 modification des commandes
* ligne decommande http://localhost/script/?exec=MSUNPV.php&url=[VAR1]
* ligne decommande http://localhost/script/?exec=MSUNPV&php&url=[VAR1]&cmd1=a
* ligne decommande http://localhost/script/?exec=MSUNPV&php&url=[VAR1]&cmd2=b
* ligne decommande http://localhost/script/?exec=MSUNPV&php&url=[VAR1]&cmd1=a&cmd2=b
* avec VAR1 : adresse ip du MSUNPV
* avec a et b = 0 ou off, 1 ou manuel, 2 ou auto
*Récupération des valeurs dans XPATHpar //champ/@vi (i de 0 à 15)
* //rtcc/@v0
* //paramSys/@v0 à //paramSys/@v11
* //<inAns/@v0 à //<inAns/@v15
* //<survMm/@v0 à //<survMm/@v15
* //<cmdPos/@v0 à //<cmdPos/@v7
* //<outStat/@v0 à //<outStat/@v15
* //<cptVals/@v0 à //<cptVals/@v7
* //<chOutVal/@v0 à //<chOutVal/@v7
*Récuperations ciblées
* //time //timestamp //conso //production> //routage_1 //routage_2 //tension
* //powbal1 //powbal2 //enConso //enProd //enPV_J //enPV_P
* //heure //date //etat //intervalle //nom //version //sn //cmd1 //cmd2 //test_routeur
*Contenu du xml renvoyé (exemple)
<?xml version="1.0" encoding="UTF-8"?>
 <root>
   <time>2023-02-05 14:16:45</time>
   <timestamp>1675603005</timestamp>
   <current>
     <conso>-1957.3</conso> <production>-5953.5</production> <routage_1>400</routage_1>
     <routage_2>400</routage_2> <tension>227.5</tension> <powbal1>1.1</powbal1>
     <powbal2>2917.7</powbal2> <enConso>9042.6</enConso> <enProd>-118.1</enProd>
     <enPV_J>-7772.8</enPV_J> <enPV_P>-1416199.2</enPV_P> <heure>14:16:45</heure>
     <date>05/02/2023</date> <etat>On</etat> <intervalle>01:00</intervalle>
     <nom>MS_PV4_2</nom> <version>5.0.1</version> <sn>dl0420a</sn>
     <cmd1>auto</cmd1> <cmd2>auto</cmd2> <test_routeur>2</test_routeur>
   </current>
   <rtcc v0="14:16:44 DI" />
   <paramSys v0="14:16:45" v1="05/02/2023" v2="On" v3="01:00" v4="0.0" v5="MS_PV4_2" v6="5.0.1"
     v7="dl0420a" v8="102e" v9="102c" v10="00:00" v11="00:00" />
   <inAns v0="-1957.3" v1="-5953.5" v2="400" v3="400" v4="227.5" v5="1.1" v6="2917.7" v7="0.0"
     v8="0.0" v9="0.0" v10="0.0" v11="0.0" v12="0.0" v13="0.0" v14="0.0" v15="0.0" />
   <survMm v0="0" v1="0" v2="0" v3="0" v4="0" v5="0" v6="0" v7="0" v8="0" v9="0"
     v10="0" v11="0" v12="0" v13="0" v14="0" v15="0" />
   <cmdPos v0="10" v1="0" v2="0" v3="0" v4="0" v5="0" v6="0" v7="2" />
   <outStat v0="100" v1="100" v2="0" v3="0" v4="0" v5="0" v6="0" v7="0"
     v8="0" v9="0" v10="0" v11="0" v12="0" v13="0" v14="0" v15="0" />
   <cptVals v0="90426" v1="-118.1" v2="-7772.8" v3="-1416199.2" v4="0" v5="0" v6="0" v7="0" />
   <chOutVal v0="0" v1="0" v2="0" v3="255" v4="0" v5="0" v6="0" v7="0" />
 </root>
**************************************************************************/
function sdk_set_command($cmd1,$cmd2) {//$command 0,1,2)
  $cmd1 = min($cmd1%4,2);
  $cmd2 = min($cmd2%4,2);
  $command = $cmd1 + 4*$cmd2;
  if ($command == 10) $command = 'a';
  return $command;//nombre entre 0 et 10
}

function sdk_get_command($command) {//$command entre 0 et 10, select 0 ou 1
  if (strtolower($command) == 'a') $command = 10;
  $command = min($command,10);
  $arrCmd[1] = $command%4;
  $arrCmd[2] = round(($command - $arrCmd[1])/4);
  return $arrCmd;
}

function sdk_num_command($cmd) {//$cmd off, manuel, auto
  $cmd = trim(strtolower($cmd));
  switch ($cmd) {
    case '0' :
    case 'off'    : $cmd = 0;
                    break;
    case '1' :
    case 'manuel' : $cmd = 1;
                    break;
    case '2' :
    case 'auto'   : $cmd = 2;
                    break;
    default :       $cmd = '*';
  }
  return $cmd;               
}

$hexa = array('cmdPos','cptVals','chOutVal');//Champ hexa
$inAns = array('conso','production','routage_1','routage_2','tension','powbal1','powbal2');
$cptVals = array('enConso','enProd','enPV_J','enPV_P');
$paramSys = array('heure','date','etat','intervalle','','nom','version','sn');
$cmdPos = array('cmd0','','','','','','','test_routeur');
$cmdArr = array('off','manuel','auto');
$max_int_pos = 0X100000000;
$max_int = ($max_int_pos+1)*2;
$url_  = getArg('url');
$url  = $url_.'/status.xml';
$url_cmd  = $url_.'/index.xml';
$cmd1_  = sdk_num_command(getArg('cmd1',false,''));
$cmd2_  = sdk_num_command(getArg('cmd2',false,''));
$response = httpQuery($url, 'GET', '','', $header);
$response1 = xpath($response,'cmdPos');
$old_command = explode(';',$response1);
$old_cmds = sdk_get_command($old_command[0]);
if ($cmd1_ === '*') $new_cmds[1] = $old_cmds[1];
else {$new_cmds[1] = $cmd1_; }
if ($cmd2_ === '*') $new_cmds[2] = $old_cmds[2];
else {$new_cmds[2] = $cmd2_;}
$is_new_command = ($new_cmds[1] != $old_cmds[1]) || ($new_cmds[2] != $old_cmds[2]) ;
$cmd = sdk_set_command($new_cmds[1],$new_cmds[2]);
if ($is_new_command){
  $parS=$cmd.';';
  foreach ($old_command as $key => $item){
    if ($key == 0) continue;
    $parS .= $item.';';
  }
  $parS = str_replace(';;',';',$parS);
  $url1 = $url_cmd.'?parS='.$parS;
  $response = httpQuery($url1, 'POST', '','', $header);
}

$response = xpath($response,"concat('rtcc=',//rtcc,'@paramSys=',//paramSys,'@inAns=',//inAns,'@survMm=',//survMm,'@cmdPos=',//cmdPos,'@outStat=',//outStat,'@cptVals=',//cptVals,'@chOutVal=',//chOutVal)");
$response = trim(str_replace(';@','@',$response));
$response = str_replace(',','.',$response);
$arr_response = explode('@',$response);
foreach ($arr_response as $field) {
  list($key,$values) = explode('=',$field);
  $arrValue = array();
  $arr_values = explode(';',$values);
  if (in_array($key,$hexa)) {
    foreach ($arr_values as $value){
      $value = trim($value);
      if ($value != '') {$result[$key][] = hexdec($value);}
    }
  }
  else {
    foreach ($arr_values as $value){
      $value = trim($value);
      if ($value != '') $result[$key][] = $value;
    }
  }
}
$cmds = sdk_get_command($result['cmdPos'][0]);
$heure = $result['paramSys'][0];
list($day,$month,$year) = explode('/',$result['paramSys'][1]);
$date = $year.'-'.$month.'-'.$day;
$timestamp = strtotime($date.' '.$heure);
$time = date('Y-m-d H:i:s',$timestamp);
@sdk_header('text/xml');
$xml = '<?xml version="1.0" encoding="UTF-8"?>'.PHP_EOL;
$xml .= ' <root>'.PHP_EOL;
$xml .= '   <time>'.$time.'</time> '.PHP_EOL;;
$xml .= '   <timestamp>'.$timestamp.'</timestamp>'.PHP_EOL;;
$xml .= '   <current>'.PHP_EOL.'     ';
$key = 'inAns';
$ind = 0;
foreach ($inAns as $item){
  if ($item != '') $xml .= '<'.$item.'>'.$result[$key][$ind].'</'.$item.'> ';
  $ind++;
}
$key = 'cptVals';
$ind = 0;
foreach ($cptVals as $item){
  if ($item != '') {
    if ($result[$key][$ind]<=$max_int_pos) {
      $xml .= '<'.$item.'>'.($result[$key][$ind]/10).'</'.$item.'> ';
    }
    else {
      $result[$key][$ind] = ($result[$key][$ind]-$max_int)/10;
      $xml .= '<'.$item.'>'.$result[$key][$ind].'</'.$item.'> ';
    }
  $ind++;}
}
$key = 'paramSys';
$ind = 0;
foreach ($paramSys as $item){
  if ($item != '') $xml .= '<'.$item.'>'.$result[$key][$ind].'</'.$item.'> ';
    $ind++;
}
$xml .= '<cmd1>'.$cmdArr[$cmds[1]].'</cmd1> '.'<cmd2>'.$cmdArr[$cmds[2]].'</cmd2> ';
$key = 'cmdPos';$ind = 7;
$xml .= '<'.$cmdPos[$ind].'>'.$result[$key][$ind].'</'.$cmdPos[$ind].'>';
$xml .= PHP_EOL.'   </current>'.PHP_EOL;
foreach ($result as $key => $value){
  $xml .= '   <'.$key.' ';
  foreach ($result[$key] as $key1 => $value1){
    $xml .= 'v'.$key1.'="'.$value1.'" ';
  }
  $xml .= '/>'.PHP_EOL;
}
$xml .= ' </root>'.PHP_EOL;
echo $xml;
?>
eedomus+, Zibase V1, RFP1000, RFXcom, RadioDriver CPL 630 X2D, capteurs puissance OWL, thermometres Oregon, téléinfo (USB Linky), detecteurs ouverture X2D, pilotage chauffage X2D, Ecoflow River PRO, PAC Shogun (Atlantic-Cozytouch)
opa95
 
Messages : 723
Inscription : 04 Fév 2019
Localisation : Val d'Oise

Re: MPVSUN

Messagepar flc85 » 06 Fév 2023 18:39

Donc en cherchant un peu on a bien:
<test_routeur>1</test_routeur>
1= Injection
2= Zéro injection
4= Moyen
8= Fort

Je pense que pour commander le routeur c'est la dernière valeur de parS (parS=2;0;0;0;0;0;0;2;)mais je ne sais pas comment vérifier?
flc85
 
Messages : 70
Inscription : 17 Jan 2019

Re: MPVSUN

Messagepar opa95 » 06 Fév 2023 18:48

Bonsoir
flc85 a écrit:Donc en cherchant un peu on a bien:
<test_routeur>1</test_routeur>
1= Injection
2= Zéro injection
4= Moyen
8= Fort

Je pense que pour commander le routeur c'est la dernière valeur de parS (parS=2;0;0;0;0;0;0;2;)mais je ne sais pas comment vérifier?

Est-ce que tu peux la modifier avec ton appli?
Si oui, on peut aussi le faire avec l'eedomus.
as -tu essayé la commande avec l'actionneur HTTP? :)
eedomus+, Zibase V1, RFP1000, RFXcom, RadioDriver CPL 630 X2D, capteurs puissance OWL, thermometres Oregon, téléinfo (USB Linky), detecteurs ouverture X2D, pilotage chauffage X2D, Ecoflow River PRO, PAC Shogun (Atlantic-Cozytouch)
opa95
 
Messages : 723
Inscription : 04 Fév 2019
Localisation : Val d'Oise

Re: MPVSUN

Messagepar flc85 » 06 Fév 2023 18:56

Oui c'est comme cela que j'ai trouvé les valeurs.
il faudrait rajouter un cmd3 qui modifie la dernière valeurs de parS.
J'ai créé 2 actionneurs http un pour rout_1 et l'autre pour rout_2 tout fonctionne nickel
flc85
 
Messages : 70
Inscription : 17 Jan 2019

Re: MPVSUN

Messagepar opa95 » 06 Fév 2023 19:34

Bonsoir
flc85 a écrit:Oui c'est comme cela que j'ai trouvé les valeurs.
il faudrait rajouter un cmd3 qui modifie la dernière valeurs de parS.
J'ai créé 2 actionneurs http un pour rout_1 et l'autre pour rout_2 tout fonctionne nickel

OK, je te l'envoie demain dans la matinée. :)
eedomus+, Zibase V1, RFP1000, RFXcom, RadioDriver CPL 630 X2D, capteurs puissance OWL, thermometres Oregon, téléinfo (USB Linky), detecteurs ouverture X2D, pilotage chauffage X2D, Ecoflow River PRO, PAC Shogun (Atlantic-Cozytouch)
opa95
 
Messages : 723
Inscription : 04 Fév 2019
Localisation : Val d'Oise

Re: MPVSUN

Messagepar opa95 » 07 Fév 2023 11:43

Bonjour
Voici la dernière version (V1.2) qui affiche l'état du MSUNPV et permet d'envoyer des commandes.
Les informations nécessaires sont en tête de script, en attendant une doc et peut être une mise sur le STORE (je n'ai pas le temps).
Sauver le script MSUNPV.php et le transférer sur l'eedomus.
Créer des capteurs HTTP pour récupérer les informations : Mettre l'adresse IP du MSUNPV dans VAR1
Faire les appels avec http://localhost/script/?exec=MSUNPV.php&url=[VAR1]
Faire les lectures avec //conso.... ou //inAns/@v0...
Créer des actionneurs HTTP pour envoyer des commandes : cmd1 (routeur1), cmd2 (routeur2) ou cmdtest
Créer les valeurs 3 valeurs pour les cmd, 4 valeurs pour cmdtest (cf. script) en remplissant Valeur brute, description et URL
exemple : 2, manuel et http://localhost/script/?exec=MSUNPV.php&url=[VAR1]&cmd1=2
Tester et signaler les problèmes ou les améliorations souhaitées (je ne peux pas tester les commandes car je n'ai pas de MSUNPV) :)
Code : Tout sélectionner
<?php
/****************************************************************************
* optimisateur de production solaire MSUNPV.php por eedomus
* V1.0 : opa95 2023-02-03 niveaux instantanes
* V1.1 : opa95 2023-02-05 généralisation tests par flc85 et Scalaire
* V1.2 : opa95 2023-02-07 modification des commandes tests par flc85
* ligne decommande http://localhost/script/?exec=MSUNPV.php&url=[VAR1]
* ligne decommande http://localhost/script/?exec=MSUNPV&php&url=[VAR1]&cmd1=a
* ligne decommande http://localhost/script/?exec=MSUNPV&php&url=[VAR1]&cmd2=b
* avec VAR1 : adresse ip du MSUNPV
* avec a et b = 0 ou off, 1 ou manuel, 2 ou auto
* ligne decommande http://localhost/script/?exec=MSUNPV&php&url=[VAR1]&cmdtest=c
* avec c = 1 ou injection, 2 ou zero_injection, 4 ou moyen, 8 ou fort
* récupération avec un capteur HTTP
*Récupération des valeurs dans XPATH par //champ/@vi (i de 0 à 15)
* //rtcc/@v0
* //paramSys/@v0 à //paramSys/@v11
* //inAns/@v0 à //inAns/@v15
* //survMm/@v0 à //survMm/@v15
* //cmdPos/@v0 à //cmdPos/@v7
* //outStat/@v0 à //outStat/@v15
* //cptVals/@v0 à //cptVals/@v7
* //chOutVal/@v0 à //chOutVal/@v7
*Récuperations ciblées
* //time //timestamp //conso //production> //routage_1 //routage_2 //tension
* //powbal1 //powbal2 //enConso //enProd //enPV_J //enPV_P
* //heure //date //etat //intervalle //nom //version //sn //cmd1 //cmd2 //test_routeur
*Envoi de commande avec un actionneur HTTP
* pour cmd1, mettre les valeurs [Valeur Brute, Description,URL] et l'équivalent pour cmd2
* 0 off http://localhost/script/?exec=MSUNPV.php&url=[VAR1]&cmd1=0
* 1 manuel http://localhost/script/?exec=MSUNPV.php&url=[VAR1]&cmd1=1
* 2 manuel http://localhost/script/?exec=MSUNPV.php&url=[VAR1]&cmd1=2
* pour cmdtest, mettre les valeurs
* 1 injection http://localhost/script/?exec=MSUNPV.php&url=[VAR1]&cmdtest=1
* 2 zero_injection http://localhost/script/?exec=MSUNPV.php&url=[VAR1]&cmdtest=2
* 4 moyen http://localhost/script/?exec=MSUNPV.php&url=[VAR1]&cmdtest=4
* 8 fort http://localhost/script/?exec=MSUNPV.php&url=[VAR1]&cmdtest=8
*Contenu du xml renvoyé (exemple)
<?xml version="1.0" encoding="UTF-8"?>
 <root>
   <time>2023-02-05 14:16:45</time>
   <timestamp>1675603005</timestamp>
   <current>
     <conso>-1957.3</conso> <production>-5953.5</production> <routage_1>400</routage_1>
     <routage_2>400</routage_2> <tension>227.5</tension> <powbal1>1.1</powbal1>
     <powbal2>2917.7</powbal2> <enConso>9042.6</enConso> <enProd>-118.1</enProd>
     <enPV_J>-7772.8</enPV_J> <enPV_P>-1416199.2</enPV_P> <heure>14:16:45</heure>
     <date>05/02/2023</date> <etat>On</etat> <intervalle>01:00</intervalle>
     <nom>MS_PV4_2</nom> <version>5.0.1</version> <sn>dl0420a</sn>
     <cmd1>auto</cmd1> <cmd2>auto</cmd2> <test_routeur>zero_injection</test_routeur>
   </current>
   <rtcc v0="14:16:44 DI" />
   <paramSys v0="14:16:45" v1="05/02/2023" v2="On" v3="01:00" v4="0.0" v5="MS_PV4_2" v6="5.0.1"
     v7="dl0420a" v8="102e" v9="102c" v10="00:00" v11="00:00" />
   <inAns v0="-1957.3" v1="-5953.5" v2="400" v3="400" v4="227.5" v5="1.1" v6="2917.7" v7="0.0"
     v8="0.0" v9="0.0" v10="0.0" v11="0.0" v12="0.0" v13="0.0" v14="0.0" v15="0.0" />
   <survMm v0="0" v1="0" v2="0" v3="0" v4="0" v5="0" v6="0" v7="0" v8="0" v9="0"
     v10="0" v11="0" v12="0" v13="0" v14="0" v15="0" />
   <cmdPos v0="10" v1="0" v2="0" v3="0" v4="0" v5="0" v6="0" v7="2" />
   <outStat v0="100" v1="100" v2="0" v3="0" v4="0" v5="0" v6="0" v7="0"
     v8="0" v9="0" v10="0" v11="0" v12="0" v13="0" v14="0" v15="0" />
   <cptVals v0="90426" v1="-118.1" v2="-7772.8" v3="-1416199.2" v4="0" v5="0" v6="0" v7="0" />
   <chOutVal v0="0" v1="0" v2="0" v3="255" v4="0" v5="0" v6="0" v7="0" />
 </root>
**************************************************************************/

function sdk_set_command($cmd1,$cmd2) {//$command 0,1,2)
  $cmd1 = min($cmd1%4,2);
  $cmd2 = min($cmd2%4,2);
  $command = $cmd1 + 4*$cmd2;
  if ($command == 10) $command = 'a';
  return $command;//nombre entre 0 et 10
}

function sdk_get_command($command) {//$command entre 0 et 10, select 0 ou 1
  if (strtolower($command) == 'a') $command = 10;
  $command = min($command,10);
  $arr_cmd[1] = $command%4;
  $arr_cmd[2] = round(($command - $arr_cmd[1])/4);
  return $arr_cmd;
}

function sdk_num_command($cmd) {//$cmd off, manuel, auto
  $cmd = trim(strtolower($cmd));
  switch ($cmd) {
    case '0' :
    case 'off'    : $cmd = 0;
                    break;
    case '1' :
    case 'manuel' : $cmd = 1;
                    break;
    case '2' :
    case 'auto'   : $cmd = 2;
                    break;
    default :       $cmd = '*';
  }
  return $cmd;               
}

$hexa = array('cmdPos','cptVals','chOutVal');//Champ hexa
$inAns = array('conso','production','routage_1','routage_2','tension','powbal1','powbal2');
$cptVals = array('enConso','enProd','enPV_J','enPV_P');
$paramSys = array('heure','date','etat','intervalle','','nom','version','sn');
$cmdPos = array('cmd0','','','','','','','test_routeur');
$arr_cmds = array('off','manuel','auto');
$arr_tests = array(1 => 'injection',2 => 'zero_injection',4 => 'moyen',8 => 'fort');
$max_int_pos = 0X100000000;
$max_int = ($max_int_pos+1)*2;
$url_  = getArg('url');
$url  = $url_.'/status.xml';
$url_cmd  = $url_.'/index.xml';
$cmd1_  = sdk_num_command(getArg('cmd1',false,''));
$cmd2_  = sdk_num_command(getArg('cmd2',false,''));
$cmd_test_  = getArg('cmdtest',false,'0');
if (in_array($cmd_test_, array(1,2,4,8))) { $cmd_test = $cmd_test_;}
  else {
  $cmd_test = 0;
  foreach($arr_tests as $key => $item) {
    if ($cmd_test_ == $item) {
      $cmd_test = $key;
      break;
    }
  }
}
$response = httpQuery($url, 'GET', '','', $header);
$response1 = xpath($response,'cmdPos');
$old_command = explode(';',$response1);
$old_cmds = sdk_get_command($old_command[0]);
if ($cmd1_ === '*') $new_cmds[1] = $old_cmds[1];
else {$new_cmds[1] = $cmd1_; }
if ($cmd2_ === '*') $new_cmds[2] = $old_cmds[2];
else {$new_cmds[2] = $cmd2_;}
if ($cmd_test == 0 ) $cmd_test = $old_command[7];
$is_new_command = ($new_cmds[1] != $old_cmds[1]) || ($new_cmds[2] != $old_cmds[2]) || ($cmd_test != $old_command[7]);
$cmd = sdk_set_command($new_cmds[1],$new_cmds[2]);
if ($is_new_command){
  $parS=$cmd.';';
  foreach ($old_command as $key => $item){
    if ($key == 0) continue;
    if ($key == 7) break;
    $parS .= $item.';';
  }
  $parS = str_replace(';;',';',$parS.$cmd_test);
  $url1 = $url_cmd.'?parS='.$parS;
  $response = httpQuery($url1, 'POST', '','', $header);
}

$response = xpath($response,"concat('rtcc=',//rtcc,'@paramSys=',//paramSys,'@inAns=',//inAns,'@survMm=',//survMm,'@cmdPos=',//cmdPos,'@outStat=',//outStat,'@cptVals=',//cptVals,'@chOutVal=',//chOutVal)");
$response = trim(str_replace(';@','@',$response));
$response = str_replace(',','.',$response);
$arr_response = explode('@',$response);
foreach ($arr_response as $field) {
  list($key,$values) = explode('=',$field);
  $arrValue = array();
  $arr_values = explode(';',$values);
  if (in_array($key,$hexa)) {
    foreach ($arr_values as $value){
      $value = trim($value);
      if ($value != '') {$result[$key][] = hexdec($value);}
    }
  }
  else {
    foreach ($arr_values as $value){
      $value = trim($value);
      if ($value != '') $result[$key][] = $value;
    }
  }
}
//var_dump($result);
$cmds = sdk_get_command($result['cmdPos'][0]);
$heure = $result['paramSys'][0];
list($day,$month,$year) = explode('/',$result['paramSys'][1]);
$date = $year.'-'.$month.'-'.$day;
$timestamp = strtotime($date.' '.$heure);
$time = date('Y-m-d H:i:s',$timestamp);
@sdk_header('text/xml');
$xml = '<?xml version="1.0" encoding="UTF-8"?>'.PHP_EOL;
$xml .= ' <root>'.PHP_EOL;
$xml .= '   <time>'.$time.'</time> '.PHP_EOL;;
$xml .= '   <timestamp>'.$timestamp.'</timestamp>'.PHP_EOL;;
$xml .= '   <current>'.PHP_EOL.'     '; 
$key = 'inAns';
$ind = 0;
foreach ($inAns as $item){
  if ($item != '') $xml .= '<'.$item.'>'.$result[$key][$ind].'</'.$item.'> ';
  $ind++;
}
$key = 'cptVals';
$ind = 0;
foreach ($cptVals as $item){
  if ($item != '') {
    if ($result[$key][$ind]<=$max_int_pos) {
      $xml .= '<'.$item.'>'.($result[$key][$ind]/10).'</'.$item.'> ';
    }
    else {
      $result[$key][$ind] = ($result[$key][$ind]-$max_int)/10;
      $xml .= '<'.$item.'>'.$result[$key][$ind].'</'.$item.'> ';
    }
  $ind++;}
}
$key = 'paramSys';
$ind = 0;
foreach ($paramSys as $item){
  if ($item != '') $xml .= '<'.$item.'>'.$result[$key][$ind].'</'.$item.'> ';
    $ind++;
}
$xml .= '<cmd1>'.$arr_cmds[$cmds[1]].'</cmd1> '.'<cmd2>'.$arr_cmds[$cmds[2]].'</cmd2> ';
$key = 'cmdPos';$ind = 7;
$xml .= '<'.$cmdPos[$ind].'>'.$arr_tests[$result[$key][$ind]].'</'.$cmdPos[$ind].'>';
$xml .= PHP_EOL.'   </current>'.PHP_EOL;
foreach ($result as $key => $value){
  $xml .= '   <'.$key.' ';
  foreach ($result[$key] as $key1 => $value1){
    $xml .= 'v'.$key1.'="'.$value1.'" ';
  }
  $xml .= '/>'.PHP_EOL;
}
$xml .= ' </root>'.PHP_EOL;
echo $xml;
?>
eedomus+, Zibase V1, RFP1000, RFXcom, RadioDriver CPL 630 X2D, capteurs puissance OWL, thermometres Oregon, téléinfo (USB Linky), detecteurs ouverture X2D, pilotage chauffage X2D, Ecoflow River PRO, PAC Shogun (Atlantic-Cozytouch)
opa95
 
Messages : 723
Inscription : 04 Fév 2019
Localisation : Val d'Oise

Re: MPVSUN

Messagepar Scalaire » 07 Fév 2023 15:53

Bonjour,
Une remarque, le routeur dans sa configuration max peut gérer 4 entrées(pinces ampermetriques) et 4 sorties( relais ssr ou contact sec) ainsi que jusqu'a 8 sondes de températures, peut être que certains utilisateurs pourraient avoir l'utilité de les suivre ou de les piloter avec l'eedomus .....
Pour ma part, cette version est top.
Merci.
Scalaire
 
Messages : 9
Inscription : 21 Jan 2021

Re: MPVSUN

Messagepar opa95 » 07 Fév 2023 16:04

Bonjour Scalaire et merci :)
Scalaire a écrit:Bonjour,
Une remarque, le routeur dans sa configuration max peut gérer 4 entrées(pinces ampermetriques) et 4 sorties( relais ssr ou contact sec) ainsi que jusqu'a 8 sondes de températures, peut être que certains utilisateurs pourraient avoir l'utilité de les suivre ou de les piloter avec l'eedomus .....
Pour ma part, cette version est top.
Merci.

Les données sont accessibles avec les appels de type //champ/@vi (i de 0 à 15).
Si on veut plus convivial, il faut me donner la position et les noms des valeurs, ce sera intégré très rapidement et ça restera compatible avec les anciennes versions. :)
eedomus+, Zibase V1, RFP1000, RFXcom, RadioDriver CPL 630 X2D, capteurs puissance OWL, thermometres Oregon, téléinfo (USB Linky), detecteurs ouverture X2D, pilotage chauffage X2D, Ecoflow River PRO, PAC Shogun (Atlantic-Cozytouch)
opa95
 
Messages : 723
Inscription : 04 Fév 2019
Localisation : Val d'Oise

Re: MPVSUN

Messagepar flc85 » 11 Fév 2023 17:08

Bonjour,
J'ai testé les commandes (cmdtest) elles ne fonctionne pas.
flc85
 
Messages : 70
Inscription : 17 Jan 2019

Re: MPVSUN

Messagepar opa95 » 11 Fév 2023 18:07

Bonsoir jlc85
flc85 a écrit:Bonjour,
J'ai testé les commandes (cmdtest) elles ne fonctionne pas.

Je ne peux tester que la partie logicielle et pas l'effet sur MSUNPV car je ne l"ai pas.
J'ai rajoute un debug
depuis la fenêtre test envoie
http://localhost/script/?exec=MSUNPV.ph ... on&debug=1
et observe le résultat, moi j'ai 192.168.x.y/index.xml?parS=9;0;0;0;0;0;0;1
mais je ne peux pas l'envoyer.
qu'y a-t-il dans //message?
Est-ce que cmd1 fonctionne?
Voici le code avec debug :)
Code : Tout sélectionner
<?php
/****************************************************************************
* optimisateur de production solaire MSUNPV.php por eedomus
* V1.0 : opa95 2023-02-03 niveaux instantanes
* V1.1 : opa95 2023-02-05 généralisation tests par flc85 et Scalaire
* V1.2 : opa95 2023-02-07 modification des commandes tests par flc85
* ligne decommande http://localhost/script/?exec=MSUNPV.php&url=[VAR1]
* ligne decommande http://localhost/script/?exec=MSUNPV&php&url=[VAR1]&cmd1=a
* ligne decommande http://localhost/script/?exec=MSUNPV&php&url=[VAR1]&cmd2=b
* avec VAR1 : adresse ip du MSUNPV
* avec a et b = 0 ou off, 1 ou manuel, 2 ou auto
* ligne decommande http://localhost/script/?exec=MSUNPV&php&url=[VAR1]&cmdtest=c
* avec c = 1 ou injection, 2 ou zero_injection, 4 ou moyen, 8 ou fort
* récupération avec un capteur HTTP
*Récupération des valeurs dans XPATH par //champ/@vi (i de 0 à 15)
* //rtcc/@v0
* //paramSys/@v0 à //paramSys/@v11
* //inAns/@v0 à //inAns/@v15
* //survMm/@v0 à //survMm/@v15
* //cmdPos/@v0 à //cmdPos/@v7
* //outStat/@v0 à //outStat/@v15
* //cptVals/@v0 à //cptVals/@v7
* //chOutVal/@v0 à //chOutVal/@v7
*Récuperations ciblées
* //time //timestamp //conso //production> //routage_1 //routage_2 //tension
* //powbal1 //powbal2 //enConso //enProd //enPV_J //enPV_P
* //heure //date //etat //intervalle //nom //version //sn //cmd1 //cmd2 //test_routeur
*Envoi de commande avec un actionneur HTTP
* pour cmd1, mettre les valeurs [Valeur Brute, Description,URL] et l'équivalent pour cmd2
* 0 off http://localhost/script/?exec=MSUNPV.php&url=[VAR1]&cmd1=0
* 1 manuel http://localhost/script/?exec=MSUNPV.php&url=[VAR1]&cmd1=1
* 2 manuel http://localhost/script/?exec=MSUNPV.php&url=[VAR1]&cmd1=2
* pour cmdtest, mettre les valeurs
* 1 injection http://localhost/script/?exec=MSUNPV.php&url=[VAR1]&cmdtest=1
* 2 zero_injection http://localhost/script/?exec=MSUNPV.php&url=[VAR1]&cmdtest=2
* 4 moyen http://localhost/script/?exec=MSUNPV.php&url=[VAR1]&cmdtest=4
* 8 fort http://localhost/script/?exec=MSUNPV.php&url=[VAR1]&cmdtest=8
* en rajoutant &debug=1 dans la chaîne de commande on a d'autres informations. 
*Contenu du xml renvoyé (exemple)
<?xml version="1.0" encoding="UTF-8"?>
 <root>
   <time>2023-02-05 14:16:45</time>
   <timestamp>1675603005</timestamp>
   <current>
     <conso>-1957.3</conso> <production>-5953.5</production> <routage_1>400</routage_1>
     <routage_2>400</routage_2> <tension>227.5</tension> <powbal1>1.1</powbal1>
     <powbal2>2917.7</powbal2> <enConso>9042.6</enConso> <enProd>-118.1</enProd>
     <enPV_J>-7772.8</enPV_J> <enPV_P>-1416199.2</enPV_P> <heure>14:16:45</heure>
     <date>05/02/2023</date> <etat>On</etat> <intervalle>01:00</intervalle>
     <nom>MS_PV4_2</nom> <version>5.0.1</version> <sn>dl0420a</sn>
     <cmd1>auto</cmd1> <cmd2>auto</cmd2> <test_routeur>zero_injection</test_routeur>
   </current>
   <rtcc v0="14:16:44 DI" />
   <paramSys v0="14:16:45" v1="05/02/2023" v2="On" v3="01:00" v4="0.0" v5="MS_PV4_2" v6="5.0.1"
     v7="dl0420a" v8="102e" v9="102c" v10="00:00" v11="00:00" />
   <inAns v0="-1957.3" v1="-5953.5" v2="400" v3="400" v4="227.5" v5="1.1" v6="2917.7" v7="0.0"
     v8="0.0" v9="0.0" v10="0.0" v11="0.0" v12="0.0" v13="0.0" v14="0.0" v15="0.0" />
   <survMm v0="0" v1="0" v2="0" v3="0" v4="0" v5="0" v6="0" v7="0" v8="0" v9="0"
     v10="0" v11="0" v12="0" v13="0" v14="0" v15="0" />
   <cmdPos v0="10" v1="0" v2="0" v3="0" v4="0" v5="0" v6="0" v7="2" />
   <outStat v0="100" v1="100" v2="0" v3="0" v4="0" v5="0" v6="0" v7="0"
     v8="0" v9="0" v10="0" v11="0" v12="0" v13="0" v14="0" v15="0" />
   <cptVals v0="90426" v1="-118.1" v2="-7772.8" v3="-1416199.2" v4="0" v5="0" v6="0" v7="0" />
   <chOutVal v0="0" v1="0" v2="0" v3="255" v4="0" v5="0" v6="0" v7="0" />
 </root>
**************************************************************************/

function sdk_set_command($cmd1,$cmd2) {//$command 0,1,2)
  $cmd1 = min($cmd1%4,2);
  $cmd2 = min($cmd2%4,2);
  $command = $cmd1 + 4*$cmd2;
  if ($command == 10) $command = 'a';
  return $command;//nombre entre 0 et 10
}

function sdk_get_command($command) {//$command entre 0 et 10, select 0 ou 1
  if (strtolower($command) == 'a') $command = 10;
  $command = min($command,10);
  $arr_cmd[1] = $command%4;
  $arr_cmd[2] = round(($command - $arr_cmd[1])/4);
  return $arr_cmd;
}

function sdk_num_command($cmd) {//$cmd off, manuel, auto
  $cmd = trim(strtolower($cmd));
  switch ($cmd) {
    case '0' :
    case 'off'    : $cmd = 0;
                    break;
    case '1' :
    case 'manuel' : $cmd = 1;
                    break;
    case '2' :
    case 'auto'   : $cmd = 2;
                    break;
    default :       $cmd = '*';
  }
  return $cmd;               
}

$hexa = array('cmdPos','cptVals','chOutVal');//Champ hexa
$inAns = array('conso','production','routage_1','routage_2','tension','powbal1','powbal2');
$cptVals = array('enConso','enProd','enPV_J','enPV_P');
$paramSys = array('heure','date','etat','intervalle','','nom','version','sn');
$cmdPos = array('cmd0','','','','','','','test_routeur');
$arr_cmds = array('off','manuel','auto');
$arr_tests = array(1 => 'injection',2 => 'zero_injection',4 => 'moyen',8 => 'fort');
$max_int_pos = 0X100000000;
$max_int = ($max_int_pos+1)*2;
$url_  = getArg('url');
$url  = $url_.'/status.xml';
$url_cmd  = $url_.'/index.xml';
$cmd1_  = sdk_num_command(getArg('cmd1',false,''));
$cmd2_  = sdk_num_command(getArg('cmd2',false,''));
$cmd_test_  = getArg('cmdtest',false,'0');
$debug = getArg('debug',false,0);
$debug_str ='   <debug>'.PHP_EOL;
if (in_array($cmd_test_, array(1,2,4,8))) { $cmd_test = $cmd_test_;}
  else {
  $cmd_test = 0;
  foreach($arr_tests as $key => $item) {
    if ($cmd_test_ == $item) {
      $cmd_test = $key;
      break;
    }
  }
}
$response = httpQuery($url, 'GET', '','', $header);
$response1 = xpath($response,'cmdPos');
$old_command = explode(';',$response1);
$old_cmds = sdk_get_command($old_command[0]);
if ($cmd1_ === '*') $new_cmds[1] = $old_cmds[1];
else {$new_cmds[1] = $cmd1_; }
if ($cmd2_ === '*') $new_cmds[2] = $old_cmds[2];
else {$new_cmds[2] = $cmd2_;}
if ($cmd_test == 0 ) $cmd_test = $old_command[7];
$is_new_command = ($new_cmds[1] != $old_cmds[1]) || ($new_cmds[2] != $old_cmds[2]) || ($cmd_test != $old_command[7]);
$cmd = sdk_set_command($new_cmds[1],$new_cmds[2]);
if ($is_new_command){
  $parS=$cmd.';';
  foreach ($old_command as $key => $item){
    if ($key == 0) continue;
    if ($key == 7) break;
    $parS .= $item.';';
  }
  $parS = str_replace(';;',';',$parS.$cmd_test);
  $url1 = $url_cmd.'?parS='.$parS;
  $debug_str .='     <command>'.$url1.'</command>';
  $response = httpQuery($url1, 'POST', '','', $header);
  $debug_str .='<message>'.$response.'</message>';

}

$response = xpath($response,"concat('rtcc=',//rtcc,'@paramSys=',//paramSys,'@inAns=',//inAns,'@survMm=',//survMm,'@cmdPos=',//cmdPos,'@outStat=',//outStat,'@cptVals=',//cptVals,'@chOutVal=',//chOutVal)");
$response = trim(str_replace(';@','@',$response));
$response = str_replace(',','.',$response);
$arr_response = explode('@',$response);
foreach ($arr_response as $field) {
  list($key,$values) = explode('=',$field);
  $arrValue = array();
  $arr_values = explode(';',$values);
  if (in_array($key,$hexa)) {
    foreach ($arr_values as $value){
      $value = trim($value);
      if ($value != '') {$result[$key][] = hexdec($value);}
    }
  }
  else {
    foreach ($arr_values as $value){
      $value = trim($value);
      if ($value != '') $result[$key][] = $value;
    }
  }
}
//var_dump($result);
$cmds = sdk_get_command($result['cmdPos'][0]);
$heure = $result['paramSys'][0];
list($day,$month,$year) = explode('/',$result['paramSys'][1]);
$date = $year.'-'.$month.'-'.$day;
$timestamp = strtotime($date.' '.$heure);
$time = date('Y-m-d H:i:s',$timestamp);
$debug_str .= PHP_EOL.'   </debug>'.PHP_EOL;
@sdk_header('text/xml');
$xml = '<?xml version="1.0" encoding="UTF-8"?>'.PHP_EOL;
$xml .= ' <root>'.PHP_EOL;
$xml .= '   <time>'.$time.'</time> '.PHP_EOL;;
$xml .= '   <timestamp>'.$timestamp.'</timestamp>'.PHP_EOL;;
$xml .= '   <current>'.PHP_EOL.'     '; 
$key = 'inAns';
$ind = 0;
foreach ($inAns as $item){
  if ($item != '') $xml .= '<'.$item.'>'.$result[$key][$ind].'</'.$item.'> ';
  $ind++;
}
$key = 'cptVals';
$ind = 0;
foreach ($cptVals as $item){
  if ($item != '') {
    if ($result[$key][$ind]<=$max_int_pos) {
      $xml .= '<'.$item.'>'.($result[$key][$ind]/10).'</'.$item.'> ';
    }
    else {
      $result[$key][$ind] = ($result[$key][$ind]-$max_int)/10;
      $xml .= '<'.$item.'>'.$result[$key][$ind].'</'.$item.'> ';
    }
  $ind++;}
}
$key = 'paramSys';
$ind = 0;
foreach ($paramSys as $item){
  if ($item != '') $xml .= '<'.$item.'>'.$result[$key][$ind].'</'.$item.'> ';
    $ind++;
}
$xml .= '<cmd1>'.$arr_cmds[$cmds[1]].'</cmd1> '.'<cmd2>'.$arr_cmds[$cmds[2]].'</cmd2> ';
$key = 'cmdPos';$ind = 7;
$xml .= '<'.$cmdPos[$ind].'>'.$arr_tests[$result[$key][$ind]].'</'.$cmdPos[$ind].'>';
$xml .= PHP_EOL.'   </current>'.PHP_EOL;
foreach ($result as $key => $value){
  $xml .= '   <'.$key.' ';
  foreach ($result[$key] as $key1 => $value1){
    $xml .= 'v'.$key1.'="'.$value1.'" ';
  }
  $xml .= '/>'.PHP_EOL;
}
if ($debug) $xml .= $debug_str;
$xml .= ' </root>'.PHP_EOL;
echo $xml;
?>
eedomus+, Zibase V1, RFP1000, RFXcom, RadioDriver CPL 630 X2D, capteurs puissance OWL, thermometres Oregon, téléinfo (USB Linky), detecteurs ouverture X2D, pilotage chauffage X2D, Ecoflow River PRO, PAC Shogun (Atlantic-Cozytouch)
opa95
 
Messages : 723
Inscription : 04 Fév 2019
Localisation : Val d'Oise

Re: MPVSUN

Messagepar flc85 » 11 Fév 2023 18:16

voilà le résultat je n'ai rien en debug
Code : Tout sélectionner
<?xml version="1.0" encoding="UTF-8"?>
 <root>
   <time>2023-02-11 18:13:37</time>
   <timestamp>1676135617</timestamp>
   <current>
     <conso>369.2</conso> <production>-19.5</production> <routage_1>0</routage_1> <routage_2>0</routage_2> <tension>218.4</tension> <powbal1>0.0</powbal1> <powbal2>0.0</powbal2> <enConso>4592.7</enConso> <enProd>-2.4</enProd> <enPV_J>-6209.2</enPV_J> <enPV_P>-1273420.5</enPV_P> <heure>18:13:37</heure> <date>11/02/2023</date> <etat>On</etat> <intervalle>01:00</intervalle> <nom>MS_PV2_2</nom> <version>5.0.1</version> <sn>0000220</sn> <cmd1>off</cmd1> <cmd2>off</cmd2> <test_routeur>zero_injection</test_routeur>
   </current>
   <rtcc v0="18:13:36 SA" />
   <paramSys v0="18:13:37" v1="11/02/2023" v2="On" v3="01:00" v4="0.0" v5="MS_PV2_2" v6="5.0.1" v7="0000220" v8="102e" v9="102c" v10="00:00" v11="00:00" />
   <inAns v0="369.2" v1="-19.5" v2="0" v3="0" v4="218.4" v5="0.0" v6="0.0" v7="0.0" v8="0" v9="0" v10="0" v11="0" v12="0" v13="0" v14="0" v15="0" />
   <survMm v0="0" v1="0" v2="0" v3="0" v4="0" v5="0" v6="0" v7="0" v8="0" v9="0" v10="0" v11="0" v12="0" v13="0" v14="0" v15="0" />
   <cmdPos v0="0" v1="0" v2="0" v3="0" v4="0" v5="0" v6="0" v7="2" />
   <outStat v0="0" v1="0" v2="0" v3="0" v4="0" v5="0" v6="0" v7="0" v8="0" v9="0" v10="0" v11="0" v12="0" v13="0" v14="0" v15="0" />
   <cptVals v0="45927" v1="-2.4" v2="-6209.2" v3="-1273420.5" v4="0" v5="0" v6="0" v7="0" />
   <chOutVal v0="0" v1="0" v2="0" v3="255" v4="0" v5="0" v6="0" v7="0" />
   <debug>

   </debug>
 </root>
flc85
 
Messages : 70
Inscription : 17 Jan 2019

Re: MPVSUN

Messagepar flc85 » 11 Fév 2023 18:21

attends je n'ai pas mis "injection" mais "1"
http://localhost/script/?exec=MSUNPV2.p ... =1&debug=1

AVEC

http://localhost/script/?exec=MSUNPV2.p ... on&debug=1


Code : Tout sélectionner
<?xml version="1.0" encoding="UTF-8"?>
 <root>
   <time>2023-02-11 18:17:45</time>
   <timestamp>1676135865</timestamp>
   <current>
     <conso></conso> <production></production> <routage_1></routage_1> <routage_2></routage_2> <tension></tension> <powbal1></powbal1> <powbal2></powbal2> <enConso>0</enConso> <enProd>0</enProd> <enPV_J>0</enPV_J> <enPV_P>0</enPV_P> <heure>18:17:45</heure> <date>11/02/2023</date> <etat>On</etat> <intervalle>01:00</intervalle> <nom>MS_PV2_2</nom> <version>5.0.1</version> <sn>0000220</sn> <cmd1>off</cmd1> <cmd2>off</cmd2> <test_routeur></test_routeur>
   </current>
   <paramSys v0="18:17:45" v1="11/02/2023" v2="On" v3="01:00" v4="0.0" v5="MS_PV2_2" v6="5.0.1" v7="0000220" v8="102e" v9="102c" v10="00:00" v11="00:00" />
   <debug>
     <command>192.168.1.247/index.xml?parS=0;0;0;0;0;0;0;1</command><message><?xml version="1.0" encoding="ISO-8859-1"?><xml>
<paramSys>18:17:45;11/02/2023;On;01:00;0,0;MS_PV2_2;5.0.1;0000220;102e;102c;00:00;00:00</paramSys>
<typAns>PowRéso;1;6:PowP.V;1;6:OutBal;0;3:OutRad;0;3:VoltRés;1;4:T_Bal1;1;18:T_SDB;1;18:T_Amb;1;18:S9;0;0:S10;0;0:S11;0;0:S12;0;0:S13;0;0:S14;0;0:S15;0;0:S16;0;0:</typAns>
<typouts>R_Bal1;0;2:Rad_SDB;0;2:A3;0;0:A4;0;0:A5;0;0:A6;0;0:A7;0;0:A8;0;0:A9;0;0:A10;0;0:A11;0;0:A12;0;0:A13;0;0:A14;0;0:A15;0;0:A16;0;0:</typouts>
<cmdM0>3;0;Comd Manu/Auto;ManuBal;AutoBal;ManuRad;AutoRad;</cmdM0>
<cmdM1>0;0;Commande 2;Param1;Param2;Param3;Param4;</cmdM1>
<cmdM2>0;0;Commande 3;Param1;Param2;Param3;Param4;</cmdM2>
<cmdM3>0;0;Commande 4;Param1;Param2;Param3;Param4;</cmdM3>
<cmdM4>0;0;Commande 5;Param1;Param2;Param3;Param4;</cmdM4>
<cmdM5>0;0;Commande 6;Param1;Param2;Param3;Param4;</cmdM5>
<cmdM6>0;0;Commande 7;Param1;Param2;Param3;Param4;</cmdM6>
<cmdM7>1;0;Test routeur;Inject;Zéro;Moyen;Fort;</cmdM7>
<typCpt>EnConso;1;16:EnInj;1;16:EnPV_J;1;16:EnPV_P;1;16:Compt 5;0;0:Compt 6;0;0:Compt 7;0;0:Compt 8;0;0:</typCpt>
</xml></message>
   </debug>
 </root>
flc85
 
Messages : 70
Inscription : 17 Jan 2019

Re: MPVSUN

Messagepar opa95 » 11 Fév 2023 20:41

Bonsoir

Il manquait peut-être un ";"
Voici avec la correction. :)
Code : Tout sélectionner
<?php
/****************************************************************************
* optimisateur de production solaire MSUNPV.php por eedomus
* V1.0 : opa95 2023-02-03 niveaux instantanes
* V1.1 : opa95 2023-02-05 généralisation tests par flc85 et Scalaire
* V1.2 : opa95 2023-02-07 modification des commandes tests par flc85
* ligne decommande http://localhost/script/?exec=MSUNPV.php&url=[VAR1]
* ligne decommande http://localhost/script/?exec=MSUNPV&php&url=[VAR1]&cmd1=a
* ligne decommande http://localhost/script/?exec=MSUNPV&php&url=[VAR1]&cmd2=b
* avec VAR1 : adresse ip du MSUNPV
* avec a et b = 0 ou off, 1 ou manuel, 2 ou auto
* ligne decommande http://localhost/script/?exec=MSUNPV&php&url=[VAR1]&cmdtest=c
* avec c = 1 ou injection, 2 ou zero_injection, 4 ou moyen, 8 ou fort
* récupération avec un capteur HTTP
*Récupération des valeurs dans XPATH par //champ/@vi (i de 0 à 15)
* //rtcc/@v0
* //paramSys/@v0 à //paramSys/@v11
* //inAns/@v0 à //inAns/@v15
* //survMm/@v0 à //survMm/@v15
* //cmdPos/@v0 à //cmdPos/@v7
* //outStat/@v0 à //outStat/@v15
* //cptVals/@v0 à //cptVals/@v7
* //chOutVal/@v0 à //chOutVal/@v7
*Récuperations ciblées
* //time //timestamp //conso //production> //routage_1 //routage_2 //tension
* //powbal1 //powbal2 //enConso //enProd //enPV_J //enPV_P
* //heure //date //etat //intervalle //nom //version //sn //cmd1 //cmd2 //test_routeur
*Envoi de commande avec un actionneur HTTP
* pour cmd1, mettre les valeurs [Valeur Brute, Description,URL] et l'équivalent pour cmd2
* 0 off http://localhost/script/?exec=MSUNPV.php&url=[VAR1]&cmd1=0
* 1 manuel http://localhost/script/?exec=MSUNPV.php&url=[VAR1]&cmd1=1
* 2 manuel http://localhost/script/?exec=MSUNPV.php&url=[VAR1]&cmd1=2
* pour cmdtest, mettre les valeurs
* 1 injection http://localhost/script/?exec=MSUNPV.php&url=[VAR1]&cmdtest=1
* 2 zero_injection http://localhost/script/?exec=MSUNPV.php&url=[VAR1]&cmdtest=2
* 4 moyen http://localhost/script/?exec=MSUNPV.php&url=[VAR1]&cmdtest=4
* 8 fort http://localhost/script/?exec=MSUNPV.php&url=[VAR1]&cmdtest=8
*Contenu du xml renvoyé (exemple)
<?xml version="1.0" encoding="UTF-8"?>
 <root>
   <time>2023-02-05 14:16:45</time>
   <timestamp>1675603005</timestamp>
   <current>
     <conso>-1957.3</conso> <production>-5953.5</production> <routage_1>400</routage_1>
     <routage_2>400</routage_2> <tension>227.5</tension> <powbal1>1.1</powbal1>
     <powbal2>2917.7</powbal2> <enConso>9042.6</enConso> <enProd>-118.1</enProd>
     <enPV_J>-7772.8</enPV_J> <enPV_P>-1416199.2</enPV_P> <heure>14:16:45</heure>
     <date>05/02/2023</date> <etat>On</etat> <intervalle>01:00</intervalle>
     <nom>MS_PV4_2</nom> <version>5.0.1</version> <sn>dl0420a</sn>
     <cmd1>auto</cmd1> <cmd2>auto</cmd2> <test_routeur>zero_injection</test_routeur>
   </current>
   <rtcc v0="14:16:44 DI" />
   <paramSys v0="14:16:45" v1="05/02/2023" v2="On" v3="01:00" v4="0.0" v5="MS_PV4_2" v6="5.0.1"
     v7="dl0420a" v8="102e" v9="102c" v10="00:00" v11="00:00" />
   <inAns v0="-1957.3" v1="-5953.5" v2="400" v3="400" v4="227.5" v5="1.1" v6="2917.7" v7="0.0"
     v8="0.0" v9="0.0" v10="0.0" v11="0.0" v12="0.0" v13="0.0" v14="0.0" v15="0.0" />
   <survMm v0="0" v1="0" v2="0" v3="0" v4="0" v5="0" v6="0" v7="0" v8="0" v9="0"
     v10="0" v11="0" v12="0" v13="0" v14="0" v15="0" />
   <cmdPos v0="10" v1="0" v2="0" v3="0" v4="0" v5="0" v6="0" v7="2" />
   <outStat v0="100" v1="100" v2="0" v3="0" v4="0" v5="0" v6="0" v7="0"
     v8="0" v9="0" v10="0" v11="0" v12="0" v13="0" v14="0" v15="0" />
   <cptVals v0="90426" v1="-118.1" v2="-7772.8" v3="-1416199.2" v4="0" v5="0" v6="0" v7="0" />
   <chOutVal v0="0" v1="0" v2="0" v3="255" v4="0" v5="0" v6="0" v7="0" />
 </root>
**************************************************************************/

function sdk_set_command($cmd1,$cmd2) {//$command 0,1,2)
  $cmd1 = min($cmd1%4,2);
  $cmd2 = min($cmd2%4,2);
  $command = $cmd1 + 4*$cmd2;
  if ($command == 10) $command = 'a';
  return $command;//nombre entre 0 et 10
}

function sdk_get_command($command) {//$command entre 0 et 10, select 0 ou 1
  if (strtolower($command) == 'a') $command = 10;
  $command = min($command,10);
  $arr_cmd[1] = $command%4;
  $arr_cmd[2] = round(($command - $arr_cmd[1])/4);
  return $arr_cmd;
}

function sdk_num_command($cmd) {//$cmd off, manuel, auto
  $cmd = trim(strtolower($cmd));
  switch ($cmd) {
    case '0' :
    case 'off'    : $cmd = 0;
                    break;
    case '1' :
    case 'manuel' : $cmd = 1;
                    break;
    case '2' :
    case 'auto'   : $cmd = 2;
                    break;
    default :       $cmd = '*';
  }
  return $cmd;               
}

$hexa = array('cmdPos','cptVals','chOutVal');//Champ hexa
$inAns = array('conso','production','routage_1','routage_2','tension','powbal1','powbal2');
$cptVals = array('enConso','enProd','enPV_J','enPV_P');
$paramSys = array('heure','date','etat','intervalle','','nom','version','sn');
$cmdPos = array('cmd0','','','','','','','test_routeur');
$arr_cmds = array('off','manuel','auto');
$arr_tests = array(1 => 'injection',2 => 'zero_injection',4 => 'moyen',8 => 'fort');
$max_int_pos = 0X100000000;
$max_int = ($max_int_pos+1)*2;
$url_  = getArg('url');
$url  = $url_.'/status.xml';
$url_cmd  = $url_.'/index.xml';
$cmd1_  = sdk_num_command(getArg('cmd1',false,''));
$cmd2_  = sdk_num_command(getArg('cmd2',false,''));
$cmd_test_  = getArg('cmdtest',false,'0');
$debug = getArg('debug',false,0);
$debug_str ='   <debug>'.PHP_EOL;
if (in_array($cmd_test_, array(1,2,4,8))) { $cmd_test = $cmd_test_;}
  else {
  $cmd_test = 0;
  foreach($arr_tests as $key => $item) {
    if ($cmd_test_ == $item) {
      $cmd_test = $key;
      break;
    }
  }
}
$response = httpQuery($url, 'GET', '','', $header);
$response1 = xpath($response,'cmdPos');
$old_command = explode(';',$response1);
$old_cmds = sdk_get_command($old_command[0]);
if ($cmd1_ === '*') $new_cmds[1] = $old_cmds[1];
else {$new_cmds[1] = $cmd1_; }
if ($cmd2_ === '*') $new_cmds[2] = $old_cmds[2];
else {$new_cmds[2] = $cmd2_;}
if ($cmd_test == 0 ) $cmd_test = $old_command[7];
$is_new_command = ($new_cmds[1] != $old_cmds[1]) || ($new_cmds[2] != $old_cmds[2]) || ($cmd_test != $old_command[7]);
$cmd = sdk_set_command($new_cmds[1],$new_cmds[2]);
if ($is_new_command){
  $parS=$cmd.';';
  foreach ($old_command as $key => $item){
    if ($key == 0) continue;
    if ($key == 7) break;
    $parS .= $item.';';
  }
  $parS = str_replace(';;',';',$parS.$cmd_test.';');
  $url1 = $url_cmd.'?parS='.$parS;
  $debug_str .='     <command>'.$url1.'</command>';
  $response = httpQuery($url1, 'POST', '','', $header);
  $debug_str .='<message>'.$response.'</message>';

}

$response = xpath($response,"concat('rtcc=',//rtcc,'@paramSys=',//paramSys,'@inAns=',//inAns,'@survMm=',//survMm,'@cmdPos=',//cmdPos,'@outStat=',//outStat,'@cptVals=',//cptVals,'@chOutVal=',//chOutVal)");
$response = trim(str_replace(';@','@',$response));
$response = str_replace(',','.',$response);
$arr_response = explode('@',$response);
foreach ($arr_response as $field) {
  list($key,$values) = explode('=',$field);
  $arrValue = array();
  $arr_values = explode(';',$values);
  if (in_array($key,$hexa)) {
    foreach ($arr_values as $value){
      $value = trim($value);
      if ($value != '') {$result[$key][] = hexdec($value);}
    }
  }
  else {
    foreach ($arr_values as $value){
      $value = trim($value);
      if ($value != '') $result[$key][] = $value;
    }
  }
}
//var_dump($result);
$cmds = sdk_get_command($result['cmdPos'][0]);
$heure = $result['paramSys'][0];
list($day,$month,$year) = explode('/',$result['paramSys'][1]);
$date = $year.'-'.$month.'-'.$day;
$timestamp = strtotime($date.' '.$heure);
$time = date('Y-m-d H:i:s',$timestamp);
$debug_str .= PHP_EOL.'   </debug>'.PHP_EOL;
@sdk_header('text/xml');
$xml = '<?xml version="1.0" encoding="UTF-8"?>'.PHP_EOL;
$xml .= ' <root>'.PHP_EOL;
$xml .= '   <time>'.$time.'</time> '.PHP_EOL;;
$xml .= '   <timestamp>'.$timestamp.'</timestamp>'.PHP_EOL;;
$xml .= '   <current>'.PHP_EOL.'     '; 
$key = 'inAns';
$ind = 0;
foreach ($inAns as $item){
  if ($item != '') $xml .= '<'.$item.'>'.$result[$key][$ind].'</'.$item.'> ';
  $ind++;
}
$key = 'cptVals';
$ind = 0;
foreach ($cptVals as $item){
  if ($item != '') {
    if ($result[$key][$ind]<=$max_int_pos) {
      $xml .= '<'.$item.'>'.($result[$key][$ind]/10).'</'.$item.'> ';
    }
    else {
      $result[$key][$ind] = ($result[$key][$ind]-$max_int)/10;
      $xml .= '<'.$item.'>'.$result[$key][$ind].'</'.$item.'> ';
    }
  $ind++;}
}
$key = 'paramSys';
$ind = 0;
foreach ($paramSys as $item){
  if ($item != '') $xml .= '<'.$item.'>'.$result[$key][$ind].'</'.$item.'> ';
    $ind++;
}
$xml .= '<cmd1>'.$arr_cmds[$cmds[1]].'</cmd1> '.'<cmd2>'.$arr_cmds[$cmds[2]].'</cmd2> ';
$key = 'cmdPos';$ind = 7;
$xml .= '<'.$cmdPos[$ind].'>'.$arr_tests[$result[$key][$ind]].'</'.$cmdPos[$ind].'>';
$xml .= PHP_EOL.'   </current>'.PHP_EOL;
foreach ($result as $key => $value){
  $xml .= '   <'.$key.' ';
  foreach ($result[$key] as $key1 => $value1){
    $xml .= 'v'.$key1.'="'.$value1.'" ';
  }
  $xml .= '/>'.PHP_EOL;
}
if ($debug) $xml .= $debug_str;
$xml .= ' </root>'.PHP_EOL;
echo $xml;
?>
eedomus+, Zibase V1, RFP1000, RFXcom, RadioDriver CPL 630 X2D, capteurs puissance OWL, thermometres Oregon, téléinfo (USB Linky), detecteurs ouverture X2D, pilotage chauffage X2D, Ecoflow River PRO, PAC Shogun (Atlantic-Cozytouch)
opa95
 
Messages : 723
Inscription : 04 Fév 2019
Localisation : Val d'Oise

PrécédentSuivant

Retour vers API eedomus & eedomus toolbox

Qui est en ligne ?

Utilisateurs parcourant ce forum : Aucun utilisateur inscrit et 5 invité(s)