Keine Ahnung, wie der Verkehrsbetrieb das handhabt…. Eventuell gibt es da temporär andere Liniennummern, oder Haltestelllen. Ich häng in dem ganzen nicht wirklich drinn.
Ankündigung
Einklappen
Keine Ankündigung bisher.
LBS - 19001751 Hafas Client (OePNV Monitor)
Einklappen
X
-
Ich nochmal,
die Formatierung der Liste an A23 wird doch mit dein Werten von E19 vorgenommen.
An E19 hab ich folgende WerteAn A23 bekomme ich10|10|10|60|10#10|10|10|60|10Wenn ich da nachzähle, sind das 6 Spalten. In der Hilfe ist aber nur von 5 Spalten die Rede und an E19 werden auch nur 5 Werte für die Spaltenbreite (in Prozent?) angegeben.***W:4*A:center|Abfahrtsmonitor***W:13*A:left|***W :11*A:left|***W:14*A:left|Lichtenrader Damm/Barnetstr.***W:34*A:left|***W:9*A:left|§|Abfahrt|E rwartet|Linie|in Richtung|Bahnsteig§|00:29||M76|U Walther-Schreiber-Platz|§|00:59||M76|U Walther-Schreiber-Platz|§
Kannst du mich bitte erleuchten?
Danke!
Kommentar
-
Servus zusammen,
da ich heute auf den LXC Container umgestiegen bin, musste ich den hafas client neu installieren. Da er in der usprünglichen Version 14 von NodeJs lief, der neue hafas Client aber mind. Version 18 haben wollte, habe ich (danke KI) heute den gesamte Code mal auf "neu" umbauen lassen. Zumindest sind alle Anpassungen für aktuell
- NodeJS 20.x
- hafas Client 6.3.6
kompatibel.
Hier der Code überarbeitet, falls ihn jemand benutzen möchte:
PHP-Code:###[DEF]###
[name = hafas client]
[e#1 trigger = LBS aktiv ]
[e#2 important = Station ID #init=0013550]
[e#3 optional = Operator #init=insa]
[e#4 important = Verkehrsmittel #init=bus|tram]
[e#5 optional = Vorschau (min) #init=25]
[e#6 optional = Filter Ziel ]
[e#7 optional = max Liste A24 #init=20]
[e#8 optional = long #init=1 ]
[e#9 optional = board type #init=1]
[e#10 optional = Station Name ]
[e#11 optional = Dest Station Name ]
[e#20 optional = Debug #init=0 ]
[a#1 = Json String]
[a#2 = Name]
[a#3 = Zeile 1]
[a#4 = Zeile 2]
[a#5 = Zeile 3]
[a#6 = Zeile 4]
[a#7 = Zeile 5]
[a#8 = Zeile 6]
[a#9 = Zeile 7]
[a#10 = Zeile 8]
[a#11 = Zeile 9]
[a#12 = Zeile 10]
[a#13 = Zeile 11]
[a#14 = Zeile 12]
[a#15 = Zeile 13]
[a#16 = Zeile 14]
[a#17 = Zeile 15]
[a#18 = Zeile 16]
[a#19 = Zeile 17]
[a#20 = Zeile 18]
[a#21 = Zeile 19]
[a#22 = Zeile 20]
[a#23 = Listenelement enhanced]
[a#24 = ID List]
[a#25 = ID Dest List]
[a#26 = xx]
[v#1 remanent =0 ] //alles installiert LBS bereit
[v#2 remanent ={"op":null,"stid":null,"zugnummer":null,"travel_id":null,"alarm_time":null,"dir_filter":null} ] //remanente inputs
[v#100 =0.11 ] //Version
[v#101 =19999984 ] //LBS ID
[v#102 =hafas client ] //LBS Name
[v#103 = 0 ] // Log level
[v#104 = 1 ] // Log per instance
[v#105 = 0 ] // log ID in each line
###[/DEF]###
###[HELP]###
<h2><b>OEPNV live Monitor</b></h2>
<p style="color: #ffffff; background-color: #00ff00">lauffähig unter EDOMI 1.64 und 2.x </p>
<details><summary><b>Changelog</b></summary>
<b>V 0.1</b>
<li>initiale Version</li>
</details>
<details open><summary><b>Installation</b></summary>
Der LBS installiert node_js und den Node hafas-client auf dem Rechner. Sollte die Installation fehlschlagen die benötigten Pakete mittels
yum install -y gcc-c++ make
curl -sL https://rpm.nodesource.com/setup_14.x | sudo -E bash -
sudo yum -y install nodejs
npm -g install hafas-client
auf der konsole installieren
<b>Nodejs wird mindestens in der Version 12.x benötigt.</b>
Die installierte Version kann auf der Konsole mittels 'node -v' herausgefunden werden.
Durch die Installation dauert der erste Start des LBS etwas länger. War die Installation erfolgreich, sollten nach spätestens 2 Minuten Daten ausgegeben werden. Eine erfolgreiche Installation wird durch die LBS Variable 1 mit Wert 1 angezeigt.
mehr Infos über die benutzten Node gibt es hier:
https://github.com/public-transport/hafas-client
</details>
<details><summary><b> Allgemeines</b></summary>
Der LBS wird durch jegliche Änderungen an den Eingängen getriggert. Zusätzlich werden die Daten aller 2 Minuten aktualisiert.
Da die heruntergeladenen Daten schnell über die 10000 Zeichen gehen, wird empfohlen den Ausgang A1 nicht zu verwenden, und stattdessen die heruntergeladenen json Daten selber zu verarbeiten.
Die Daten befinden sich unter /var/tmp/monitor_#id_desLBS#.json
</details>
<details><summary><b>Eingänge</b></summary>
<li><b>E1</b> LBS Ein / Aus (1/0) der LBS aktualisiert die Daten kontinuierlich, ein externes triggern ist nicht nötig.</li>
<li><b>E2</b> id des Bahnhofes (kann mittels E10 / A24 herausgefunden werden)</li>
<li><b>E3</b> Datenlieferant</li>
<details><summary><b>Mögliche Anbieter:</b></summary>
<li>bvg (Verkehrsverbund Berlin-Brandenburg )</li>
<li>cfl (Société Nationale des Chemins de Fer Luxembourgeois)</li>
<li>db (Deutsche Bahn AG)</li>
<li>db-busradar-nrw (DB Rheinlandbus, DB Westfalenbus, DB Ostwestfalen-Lippe-Bus)</li>
<li>hvv (Hamburger Verkehrsverbund)</li>
<li>insa (Informationssystem Nahverkehr Sachsen-Anhalt)</li>
<li>invg (Ingolstädter Verkehrsgesellschaft)</li>
<li>nahsh (Nahverkehrsverbund Schleswig-Holstein)</li>
<li>nvv (Nordhessischer Verkehrsverbund)</li>
<li>oebb (Österreichische Bundesbahnen)</li>
<li>pkp (Polskie Koleje Państwowe)</li>
<li>rmv (Rhein-Main-Verkehrsverbund)</li>
<li>rsag (Rostocker Straßenbahn AG)</li>
<li>saarfahrplan</li>
<li>sbahn-muenchen (S-Bahn München)</li>
<li>sncb (Société nationale des chemins de fer belges)</li>
<li>svv (Salzburger Verkehrsverbund)</li>
<li>vbb (Verkehrsverbund Berlin-Brandenburg)</li>
<li>vbn (Verkehrsverbund Bremen/Niedersachsen)</li>
<li>vmt (Verkehrsverbund Mittelthüringen)</li>
<li>vsn (Verkehrsverbund Süd-Niedersachsen)</li>
</details>
<li><b>E4 anzuzeigende Verkehrsmittel </b> Es müssen nicht alle Verkehrsmittel eingetragen werden, man kann sich z.B auch nur 'tram|bus' ausgeben lassen. Je nach Anbieter unteschiedlich:</li>
<details><summary><b>bvg (Verkehrsverbund Berlin-Brandenburg)</b></summary>
suburban|subway|tram|bus|ferry|express|regional</details>
<details><summary><b>cfl (Société Nationale des Chemins de Fer Luxembourgeois)</b></summary>
express-train|local-train|tram|bus|gondola</details>
<details><summary><b>db (Deutsche Bahn AG)</b></summary>
nationalExpress|national|regionalExp|regional|suburban|bus|ferry|subway|tram|taxi</details>
<details><summary><b>db-busradar-nrw (DB Rheinlandbus, DB Westfalenbus, DB Ostwestfalen-Lippe-Bus)</b></summary>
national-expressnational|regional-express|regional|suburban|bus|ferry|taxi</details>
<details><summary><b>hvv (Hamburger Verkehrsverbund)</b></summary>
subway|suburban|akn|regional-express-train|regional-train|ferry|bus|express-bus|anruf-sammel-taxi|long-distance-train|long-distance-bus</details>
<details><summary><b>insa (Informationssystem Nahverkehr Sachsen-Anhalt)</b></summary>
nationalExpress|national|regional|suburban|tram|bus|tourismTrain</details>
<details><summary><b>invg (Ingolstädter Verkehrsgesellschaft)</b></summary>
bus|express-train|regional-train|local-train|ferry|subway|tram|on-demand</details>
<details><summary><b>nahsh (Nahverkehrsverbund Schleswig-Holstein)</b></summary>
nationalExpress|national|interregional|regional|suburban|bus|ferry|subway|tram|onCall</details>
<details><summary><b>nvv (Nordhessischer Verkehrsverbund)</b></summary>
express|national|regional|regiotram|tram|bus|on-call</details>
<details><summary><b>oebb (Österreichische Bundesbahnen)</b></summary>
nationalExpress|national|interregional|regional|suburban|bus|ferry|subway|tram|onCall</details>
<details><summary><b>pkp (Polskie Koleje Państwowe)</b></summary>
high-speed-train|long-distance-train|regional-train|bus</details>
<details><summary><b>rmv (Rhein-Main-Verkehrsverbund)</b></summary>
express-train|long-distance-train|regiona-train|s-bahn|u-bahn|tram|bus|watercraft|ast|cable-car</details>
<details><summary><b>rsag (Rostocker Straßenbahn AG)</b></summary>
ice|ic-ec|long-distance-train|regional-train|s-bahn|bus|ferry|u-bahn|tram|on-call</details>
<details><summary><b>saarfahrplan </b></summary>
nationalExpress|national|interregional|regional|suburban|subway|saarbahn|bus|watercraft|onCall|school-bus</details>
<details><summary><b>sbahn-muenchen (S-Bahn München)</b></summary>
ice|ic-ecir-d|region|sbahn|bus|ubahn|tram|on-call</details>
<details><summary><b>sncb (Société nationale des chemins de fer belges)</b></summary>
high-speed-train|intercity-p|s-train|local-train|metro|bus|tram</details>
<details><summary><b>svv (Salzburger Verkehrsverbund)</b></summary>
bahn-s-bahn|u-bahn|strassenbahn|fernbus|regionalbus|stadtbus|seilbahn-zahnradbahn|schiff</details>
<details><summary><b>vbb (Verkehrsverbund Berlin-Brandenburg)</b></summary>
suburban|subway|tram|bus|ferry|express|regional</details>
<details><summary><b>vbn (Verkehrsverbund Bremen/Niedersachsen)</b></summary>
express-train|national-train|local-train|suburban|bus|watercraft|subway|tram|dial-a-ride</details>
<details><summary><b>vmt (Verkehrsverbund Mittelthüringen)</b></summary>
long-distance-train|regional-train|tram|bus</details>
<details><summary><b>vsn (Verkehrsverbund Süd-Niedersachsen)</b></summary>
nationalExpress|national|regionalExpress|regional|suburban|bus|ferry|subway|tram|anrufSammelTaxi</details>
<li><b>E5</b> Maximale Vorschauzeit in Minuten</li>
<li><b>E6</b> Zielfilter (nur Anzeige von verkehrsmitteln mit dem an E6 eingegebenen Ziel) Ein leerer Eingang, oder 'Filter entfernen' löscht den Zielfilter, und es werden wieder alle Verbindungen angezeigt</li>
<li><b>E7</b> Maximale Anzahl an Ergebnissen an A24 und A1</li>
<li><b>E8</b> Steuert die Ausgabe an A3-A22</li>
<li><b>E9</b> Board type 0 = Abfahrtsmonitor 1 = Ankunftsmonitor</li>
<li><b>E10</b> Name des Bahnhofes, für den die ID gesucht werden soll. Die besten Ergebnisse erreicht man, wenn man ein '-' an den Namen anhängt. Also anstatt 'Leipzig' 'Leipzig-' verwenden. Die Liste der gefundenen IDs wird an A24 ausgegeben (fertig formatiert für das Listenelement enhanced</li>
<li><b>E11</b> Debug Level</li>
</details>
<details><summary><b>Ausgänge</b></summary>
<li><b>A1</b> json string der Rohdaten (nur wenn kleiner als 10000 Zeichen) </li>
<li><b>A2</b> Name des Bahnhofs</li>
<li><b>A3-A22</b>
bei E8 = 1:
Abfahrtsmonitor:
Format: Abfahrtszeit | Verspätungszeit | Typ und Zugnummer | Richtung | Bahnsteig | Abfahrtszeit als Unixtime
Ankunftsmonitor:
Format:Ankunftszeit | Verspätungszeit | Typ und Zugnummer | aus Richtung | Bahnsteig | Ankunftszeit als Unixtime
bei E8 = 0
Ankunft oder Abfahrtszeit (je nach board type) im Unix Format
<li><b>A23</b> Ausgabe formatiert für das Listenelement enhanced Spaltentrenner "|" Zeilentrenner "#"</li>
<li><b>A24</b> ID Liste (Ergebnisse von E24) formatiert für das Listenelement enhanced Spaltentrenner "|" Zeilentrenner "#" (Suchergebniss Name |id)</li>
<li><b>A25</b> Ausgabe möglicher Zielfilter für E6 formatiert für das Listenelemet enhanced Zeilentrenner '#'</li>
</details>
###[/HELP]###
###[LBS]###
<?
function LB_LBSID($id) {
if ($E=logic_getInputs($id)) {
if (logic_getStateExec($id)==0) { //EXEC-Script läuft noch nicht
logic_setInputsQueued($id,$E); //Eingangsdaten $E in der Queue speichern
logic_callExec(LBSID,$id); //Exec-Script starten
} else {
if(logic_getStateExec($id)==2){ // Nur wenn der exec läuft:
logic_setInputsQueued($id,$E); //Eingangsdaten $E in der Queue speichern
}
}
}
}
?>
###[/LBS]###
###[EXEC]###
<?
require(dirname(__FILE__)."/../../../../main/include/php/incl_lbsexec.php");
set_time_limit(0); //Script soll endlos laufen
sql_connect();
if (!file_exists('/usr/local/edomi/www/data/LBS_cache')) {
mkdir('/usr/local/edomi/www/data/LBS_cache', 0777, true);
}
if(file_exists("/usr/local/edomi/www/data/LBS_cache/out_".$id."_cache.json")){
unlink("/usr/local/edomi/www/data/LBS_cache/out_".$id."_cache.json");
}
$outcache = array();
$retarr = array();
$nexttime = 0;
$next_auto = time() +180;
$sperrzeit =0;
$sperre_eing = false;
$st_file = '/var/tmp/monitor_'.$id.'.json';
$next_time = array();
$dir_filter = null;
if (@is_file('/.dockerenv')){LB_LBSID_logging_exe($id,"Docker",7);} else {LB_LBSID_logging_exe($id,"no Docker",7);}
$path = shell_exec('which node');
$path = str_replace(array("\n", "\r\n", "\r", "\t", " "), "", $path);
$path = str_replace("bin","lib",$path);
$ver = shell_exec('node -v');
if(substr($ver,1) < 12 ) {
LB_LBSID_logging_exe($id,"goto installation",7);
logic_setVar($id,1,0);
install($id);
}
while (logic_getEdomiState()==1) {
//$E = json_decode(logic_getVar($id,3),true);
if( !file_exists('/opt/oebb/table_'.$id.'.js') || !file_exists('/opt/oebb/station_'.$id.'.js') || (!`which node`) || !file_exists($path."_modules/hafas-client")) {
LB_LBSID_logging_exe($id,"goto installation",7);
logic_setVar($id,1,0);
install($id);
}
$cmd = 'node';
$return = shell_exec(sprintf("which %s", escapeshellarg($cmd)));
if(empty($return)) {
LB_LBSID_logging_exe($id,"nodejs nicht installiert ",8);
goto ende;
}
$remanent = json_decode(logic_getVar($id,2),true);
$op = $remanent['op'];
$stid = $remanent['stid'];
$dir_filter = $remanent['dir_filter'];
/*$zugnummer = $remanent['zugnummer'] ? $remanent['zugnummer'] : null;
$travel_id = $remanent['travel_id'] ? $remanent['travel_id'] : null;
$alarm_time = $remanent['alarm_time'] ? $remanent['alarm_time'] : null;*/
if ($E=logic_getInputsQueued($id)) {
// Eingänge
/*
foreach($E as $k => $in){
$rem[$k]= $in;
$rem[$k]['refresh'] = 0;
}
logic_setVar($id,3,json_encode($rem));
LB_LBSID_logging_exe($id,"inputs",8,$rem); */
if($E[1]['value'] != 1 ){
LB_LBSID_logging_exe($id,"LBS beendet ",8);
logic_setState($id,0);
exit();
}
$max_Abfrage = $E[5]['value'];
$max = $E[7]['value'];
$type = $E[9]['value'];
$op = $E[3]['value'];
$stid = ltrim($E[2]['value'],'0');
$filter = explode('|',$E[4]['value']);
$long = $E[8]['value'] ? true :false;
if($E[6]['value'] == 'Filter entfernen' || $E[6]['value'] == '' ) {
$dir_filter = null;
$remanent['dir_filter'] = null;
} else {
$dir_filter = $E[6]['value'];
$remanent['dir_filter'] = $E[6]['value'];
}
//logic_setVar($id,2,$dir_filter);
//LB_LBSID_logging_exe($id,"Filter id $dir_filter",8);
if($E[10]['refresh'] == 1 ){
if($E[10]['refresh'] == 1 && $E[10]['value'] != ''){
get_st_id($id,$E[10]['value'],$op);
}
goto ende;
} else {
if($E[3]['refresh'] == 1 ) goto ende;
$filter = explode('|',$E[4]['value']);
$sperre_eing = false;
$sperrzeit = time();
LB_LBSID_logging_exe($id,"Filter komplett an E3 nächste Abfrage $sperrzeit",8);
}
if($E[11]['refresh'] == 1 ){
if($E[11]['refresh'] == 1 && $E[11]['value'] != ''){
get_dest_st_id($id,$E[11]['value'],$op);
}
goto ende;
}
if($E[1]['refresh'] == 1 || $E[2]['refresh'] == 1 || $E[9]['refresh'] == 1){
if(file_exists("/usr/local/edomi/www/data/LBS_cache/out_".$id."_cache.json")){
unlink("/usr/local/edomi/www/data/LBS_cache/out_".$id."_cache.json");
$stid = ltrim($E[2]['value'],'0');
$next_auto = time() +120;
LB_LBSID_logging_exe($id,"neues Ziel -> neue Abfrage ",8);
$dir_to_filter = array();
get_table($id, $stid, $op, $max_Abfrage, $type, $dir_filter);
}
}
$remanent['stid'] = $stid;
$remanent['op'] = $op;
logic_setVar($id,2,json_encode($remanent));
}
if (time() > $sperrzeit && $sperre_eing === false){
$sperre_eing = true;
$next_auto = time() +120;
LB_LBSID_logging_exe($id,"gänderte Filter -> neue Abfrage ",8);
get_table($id, $stid, $op, $max_Abfrage, $type, $dir_filter);
}
if(time() > $next_auto){
$next_auto = time() +120;
LB_LBSID_logging_exe($id,"autoupdate ",8);
get_table($id, $stid, $op, $max_Abfrage, $type, $dir_filter);
}
if(file_exists("/usr/local/edomi/www/data/LBS_cache/out_".$id."_cache.json")){
$out_old = json_decode(file_get_contents( "/usr/local/edomi/www/data/LBS_cache/out_".$id."_cache.json"),true);
if(array_key_exists(25,$out_old)){
logic_setOutput($id,25,$out_old[25]);
}
} else {
$out_old = array();
}
if(file_exists($st_file)){
$retarr = json_decode(file_get_contents($st_file),true);
$filemtime = @filemtime($st_file);
if (!$filemtime or (time() - $filemtime <= 1)){
LB_LBSID_logging_exe($id,"Daten empfangen ",7,$retarr);
}
$sperre = false;
$station_name = '';
if(count($retarr)>0){
$outcache[2] = @preg_replace('/ \(.*\)$/m', '', $retarr[0]['stop']['name']);
$station_name = @$outcache[2];
}
#####################################################
$out_count = 3;
if($type == 1){
//Ankunft
$table = ' ***W:6*A:center|Ankunftsmonitor***W:9*A:left|***W:11*A:left|***W:17*A:left|'.$station_name.'***W:34*A:left|***W:15*A:left|***W:0*A:left|#';
$table .= '|Ankunft|Erwartet|Linie|aus Richtung|Bahnsteig#';
} else {
//$table = ' ***W:6*A:center|Abfahrtsmonitor***W:9*A:left|***W:11*A:left|***W:17*A:left|'.$station_name.'***W:34*A:left|***W:15*A:left|***W:0*A:left|#';
//$table .= '|Abfahrt|Erwartet|Linie|in Richtung|Bahnsteig#';
$table = ' ***W:6*A:center|Abfahrtsmonitor***W:9*A:left|***W:11*A:left|***W:17*A:left|'.$station_name.'***W:34*A:left#';
$table .= '|Abfahrt|Erwartet|Linie|in Richtung#';
}
$dir_to_filter = array();
$ges_out = array();
$next_time = array();
foreach($retarr as $tour){
if(in_array($tour['line']['product'],$filter)){
$next_time_unix = strtotime($tour['when']);
if(time() <= $next_time_unix +30){
$tour['when'] = strftime('%R',strtotime($tour['when']));
$tour['plannedWhen'] = strftime('%R',strtotime($tour['plannedWhen']));
$vers = '';
$vers_time = round(($tour['delay'] / 60),0);
if($vers_time >0 ) $vers = $tour['when']; //$vers ='<font color="yellow">'.$tour['when'].'</>';
$direction = preg_replace('/ \(.*\)$/m', '', $tour['direction']);
if($direction != null && !in_array($direction,$dir_to_filter)) $dir_to_filter[] = $direction;
$linie_nr = preg_replace('/ \(.*\)$/m', '', $tour['line']['name']);
$str = $tour['plannedWhen'] .'|'.$vers.'|'.$linie_nr.'|'.$direction.'|'.$tour['platform'];
if($out_count <= $max +2){
$table .= '|'.$str.'#';
unset($tour['remarks']);
$ges_out[] = $tour;
}
if($long == true) {
$outcache[$out_count] = $str."|".$next_time_unix;
}else{
$outcache[$out_count] = $next_time_unix;
}
$out_count++;
$next_time[] = $next_time_unix;
}
}
if($out_count > 22) break;
}
if(strlen(json_encode($ges_out)) <10000) {
$outcache[1] = json_encode($ges_out);
}else{
$outcache[1] = '';
}
for($out_count; $out_count <= 22; $out_count++){
$outcache[$out_count] = '';
}
if(count($next_time)>0) {
if($next_auto > min($next_time) +60){
$next_auto = min($next_time) +60;
LB_LBSID_logging_exe($id,"min time next run $next_auto ".time(),8);
}
}
#####################################################
}
set:
$diff = array_diff_assoc($outcache, $out_old);
if($diff){
$ausg_file = 'oebb_table';
if(strlen($table) >= 9990 ){
file_put_contents( "/usr/local/edomi/www/data/LBS_cache/out_".$id."_".$ausg_file.".txt",$table);
logic_setOutput($id,23,"FILE:/data/LBS_cache/out_".$id."_".$ausg_file.".txt");
}else{
logic_setOutput($id,23,$table);
}
LB_LBSID_logging_exe($id,"Diff ",8,$diff);
ksort($diff);
foreach($diff as $outnr => $outval){
if($outval !== null) {
logic_setOutput($id,$outnr,$outval);
LB_LBSID_logging_exe($id,"Ausgang $outnr auf $outval gesetzt",7);
}
}
file_put_contents( "/usr/local/edomi/www/data/LBS_cache/out_".$id."_cache.json",json_encode($outcache));
}
ende:
usleep(1000000);
}
function install($id){
if (!file_exists('/opt/oebb')) {
mkdir('/opt/oebb', 0777, true);
}
if (!`which node`){
shell_exec('yum install -y gcc-c++ make');
shell_exec('curl -sL https://rpm.nodesource.com/setup_14.x | sudo -E bash -');
shell_exec('sudo yum -y install nodejs');
} else {
$ver = shell_exec('node -v');
if(substr($ver,1) < 12 ) {
LB_LBSID_logging_exe($id,"Update node",7);
shell_exec('sudo npm cache clean -f');
shell_exec('sudo npm install -g n');
shell_exec('sudo n latest');
}
}
$path = shell_exec('which node');
$path = str_replace(array("\n", "\r\n", "\r", "\t", " "), "", $path);
$path = str_replace(array("bin"), "lib", $path);
if (!file_exists($path."_modules/hafas-client")) shell_exec('npm -g --safe install hafas-client');
$fp = fopen('/opt/oebb/table_'.$id.'.js', 'w');
fwrite($fp, '
\'use strict\'
var fs = require("fs");
var stid = process.argv[2]
var dauer = process.argv[3]
var op = process.argv[4]
var dirInput = null
var datname = \'monitor_\'+process.argv[6]+\'.json\'
const {createClient} = require(\''.$path.'_modules/hafas-client\')
const {profile} = require(\''.$path.'_modules/hafas-client/p/\'+op+\'\')
const client = createClient(profile, \'edomi-hafas-monitor\')
var timer = setTimeout(() => {
return;
}, 10000);
if (typeof process.argv[7] !== \'undefined\') {
dirInput = process.argv[7];
}
if(process.argv[5] == 1){
client.arrivals(stid, {duration: dauer, direction: dirInput, language: \'de\' })
.then(function(data) {
console.log(JSON.stringify(data));
clearTimeout(timer);
fs.writeFile(\'/var/tmp/\'+datname,
JSON.stringify(data.arrivals || []),
function(err, result) {
//if(err) console.log(\'error\', err);
});
});
} else {
client.departures(stid, { duration: dauer,remarks: false, direction: dirInput, language: \'de\' })
.then(function(data) {
console.log(JSON.stringify(data));
clearTimeout(timer);
fs.writeFile(\'/var/tmp/\'+datname,
JSON.stringify(data.departures || []),
function(err, result) {
//if(err) console.log(\'error\', err);
//if (err) fs.writeFile(\'/var/tmp/\'+datname, error);
});
});
}
');
fclose($fp);
$fp = fopen('/opt/oebb/station_'.$id.'.js', 'w');
fwrite($fp, '
\'use strict\'
var fs = require("fs");
var stid = process.argv[2]
var op = process.argv[3]
const {createClient} = require(\''.$path.'_modules/hafas-client\')
const {profile} = require(\''.$path.'_modules/hafas-client/p/\'+op+\'\')
const client = createClient(profile, \'edomi-hafas-monitor\')
var timer = setTimeout(() => {
return;
}, 10000);
client.locations(stid, {
results: 20,
stops: true,
addresses: false,
poi: false
})
.then(function(data) {
console.log(JSON.stringify(data));
clearTimeout(timer);
});
');
fclose($fp);
logic_setVar($id,1,1);
}
function get_st_id($id,$search_id,$op='insa'){
$path = str_replace(array("\n", "\r\n", "\r", "\t", " "), "", shell_exec('which node'));
$ret = shell_exec("$path /opt/oebb/station_$id.js $search_id $op" );
$list = '***W:70*A:left|***W:30*A:right#';
$arr = json_decode($ret,true);
if(is_array($arr)){
foreach($arr as $station){
if($station['type'] == 'stop'){
$list .= $station['name']."|".$station['id']."#";
}
}
logic_setOutput($id,24,$list);
}
}
function get_dest_st_id($id,$search_id,$op='insa'){
$path = str_replace(array("\n", "\r\n", "\r", "\t", " "), "", shell_exec('which node'));
$ret = shell_exec("$path /opt/oebb/station_$id.js $search_id $op" );
$list = '***W:70*A:left|***W:30*A:right#|Filter entfernen#';
$arr = json_decode($ret,true);
if(is_array($arr)){
foreach($arr as $station){
if($station['type'] == 'stop'){
$list .= $station['name']."|".$station['id']."#";
}
}
logic_setOutput($id,25,$list);
}
}
function get_table($id, $stid='13550',$op='insa', $max_Abfrage=60, $type='0', $dir_filter=null){
$path = str_replace(array("\n", "\r\n", "\r", "\t", " "), "", shell_exec('which node'));
LB_LBSID_logging_exe($id,"JS send function $stid $max_Abfrage $op $type $id $dir_filter",8);
shell_exec("$path /opt/oebb/table_$id.js $stid $max_Abfrage $op $type $id $dir_filter" );
}
function LB_LBSID_logging_exe($id, $msg, $priority = 8, $var = NULL){
$E = logic_getInputs($id);
$logLevel = $E[20]['value'];
//$logLevel =6;
if (is_int($priority) && $priority <= $logLevel && $priority > 0) {
$logLevelNames = array(
'none',
'emerg',
'alert',
'crit',
'err',
'warning',
'notice',
'info',
'debug'
);
$version = getLogicElementVar($id, 100);
$lbsNo = getLogicElementVar($id, 101);
$logName = getLogicElementVar($id, 102) . "-LBS$lbsNo";
$logName = preg_replace('/ /', '_', $logName);
if (logic_getVar($id, 104) == 1)
$logName .= "-$id";
if (logic_getVar($id, 105) == 1)
$msg .= " ($id)";
strpos($_SERVER['SCRIPT_NAME'], $lbsNo) ? $scriptname = 'EXE' . $lbsNo : $scriptname = 'LBS' . $lbsNo;
writeToCustomLog($logName, str_pad($logLevelNames[$logLevel], 7), $scriptname . " [v$version]:\t" . $msg);
if (isset($var)) {
writeToCustomLog($logName, str_pad($logLevelNames[$logLevel], 7), $scriptname . " [v$version]:\t================ ARRAY/OBJECT START ================");
writeToCustomLog($logName, str_pad($logLevelNames[$logLevel], 7), $scriptname . " [v$version]:\t" . json_encode($var, JSON_UNESCAPED_UNICODE));
writeToCustomLog($logName, str_pad($logLevelNames[$logLevel], 7), $scriptname . " [v$version]:\t================ ARRAY/OBJECT END ================");
}
}
}
sql_disconnect();
?>
###[/EXEC]###
Kommentar


bis zum nächsten SEV
Kommentar