Community discussions

MikroTik App
 
User avatar
rcourtney
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 61
Joined: Wed May 22, 2013 10:55 pm

NOAA weather information in hotspot login

Wed Dec 30, 2015 9:36 pm

I have written a script to grab current weather information. (See below)

I would like to present the global environment variables to the user login page.

I am not seeing them appear. $(weather) Any hints?
/tool fetch url="http://w1.weather.gov/xml/current_obs/KIOW.xml" mode=http 

:global fileContents [/file get [/file find name=KIOW.xml] contents];
                                                   
:local start [:find $fileContents "<station_id>" 0];
:set start ($start + 12 );
:local end [:find $fileContents "</station_id>" $start];
:global "station_id" [:pick $fileContents $start $end];

:set start [:find $fileContents "<weather>" 0];
:set start ($start + 9 );
:set end [:find $fileContents "</weather>" $start];
:global weather [:pick $fileContents $start $end];

:set start [:find $fileContents "<temperature_string>" 0];
:set start ($start + 20 );
:set end [:find $fileContents "</temperature_string>" $start];
:global temperature [:pick $fileContents $start $end];

:set start [:find $fileContents "<wind_string>" 0];
:set start ($start + 13 );
:set end [:find $fileContents "</wind_string>" $start];
:global winds [:pick $fileContents $start $end];
                                              
:set start [:find $fileContents "<observation_time>" 0];
:set start ($start + 18 );
:set end [:find $fileContents "</observation_time>" $start];
:global observation [:pick $fileContents $start $end];

:set start [:find $fileContents "<icon_url_name>" 0];
:set start ($start + 15 );
:set end [:find $fileContents "</icon_url_name>" $start];
:global icon [:pick $fileContents $start $end];

:set start [:find $fileContents "<icon_url_base>" 0];
:set start ($start + 15 );
:set end [:find $fileContents "</icon_url_base>" $start];
:global iconurl ( [:pick $fileContents $start $end] . $icon);

/tool fetch url=$iconurl mode=http
 
User avatar
ZeroByte
Forum Guru
Forum Guru
Posts: 4047
Joined: Wed May 11, 2011 6:08 pm

Re: NOAA weather information in hotspot login

Wed Dec 30, 2015 9:48 pm

Do they have a web widget / gadet / graphic that contains the info you want, and on a URL on their server so that you could just reference it as an image/script/etc on the login page? If so, do that and add the URL to the walled garden.
 
User avatar
rcourtney
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 61
Joined: Wed May 22, 2013 10:55 pm

Re: NOAA weather information in hotspot login

Wed Dec 30, 2015 10:34 pm

Not directly. An icon (fog, rain, sunny, snow, etc) is named in the xml. It could be copied
in the script to the hotspot folder.

I could dynamically build the login.html file as a last resort in the script each hour.
Was hoping there was a "secret" way to get the scripting environment variable exposed
to the hotspot.
 
User avatar
ZeroByte
Forum Guru
Forum Guru
Posts: 4047
Joined: Wed May 11, 2011 6:08 pm

Re: NOAA weather information in hotspot login

Thu Dec 31, 2015 3:22 am

Here, use something like this:
http://www.wunderground.com/stickers/
 
User avatar
rcourtney
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 61
Joined: Wed May 22, 2013 10:55 pm

Re: NOAA weather information in hotspot login

Sat Jan 02, 2016 6:09 am

Thanks for taking time to help.
I looked at the stickers and decided to dynamically build the login page hourly.
I am bench testing now.
login.html was divided into two parts and reassembled with the information.
:global login1 [/file get [/file find name="hotspot/login1.txt"] contents];
:global login2 [/file get [/file find name="hotspot/login2.txt"] contents];

:global login; 
:set login ($login1);
#:set login ($login . "<p class=\"ws\">");
#:set login ($login . "<img src=\"". $iconurl . "\">");
#:set login ($login . "</p>\r\n");
:set login ($login . "<p class=\"ws\">Weather conditions: " . $weather . "</p>");
:set login ($login . "<p class=\"ws\">Temp: " . $temperature . "</p>\r\n");
:set login ($login . "<p class=\"ws\">Winds: " . $winds . "</p>");
:set login ($login . "<p class=\"ws\">" . $observation . "</p>\r\n");

:set login ($login . $login2);

/file set [/file find name="hotspot/login.html"] contents=$login;
There are a few RSS feeds for other news that I may add later on.

I do hope script globals may be made accessible to the hotspot in the future.

Who is online

Users browsing this forum: No registered users and 8 guests