Weather Script

Jordan

I pasted this script on the gateway timer, but it does not run. it works if I paste it on a button.

What am I doing wrong?

This code would query Yahoo Weather for the temperature at

Inductive Automation’s headquarters in Sacramento, CA

and then find the current temperature using a regular expression

#replace the ‘49247’ with your zipcode-- unless you want the weather in Hudson, MI…
response = system.net.httpGet(“http://xml.weather.yahoo.com/forecastrss?p=49247”)

import Python’s regular expression library

import re

NOTE - if you’ve never seen regular expressions before, don’t worry, they look

confusing even to people who use them frequently.

pattern = re.compile(’.?<yweather:condition (.?)/>’, re.DOTALL)
match = pattern.match(response)

if match:
subText = match.group(1)
condition = re.compile(’.?text="(.?)"’).match(subText).group(1)
temp = re.compile(’.?temp="(.?)"’).match(subText).group(1)
code = re.compile(’.?code="(.?)"’).match(subText).group(1)
system.tag.writeToTag(“Weather/Condition”,condition)
system.tag.writeToTag(“Weather/Code”,code)
system.tag.writeToTag(“Weather/Temp”,temp)
#print "Condition: ", condition
#print "Temperature (F): ", temp
else:
system.tag.writeToTag(“Weather/Condition”,“N/A”)#print ‘Weather service format changed’

pattern = re.compile(’.?<yweather:forecast (.?)/>’, re.DOTALL)
match = pattern.match(response)

if match:
subText = match.group(1)
lowtemp = re.compile(’.?low="(.?)"’).match(subText).group(1)
hightemp = re.compile(’.?high="(.?)"’).match(subText).group(1)
system.tag.writeToTag(“Weather/Low”,lowtemp)
system.tag.writeToTag(“Weather/High”,hightemp)
#print "Condition: ", condition
#print "Temperature (F): ", temp
else:
system.tag.writeToTag(“Weather/Condition”,“N/A”)#print ‘Weather service format changed’

What is the error reported in the console? You can view the console by logging into the Ignition Gateway configuration webpage and selecting Console on the left hand side.

Is it possible the Ignition server doesn’t have internet access?

Travis

10:31:50 AM

TimerScriptTask

Error executing global timer script: Weather_Update (10000) [Delay, Shared]. Repeat errors of this type will be logged as ‘debug’ messages.

Traceback (innermost last):
File “<TimerScript:Weather/Weather_Update (10000) [Delay, Shared]>”, line 5, in ?
IOError: Connection timed out: connect

Right, that means that Ignition could not contact Yahoo on the server machine. I don’t think it has internet access.

I have the same script on a button, it works Good ??

Whew! Dodged that bullet... :mrgreen:

Also did a quick check to make sure yahoo didn't change anything on us... anything's possible!

Jerry: It works on the button because the script on the button is local to the client, which apparently has internet access. Gateway scripts run local to the Igniton server. That's whay Travis was wanting to check for an internet connection on the server.

I am actually on remote desktop to the server. with a Client open on the server itself.

Looking at the console I see the error about every 5 to 10 minutes, but the timer is at 15 seconds.

Do the tags get updated, then? It sounds like an intermittent issue with the internet connection.

The tags have never updated off the timer script, Tags only update , if i use the button.

[quote=“Jerry_H”]Travis
10:31:50 AM

TimerScriptTask

Error executing global timer script: Weather_Update (10000) [Delay, Shared]. Repeat errors of this type will be logged as ‘debug’ messages.

Traceback (innermost last):
File “<TimerScript:Weather/Weather_Update (10000) [Delay, Shared]>”, line 5, in ?
IOError: Connection timed out: connect[/quote]

Ok, that explains the log behavior. All the other errors got downgraded to “debug” type. This reduces log clutter…

This will sound stupid, but it is the same url in the timer script? I’ve gotten caught with that sort of thing.

Another thing I thought of. Do you have a firewall running?

Exactly the same script–copy&pasted

Yes, there is a firewall! I added an except to yahoo but maybe it not correct.

Stop the firewall same issue,

Created a client timer script it does not work either.

Are you getting the same error?

Was there a resolution to this? I would like to do the same thing.

Thanks

Not resolved ! Button works Gateway Timer does not.

It could be a group policy of some kind on my end?

I gave up and went a different direction using active X now and taking a screen shot and passing it on to non internet connected PC’s, shows all current conditions and radar from Weatherbug.

What version of Ignition are you running?

7.2.11

7.2.11, same as me. Or is that same as I?

I’ve been using this script for about a year and a half. If it’s working off a button but not a gateway timer, then I’d have to say the script itself is okay.

That being said, I originally put this together as a complete and separate project. In fact this original project is still running. I’ll attach it here. See if this makes any difference for you. Odder things have happened…
weather.proj (25.1 KB)

Downloaded and created a project.

Opened in Designer, gateway script fails to run, copied script to a button, it worked.

Saved and Opened the project…Just a blank grey screen.

Is this 32 bit or 64 bit?

I am running 64 bit with java 1.6.33

Attached is a screen shot of what I am now doing using active X