Repository navigation
Expand file tree
/
Copy pathcap_warn.php
More file actions
275 lines (206 loc) · 9.99 KB
/
Copy pathcap_warn.php
File metadata and controls
275 lines (206 loc) · 9.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
#!/usr/bin/php
<?php
// Recovering oprginal CAP-Warn code from 2023. Capwarn is now a standalone project And has been moved to its own
// Archive. (c) 2026 https://github.com/tmastersmart/cap-warn
//
// The folowing is the history of cap-warn a hand coded orginal projet.....DO not use this its part of a larger system and wont run
//
// (c)2023 by WRXB288 and LAgmrs.com
//
// _____ _ __ __ _____ _____
// / ____| | \ \ / / / ____| /\ | __ \
// | (___ | | ___ \ \ /\ / /_ _ _ __ _ __ | | / \ | |__) |
// \___ \| |/ / | | \ \/ \/ / _` | '__| '_ \ | | / /\ \ | ___/
// ____) | <| |_| |\ /\ / (_| | | | | | | | |____ / ____ \| |
// |_____/|_|\_\\__, | \/ \/ \__,_|_| |_| |_| \_____/_/ \_\_|
// __/ |
// |___/
//
// weather.gov
//
//What is CAP?
//Common Alerting Protocol (CAP) is an XML-based information standard used to facilitate emergency information sharing and data exchange across
// local, state, tribal, national and non-governmental organizations of different professions that provide emergency response and management services.
//
//NWS produces CAP for NWS weather and hydrologic alerts including watches, warnings, advisories, and special statements.
//NWS CAP messages follow the CAP v1.2 standard defined by the Organization for the Advancement of Structured Information Standards (OASIS) and
//comply with the Federal Emergency Management Agency (FEMA) Integrated Public Alert and Warning System (IPAWS) CAP profile.
//The National Weather Service (NWS) CAP v1.2 Documentation provided on this site supplements the OASIS CAP v1.2 standard and IPAWS CAP
// profile by identifying the formats of NWS information contained within NWS CAP messages.
//Uses of CAP
//NWS CAP can be used to launch Internet messages, trigger alerting systems, feed mobile device applications, news feeds, television/radio display
// and audio, digital highway signs, synthesized voice over automated telephone calls, and much more.
// The goal of this project is to control the software and how it works without using any prior closed source scripts in the node.
// a total rewrite allows me to control how my node works. I wrote this for myself but am releaseing it to other GMRS users.
// This is ground up written from scratch php using
//
// Notice this is only as reliable as the weather.gov server which goes down from time to time & your node.
// Not responiable for any failed reports use as is at your own risk.
//
// Notes the tailfile is shorter for repeated use in tail file settings
//
// skywarn-tm.wav is temp file the program creates on a update. This should not be used as a tail file. it should be autodeleted
//
$mtime = microtime();$mtime = explode(" ",$mtime);$mtime = $mtime[1] + $mtime[0];$script_start = $mtime;
$path ="/etc/asterisk/local/mm-software";
$outTmp ="/tmp/skywarn-tmp.wav"; if (file_exists($outTmp)){unlink($outTmp);}
$alertTxt ="/tmp/skywarn.txt";
$alertTxtHeadline ="/tmp/skywarn_headline.txt";
$clash ="/tmp/mmweather-task.txt";
$tailfile ="/tmp/skywarn-tail.wav";
$ver= "v2.2";
include ("$path/load.php");
include ("$path/sound_db.php");
include ("$path/check_reg.php");
// do not change this its only for debugging
//$skywarn="ARC111";// for live testing ONLY. Find a zone with an alert and enter it.
// Get php timezone in sync with the PI
$line = exec('timedatectl | grep "Time zone"'); // Time zone: America/Chicago (CDT, -0500)
$line = str_replace(" ", "", $line);
$pos1 = strpos($line, ':');$pos2 = strpos($line, '(');
if ($pos1){ $zone = substr($line, $pos1+1, $pos2-$pos1-1); }
else {$zone="America/Chicago";}
define('TIMEZONE', $zone);
date_default_timezone_set(TIMEZONE);
$phpzone = date_default_timezone_get(); // test it
if ($phpzone == $zone ){$phpzone="$phpzone set";}
else{$phpzone="$phpzone ERROR";}
$phpVersion= phpversion();
$time= date('H:i');
$date = date('m-d-Y');
$datum = date('m-d-Y H:i:s');
$gmdatum = gmdate('m-d-Y H:i:s');
print "
===================================================
Cap Warn CAP 1.1/1.2 NWS API $coreVersion-c$ver
(c)2023 WRXB288 LAGMRS.com all rights reserved
$phpzone PHP v$phpVersion
===================================================
$datum Model: $piVersion
$datum Node:$node UTC:$gmdatum
";
$action="";
// We dont want 2 voices at the same time playing
// This could happen if cron calls 2 at the same time.
if(file_exists($clash)){unlink($clash);
$out="Pausing for other thread(s) to finish";
print "$datum $out
"; save_task_log ($out);
sleep(25);
}
include("$path/forcast.php"); // Read the new API.
// returns $apiVer,$description,$headline,$event,$icon,$shortForcast,$detailedForecast,
$html = str_replace('"', "", $html);
$pos = strpos($html, "features: []");if ($pos){$event="clear";}
// Check the reg -----------------
reg_check ("check");// $node1 $ip $port2 $registered
if($registered =="Registered"){watchdog ("okreg");}
if($registered !="Registered"){
watchdog ("reg");// add to counter
check_gsm_db ("an-error-has-occured");if($file1){$action = "$action $file1";}
check_gsm_db ("node");if($file1){$action = "$action $file1";}
$oh=false;
$x = (string)$node1;
for($i=0;$i<strlen($x);$i++)
{
make_number ($x[$i]);
if($file1){$action = "$action $file1";}
if($file2){$action = "$action $file2";}
}
// "Auth. Sent" "Registered" rejected: 'Registration Refused' // Request,Auth.,
$pos1 = strpos("-$registered", 'Unregistered');if($pos1){check_gsm_db ("is-not-registered");if($file1){$action = "$action $file1";}}
$pos1 = strpos("-$registered", 'Refused'); if($pos1){check_gsm_db ("is-rejected"); if($file1){$action = "$action $file1";}}
$pos1 = strpos("-$registered", 'Auth'); if($pos1){check_gsm_db ("connecting"); if($file1){$action = "$action $file1";}}
$pos1 = strpos("-$registered", 'Request'); if($pos1){check_gsm_db ("not-yet-connected");if($file1){$action = "$action $file1";}}
// if no events we need to talk seperate from alert.
if($event=="clear"){
$file = $outTmp;
exec ("sox $action $file",$output,$return_var);
$datum = date('m-d-Y H:i:s');
print "$datum Playing file $file
";
$status= exec("sudo asterisk -rx 'rpt localplay $node /tmp/skywarn'",$output,$return_var);
}
// Do my repair fix if counter says to
if($counter >$watchdog and $NotReg){
reg_fix ("check");
if(!$NotReg){$out="We are back online"; save_task_log ($out);print "$datum $out
";}
}
}
if ($event=="clear"){all_clear("ok");line_end("There are no active events");}
if (!$event){$out="Error Bad CAP data";save_task_log ($out);line_end($out);}
if (file_exists($alertTxt)){
$test = file_get_contents($alertTxt);
if ($test == $event){line_end("No changes detected");}
print "$datum Change detected
";
save_task_log ("new Alert $event");
}
$fileOUT = fopen($alertTxt,'w');fwrite ($fileOUT,$event);fclose ($fileOUT);
$fileOUT = fopen($alertTxtHeadline,'w');fwrite ($fileOUT,$headline);fclose ($fileOUT);
$file = $tailfile;if(file_exists($file)){unlink($file);} // kill the last tail file to prevent it launching during play
check_wav_db ("silence1"); if($file1){$action = "$action $file1";}
check_wav_db ("strong click"); if($file1){$action = "$action $file1";}
check_wav_db ("updated weather information"); if($file1){$action = "$action $file1";}
check_wav_db ("weather service"); if($file1){if($file1){$action = "$action $file1";}}
$u= explode(",",$event);
foreach($u as $line){
check_wav_db ("star dull"); if($file1){$action = "$action $file1";}
check_wav_db ($line); if($file1){$action = "$action $file1";}
check_wav_db ("light click"); if($file1){$action = "$action $file1";}
// check for major warrnings.
if($line=="Tornado Warning" or $line=="Blizzard Warning" or $line=="Hurricane Warning" or $line=="Severe Thunderstorm Warning" ){
check_gsm_db ("advised to seek shelter");if($file1){$action = "$action $file1";}
}
}
$file = $outTmp;
exec ("sox $action $file",$output,$return_var);
$datum = date('m-d-Y H:i:s');
print "$datum Playing file $file
";
$status= exec("sudo asterisk -rx 'rpt localplay $node /tmp/skywarn-tmp'",$output,$return_var);
// build the shorter tail file
$action="";
check_wav_db ("silence1"); if($file1){$action = "$action $file1";}
$u= explode(",",$event);
foreach($u as $line){
check_wav_db ("star dull"); if($file1){$action = "$action $file1";}
check_wav_db ($line); if($file1){$action = "$action $file1";}
check_wav_db ("light click"); if($file1){$action = "$action $file1";}
}
$file = $tailfile;
exec ("sox $action $file",$output,$return_var);
print "$datum Tailfile updated $file
";
line_end("Finished");
function all_clear($in){
global $file1,$file,$alertTxt,$tailfile,$node,$outTmp;
//$alertTxt ="/tmp/AUTOSKY/warnings.txt";
$action="";
$datum = date('m-d-Y H:i:s');
print "$datum Processing all Clear
";
$outTmp ="/tmp/skywarn-tmp.wav"; if (file_exists($outTmp)){unlink($outTmp);}
if (file_exists($alertTxt)){unlink($alertTxt); // There has been a past alert so we need to clear it and notify
if (file_exists($tailfile)){unlink($tailfile);}
check_wav_db ("silence1"); if($file1){$action = "$action $file1";}
check_wav_db ("updated weather information"); if($file1){$action = "$action $file1";}
check_wav_db ("strong click"); if($file1){$action = "$action $file1";}
check_wav_db ("clear"); if($file1){$action = "$action $file1";}
check_wav_db ("star dull"); if($file1){$action = "$action $file1";}
exec ("sox $action $outTmp",$output,$return_var);
$status ="Playing all clear $file";save_task_log ("All Events now Clear");print "$datum $status
";
$status= exec("sudo asterisk -rx 'rpt localplay $node /tmp/skywarn-tmp'",$output,$return_var);
if(!$status){$status="OK";}
}
if (!file_exists($tailfile)){
$file = $tailfile;
check_wav_db ("silence1");if ($file1){ $fileIN = file_get_contents ($file1);file_put_contents ($file,$fileIN, FILE_APPEND);}
$datum = date('m-d-Y H:i:s');
print "$datum tail file reset to silence. $tailfile
";
}
}
?>