Pelican Parts Forums

Pelican Parts Forums (http://forums.pelicanparts.com/)
-   Off Topic Discussions (http://forums.pelicanparts.com/off-topic-discussions/)
-   -   Code gurus (http://forums.pelicanparts.com/off-topic-discussions/799467-code-gurus.html)

TimT 03-03-2014 03:07 PM

Code gurus
 
I built a little gizmo that fetches weather reports from WeatherUnderground... Used code that was available on Instructables. I re-wrote some things to streamline things.... but am having a hard time getting a good location.. I.e. I live in NY and the box is querying weather in Baltimore... (code author say something about service providers using proxies etc..)


The author of the code mentions in his notes that this section of code is where more accurate geolocations can be noted...

Here is snip where things should change ...


private static void InitLocation()
{
GeoLoactionByIP myLocation = new GeoLoactionByIP();
AskGeoService askGeo = new AskGeoService();

myLocation.queryLocation();

weatherData = new WeatherUndergroundData("d0", myLocation.latitude, myLocation.longitude);// <<< Your Key Here

askGeo.queryLocation(myLocation.latitude, myLocation.longitude);

int minutes = (int)(askGeo.currentOffserMS / 1000 / 60);
Debug.Print("\tTimezone offset (+DST)=" + minutes + " minutes");
ntpService.SetTimeZoneOffset(minutes);
}



FWIW I've tried numerous iterations....

C#, VB running a netduino +

FWIW 2 because of a snow day...I had plenty of time to google

TimT 03-03-2014 03:18 PM

This is the authors bread crumb trail...

Maybe I am over thinking this...

If your network is going through a very remote proxy, like many organizations are still using for connecting remote offices to the internet, then the location the Netduino-Plus finds is where your proxy server is. It is fairly easy to change the Netduino-Plus code to use fixed location instead of auto-detecting it, and I will let those who are interested do it themselves. Hint: All you need is use fixed longitude and latitude in function ' InitLocation' coded in the file Program.cs

TimT 03-03-2014 03:37 PM

Quote:

but weather underground seems to pull the location from the ISP
This is what is driving me crazy... it used to poll and display WU from a few miles away. The one day I woke up and noticed it was displaying info from Baltimore...

I've been at the code a number of times, and no joy... I emailed the author a few weeks ago... and haven't heard back

masraum 03-03-2014 04:14 PM

Does it have to auto locate? Can you pick a specific weather station from their page and then specifically query that station?

HardDrive 03-03-2014 04:17 PM

Need more info about myLocation.queryLocation(); function.

Couldn't you just comment out the query and manually fill in your long/lat info?

Vipergrün 03-03-2014 04:27 PM

Did you see this snippet about their API;

API | Weather Underground

Looks like you need to request a "key" and insert it into the code block you referenced;

Your_Key
Your API key. You can request a key on the sign in page. This is used in most API calls (with the exception of the AutoComplete API).

id10t 03-03-2014 04:32 PM

Determine your true lat/long (instead of using the GeoLocationByIP function) and just plug it in as the RealLatitude and RealLongitude variables

Code:

private static void InitLocation()
{
AskGeoService askGeo = new AskGeoService();
weatherData = new WeatherUndergroundData("d0", RealLatitude, RealLongitude);

askGeo.queryLocation(RealLatitude, RealLongitude);

int minutes = (int)(askGeo.currentOffserMS / 1000 / 60);
Debug.Print("\tTimezone offset (+DST)=" + minutes + " minutes");
ntpService.SetTimeZoneOffset(minutes);
}

I'd also wrap the whole thing up in a check, first by using the GeolocationByIP function, prompting the user to either accept that location as "close enough" or entering a more correct location and then doing the query for the actual weather data.

TimT 03-03-2014 04:36 PM

Quote:

Looks like you need to request a "key" and insert it into the code block you referenced;
I have a key.... i just obscured it in the snippet I posted....I mean people on Pelican are genuinely solid folks....

But still...

TimT 03-03-2014 04:42 PM

When I entered my real Lat/Long in code..

weatherData = new WeatherUndergroundData("d0", RealLatitudehere, RealLongitudehere )

Upon debugging and compiling there were many errors. tried many variations of syntax..could not get that to work...

TimT 03-03-2014 04:44 PM

Oops will try this...

after reading this code for hours,its not a surprise than I miss some nuggets.

id10t 03-03-2014 05:13 PM

Quote:

Originally Posted by TimT (Post 7942360)
When I entered my real Lat/Long in code..

weatherData = new WeatherUndergroundData("d0", RealLatitudehere, RealLongitudehere )

Upon debugging and compiling there were many errors. tried many variations of syntax..could not get that to work...

Need to see the errors. If it is about data type mismatch then check the docs for the data type the GeoByIP call returns and be sure to define your lat/long variables as the same type.

Head416 03-03-2014 07:02 PM

I agree, determining location by IP is unreliable. Too many variables outside of your control.

HardDrive 03-03-2014 07:35 PM

Quote:

Originally Posted by Head416 (Post 7942640)
I agree, determining location by IP is unreliable. Too many variables outside of your control.

Yup. Proxy server could be a long, long way from your physical location.

Tishabet 03-03-2014 11:12 PM

Quote:

Originally Posted by HardDrive (Post 7942302)
Need more info about myLocation.queryLocation(); function.

Couldn't you just comment out the query and manually fill in your long/lat info?

Or, dump the values of mylocation.lat/mylocation.long to screen... shoild be able to debug if you know what data has been retrieved using this geodatafromip() functionality. Comment out anything related to the askgeo and weatherundergrounddata functions to keep your test simple.

Nostril Cheese 03-04-2014 12:33 AM

I know some of those words..

id10t 03-04-2014 03:47 AM

Quote:

Originally Posted by Head416 (Post 7942640)
I agree, determining location by IP is unreliable. Too many variables outside of your control.

Hey, 127.0.0.1 is always where I am !

TimT 03-11-2014 04:25 PM

Corresponded with the guy who wrote the snippets.... There is now joy

//GeoLoactionByIP myLocation = new GeoLoactionByIP();

AskGeoService askGeo = new AskGeoService();

//myLocation.queryLocation();

//m_weatherData = new WeatherUndergroundData("here was your key", myLocation.latitude, myLocation.longitude);

string lat = "32."; // "32.0";

string longi = "34.";// "34.7";

//askGeo.queryLocation(myLocation.latitude, myLocation.longitude);

askGeo.queryLocation(lat, longi);

weatherData = new WeatherUndergroundData("here place your key", lat, longi);

int minutes = (int)(askGeo.currentOffserMS / 1000 / 60);

Debug.Print("\tTZ offset(+DST)=" + minutes + " minutes");

ntpService.SetTimeZoneOffset(minutes);



Its just a little gizmo that displays current and two day future weather...

Next I am going to tackle the touch screen coding....

http://forums.pelicanparts.com/uploa...1394583929.jpg

flatbutt 03-11-2014 04:45 PM

Quote:

Originally Posted by TimT (Post 7956809)
Corresponded with the guy who wrote the snippets.... There is now joy

//GeoLoactionByIP myLocation = new GeoLoactionByIP();

AskGeoService askGeo = new AskGeoService();

//myLocation.queryLocation();

//m_weatherData = new WeatherUndergroundData("here was your key", myLocation.latitude, myLocation.longitude);

string lat = "32."; // "32.0";

string longi = "34.";// "34.7";

//askGeo.queryLocation(myLocation.latitude, myLocation.longitude);

askGeo.queryLocation(lat, longi);

weatherData = new WeatherUndergroundData("here place your key", lat, longi);

int minutes = (int)(askGeo.currentOffserMS / 1000 / 60);

Debug.Print("\tTZ offset(+DST)=" + minutes + " minutes");

ntpService.SetTimeZoneOffset(minutes);



Its just a little gizmo that displays current and two day future weather...

Next I am going to tackle the touch screen coding....

http://forums.pelicanparts.com/uploa...1394583929.jpg

you need a girlfriend.;)

TimT 03-11-2014 04:54 PM

Quote:

you need a girlfriend.
In addition to my wife? I'll tell her you said so.

pete3799 03-11-2014 06:15 PM

I'll save you the trouble Tim......
Up to 24 inches expected here maybe less down where your place is in Bomoseen.
Pack your snow shoes.:D


All times are GMT -8. The time now is 05:40 PM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
Search Engine Optimization by vBSEO 3.6.0
Copyright 2025 Pelican Parts, LLC - Posts may be archived for display on the Pelican Parts Website


DTO Garage Plus vBulletin Plugins by Drive Thru Online, Inc.