PDA

View Full Version : OpenWeather [Testing]: A proposal to fix weather issues



Asturbo
06-10-2018, 18:37
NOTE: Initial Beta testing versión here (http://forum.projectcarsgame.com/showthread.php?65160-API-weather-request-A-proposal-to-fix-weather-issues&p=1545037&viewfull=1#post1545037)

PRELUDE

As we all know, we have some problems with the weather configuration that affects specially to online communities:


If we select Ramdom Weather we have rain and its variations in most of the times. Nice to show the game possibilities the first weeks, but not valid to communities. Link (http://forum.projectcarsgame.com/showthread.php?61561-Project-Rain)
If we select Real Weather, we always get clear weather, because it has stopped working from 1 month ago. Link (http://forum.projectcarsgame.com/showthread.php?58197-Real-weather&p=1540704&viewfull=1#post1540704)

So we only can use predefined slots for our races. That is a problem, because there is no surprise and everybody knows what will happen during the race, and the exact moment when the weather will change. With Project Cars 1, I was using a table with the lottery of the day of the race to choose the weather conditions, using different weights to the different scenarios. A little bizarre but it worked because all we know the weather few minutes before the race.

The prefered solution would be another type of weather called “random realistic” with more logical options of each scenario (clear 30%, cloud 30%, …light rain 10%, Rain 8%, Extreme 1%). But I don’t think at this stage of development, we could get this. So I was thinking in other possible solutions after studying how RW works in the game and why is probably failing. (See this link (http://forum.projectcarsgame.com/showthread.php?58197-Real-weather&p=1544362&viewfull=1#post1544362))

HOW IT WORKS RW

The host of the race (P2P or DS), connects to realweather API to obtain the next hours slots for the current time & location. The program (PC2), logs in the weather server, makes a query for the next hours forecast and receives the weather data, that are assigned by the game to the slots of the session. The problem ATM, is that we aren't receiving any data, so we always get clear weather. In previous link I commented the possible reason (the key id), but after undestanding how the system works, I'm now thinking in a more ambitious solution.

PROPOSED SOLUTION

We can redirect the query to another IP where we can build our own weather server . Obviously we don’t will have real weather (because we don't have the data), but we can obtain weather slots with a random & logical pattern with different weights to diferent scenarios. SMS (or a third party) could make a tiny web based APP installed in the local computer, that accepts the query and responds with random-logical weather data. We can use the method used by Zenzic with his wonderful utility [link (http://forum.projectcarsgame.com/showthread.php?56777-quot-Custom-Random-Weather-Automator-quot)] and we can personalize the weather weights, or exclude bizarre scenarios.

HOW REDIRECT THE QUERY

It’s very easy. We know the URL used to get real weather: api.openweathermap.org , and we can add it manually to the host file of our Windows to tell the system where is our weather server hosted (without using public DNS resolution). So we can redirect this URL to any other IP (public or private) or our own localhost IP, where the weather server app is hosted.

The windows host file (if exist, if not we can create it) is stored in the C:\Windows\System32\drivers\etc folder. If we add the line:

127.0.0.1 api.openweathermap.com

all the connections to this URL are redirected to the IP 127.0.0.1 (Localhost), where the API could be located providing random weather data.

261023

THE HARD WORK

Someone (SMS or any Third Party) has to make a tiny web bassed APP that accepts the query, generates a random weather pattern and responds in the same format as opensimweather (Example (http://api.openweathermap.org/data/2.5/forecast?lat=10&lon=10&mode=xml&c&appid=aac05e0ee50fad048ec4c417ab3b9920)). Obviously the weather data would be random (not real) because we don't have the data, but it would be a big step forward because we can get random-custom weather, that it's all we want (for me even better than RW). Thats allows us to simulate a full season in Christmas without driving at 5º.

ADVANTAGES


We don’t need any API key, licences… only our own app.
No connectivity or traffic overload issues.
We solve in a row the "Too rainy random weather" and the "Real Weather not working" issues.
This method is better that in-build ones (random and real) and we could have "ramdom custom".
We can program the Weather Server API with different weights based in our preferences or logical patterns (using Zecnic or similar method)
No need to touch the code of the game. Everything could be outside, so no redesign or hard code changes needed. That's the best part for SMS.
It’s very easy to program (much more than doin in-game). The APP only needs to accept the query, generate the random weather pattern (Zecnic method) and responding in the same output format as openweather.org (example (http://api.openweathermap.org/data/2.5/forecast?lat=10&lon=10&mode=xml&c&appid=aac05e0ee50fad048ec4c417ab3b9920))
It's transparent to the game. It gets the data from a diferent IP and applies to the weather slots ingame.
The API port could be forwarded in our router, to have a public weather server hosted in our public IP.
It will work online and offline and the querys probably goes much faster than with the real servers.
It's reversible. The API could have a check that enables disables the redirection. So we can choose Real Weather (if it gets fixed) or random personalized weather using out local appp.


Hope SMS could have a think about this solution, because it’s easy, effective and solves most of the weather issues we have without touching any line of code of the game. We have to use the in-game RW option, but the result will be custom-random weather. It could be distributed as an Steam utility like the DS as "Custom Weather Generator" or as third part app.

I’ll contact by PM with Zecnic, to study the viability of this possible solution, because he has solved brilliantly the most of the hard work needed for this App.

[Sorry, I'm system engenieer, but not programmer and can't do the task] :(

Asturbo
07-10-2018, 08:29
This is the format of the query:

http://api.openweathermap.org/data/2.5/forecast?lat=%3.2f&lon=%3.2f&mode=xml&c

I our app we can ignore the Latitude and Longitude parameter, because it doesn't condition the random pattern.

And this is the format data obtained from openweahtermap for 3 hours slots. Probably only few of this lines are used in Project Cars 2

<time from="2018-10-07T12:00:00" to="2018-10-07T15:00:00">
<symbol number="500" name="light rain" var="10d"/>
<precipitation unit="3h" value="0.615" type="rain"/>
<windDirection deg="80.5023" code="E" name="East"/>
<windSpeed mps="4.21" name="Gentle Breeze"/>
<temperature unit="kelvin" value="310.67" min="307.615" max="310.67"/>
<pressure unit="hPa" value="966.38"/>
<humidity value="42" unit="%"/>
<clouds value="few clouds" all="12" unit="%"/>
</time>

These are some links that expains the data output formats:

https://openweathermap.org/current
https://openweathermap.org/weather-conditions
https://openweathermap.org/weather-data

mr_belowski
07-10-2018, 08:47
Now that's a *very* good idea. A little webservice running locally and a hosts file redirect to the loopback address and the pcars2 weather stuff could be unpredictable, convincing and awesome in single player.

If only there was a locally installed app with a wide user base to host such a webservice...

A standalone service for dedicated servers would also be very cool.

I'll have a play with Crew chief to see if I can embed something. I already have a branch that includes some ReST services that I was playing with a few months ago

And for single player, doing this even opens up the possibility of weather forecasts

Asturbo
07-10-2018, 08:59
Yes, it could be integrated in the DS too. But I initially was thinking in a totaly independet app to don't touch anything else, and/or allow third party developers to do the job.

Thanks for supporting the proposal.

Maskmagog
07-10-2018, 09:19
Brilliant idea!
I'm guessing since consoles don't have the Real weather-option, they never make any calls to outside api's? So not possible for consoles?

Asturbo
07-10-2018, 09:22
No, I'm afraid it's not possible.

With this method the idea is using the in-game "real weather" option and redirect the query to our own web based APP where we can manage the different weather options with custom weights.
In consoles there is no real weather option, AFAIK :(

mr_belowski
07-10-2018, 09:36
Perhaps a standalone application is a better approach. Maybe in the future it could also expose a 'forecast' endpoint which provides some suitably unreliable info about the weather slots it's just generated

Asturbo
07-10-2018, 09:50
Perhaps a standalone application is a better approach. Maybe in the future it could also expose a 'forecast' endpoint which provides some suitably unreliable info about the weather slots it's just generated
In multiplayer, I think that only the host of the session makes the query to openweather and inserts the weather data in the weather slots of game for the session (to avoid different status for players).
Then, only the host needs the APP running in localhost and the rest gets the same random-custom generated weather when logs to the session.
So I think it should work online & offline and solves the weather problems of online comunities.

Zenzic
07-10-2018, 09:57
Good idea, Asturbo!

At the moment I don't have a lot of spare time to help out in any significant way, but I'll gladly provide the randomisation code I wrote if that's worth anything. Just don't judge me by my messy code. :)


And for single player, doing this even opens up the possibility of weather forecasts

That would be awesome. :)

mr_belowski
07-10-2018, 10:02
when i get a few hours i'll knock up a quick SpringBoot application as a prototype and see how it feels

Asturbo
07-10-2018, 10:08
when i get a few hours i'll knock up a quick SpringBoot application as a prototype and see how it feels
Preparing my donation...:cool:

inthebagbud
07-10-2018, 14:12
ingenuity is great and you guys who come up with this stuff speak a different language to me …….. but should SMS not just fix the issue

mr_belowski
07-10-2018, 17:30
Just had a play with wireshark and I couldn't see any obvious traffic going out to api.openweather.org when starting a single player session with realistic weather. You sure this is what the game is connecting to?

Asturbo
07-10-2018, 17:56
In the EXE what I found was api.openweathermap.org (you missed "map")

When you make a NETSTAT -B, you can see that pCARS2AVX.EXE is connected to 192.241.169.168 or 162.243.53.59 (in my case) when RW is enabled.

TCP 192.168.0.10:52925 192.241.169.168:http [pCARS2AVX.exe]

If you connect with a browser to this IP you get openweathermap.org/api. The IP is not always the same, probably by DNS resolution or any internal relay in openweathermap.

If you disable Real weather in-game, this connection is not stablished.

mr_belowski
07-10-2018, 18:07
Spotted it in Wireshark:

GET /data/2.5/weather?lat=49.20&lon=16.45&mode=xml&APPID=[...]
Host: api.openweathermap.org
Accept: */*

and

GET /data/2.5/forecast?lat=49.20&lon=16.45&mode=xml&cnt=8&APPID=[...]
Host: api.openweathermap.org
Accept: */*


response is

HTTP/1.1 429
Server: openresty
Date: Sun, 07 Oct 2018 17:54:55 GMT
Content-Type: application/json; charset=utf-8
Content-Length: 196
Connection: keep-alive
X-Cache-Key: /data/2.5/weather?APPID=[...]&lat=49.2&lon=16.45&mode=xml
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true
Access-Control-Allow-Methods: GET, POST

{"cod":429, "message": "Your account is temporary blocked due to exceeding of requests limitation of your subscription type. Please choose the proper subscription http://openweathermap.org/price"}




I've created a free API key which, when it's been activated will hopefully allow me to reproduce these requests and understand how to craft the appropriate responses for the various weather scenarios we might want to generate. So it's looking promising I think.

Asturbo
07-10-2018, 18:19
You can use mine from this URL:

http://api.openweathermap.org/data/2.5/forecast?lat=10&lon=10&mode=xml&c&appid=aac05e0ee50fad048ec4c417ab3b9920

mr_belowski
07-10-2018, 18:22
I wonder if it's possible to respond with more fine-grained forecast data (< 3 hours between data points) to allow the weather to change more quickly in shorter sessions. Lots and lots of possibilities here, lots of scope for experimentation.

I've got a basic service wired up to produce an appropriate XML (or JSON) response. I'll get stuck in properly this week with a view to building something that can be easily customised

Asturbo
07-10-2018, 18:29
Great news, mate. It's a new world of posibilities here.

Probably PCARS2 uses the 3 hour pattern and translates it to the 1 hour to make the slots, so if you change the intervals, probably has no effect in game, but who knows, because I've seen that the EXE keeps connected to the webAPI after the initial connection.

I would begun generating all the slots with fixed "electrical storm" or even better, using one of the real patterns from openweathermap (but a not clear one). If you get something different to "clear weather" with the random weather option ingame, you're in the right way.

If the project is viable, we can assing the weights with a CFG o JSON text file to the diferent climates. Not UI needed.

mr_belowski
07-10-2018, 18:51
I think it's viable and will make some headway this week. Maybe start with a way to generate basic weather patterns from a config file or something, and take it from there. Eventually it should be pretty easy to have an option to proxy the calls though to the real openweatherapi service with a different API key so a dedicated server owner could use realistic weather with their own known-good key which they could keep secret and manage themselves

Donnced
07-10-2018, 18:53
I completely support this proposal! And it would be great if it could be used in the console versions also..

mr_belowski
07-10-2018, 18:53
i don't think there's a way to make it work on consoles

JasonSandwich
07-10-2018, 22:11
This sort of thing is right up my alley! I wish I had a PC version of this game because I believe that I could help out.

ProDriver
08-10-2018, 07:27
What a fantastic idea mate!!! Cheers and hope it can be implemented, also in consoles.

Javaniceday
09-10-2018, 19:26
It's amazing that you guys are working on this. It'll be so cool if you get it to work. But I have a few concerns.

1 - what is the effective difference between this program, and the Custom Random Weather Automator tool? http://forum.projectcarsgame.com/showthread.php?56777-quot-Custom-Random-Weather-Automator-quot

Is it that the weather generated would be based in real life? With this current app, just knowing the % chance of rain would be enough to give you a pretty accurate presentation of the current weather since the game automatically takes the date and makes temperatures that match that time of year based on the season.

2 - A big problem with Real Weather was the 1-hour interval per weather slot. You'd have to race for 2 hours to see a change in weather. How is this being handled? Will there be a random number of slots? Random length for the weather slots (weather progression acceleration)? Different lengths for each weather slot?

3 - A current problem with the Custom Random Weather Automator is that he lobby owner would know what the weather would be, and no one else would. He/she would have to look away to make sure to not cheat, or in single-player, not spoil the surprise. Is this also being taken into account?

Wondering if you guys are taking these questions into consideration.

mr_belowski
09-10-2018, 20:14
Still at the stage of 'getting something working'.

I now have a service that successfully proxies to the real weather API, which allows you to use your own API key in place of the (expired / blocked) pCars2 API key. So it should work as a fix for real-weather always being clear / sunny.

It also generates its own weather, based on some inputs and randomisation which aren't finished yet. The weather it generates looks kind of OK but it doesn't (yet) work and I'm still trying to track down what's wrong with it and whether it's the game (which is doing some internal caching of its own) or my responses. I need a rainy day to test it really :)

[edit]

the git repo is here:
https://github.com/mrbelowski/PCars2OpenweatherServer


it's a Spring Boot app. Most of the code is just me trying to get the generated responses to look as close to the real responses as possible

[edit 2]

how it actually works is that there's an entry in the hosts file - C:\Windows\System32\drivers\etc\hosts:

127.0.0.1 api.openweathermap.org

this sends all traffic for api.openweathermap.org to the loop-back address (the spring boot app).

The spring boot app either creates its own weather responses or forwards the request on to the real server. Of course, it can't forward to api.openweathermap.org (that ends up back to the service) so the app has to use an IP address got from an nslookup of the dns name.

Asturbo
09-10-2018, 20:30
I now have a service that successfully proxies to the real weather API, which allows you to use your own API key in place of the (expired / blocked) pCars2 API key. So it should work as a fix for real-weather always being clear / sunny.

Awesome !!


It also generates its own weather, based on some inputs and randomisation which aren't finished yet. The weather it generates looks kind of OK but it doesn't (yet) work and I'm still trying to track down what's wrong with it and whether it's the game (which is doing some internal caching of its own) or my responses. I need a rainy day to test it really :)

Be patient and take your time. We are used to wait.



The git repo is here:
https://github.com/mrbelowski/PCars2OpenweatherServer

I'll have a look this weekend (no time till then)



The spring boot app either creates its own weather responses or forwards the request on to the real server. Of course, it can't forward to api.openweathermap.org (that ends up back to the service) so the app has to use an IP address got from an nslookup of the dns name.
For testing the relay you can use one of the public IPs from DNS of openweathermaps. I've seen that always are running, even when the DNS points to another one. Probably all are mirrors.
These are some I've seen last weeks:

162.243.53.59
192.241.169.168

Asturbo
09-10-2018, 21:18
I need a rainy day to test it really :)

Check the output with this place in Iceland. Rain for the next days:

http://api.openweathermap.org/data/2.5/forecast?lat=63.4427&lon=-20.2734&mode=xml&c&appid=aac05e0ee50fad048ec4c417ab3b9920

Coord: [63.4427, -20.2734]

mr_belowski
09-10-2018, 21:23
Thanks, that'll help verify the rain responses. It's hard to know which bits of the payload are actually needed, and whether it's parsed as an XML document or is just scraped - assuming it's the latter, I still need to sort out verbose end tags and element / attribute ordering. Simple stuff but fiddly

mr_belowski
10-10-2018, 10:17
OK, I've massaged the XML so it's a close as I can get it to the 'real' data without having to capture a bunch of location-specific information like city names, but the generated weather is not working and I'm not sure what the likely culprit is. Proxying to the real service with a working AppID does (I think) work, so it's some progress.

This works:

current conditions:

<?xml version="1.0" encoding="UTF-8"?>
<current>
<city id="2653591" name="Castle Donington">
<coord lon="-1.38" lat="52.83"></coord>
<country>GB</country>
<sun rise="2018-10-10T06:23:02" set="2018-10-10T17:20:51"></sun>
</city>
<temperature value="286.53" min="286.15" max="287.15" unit="kelvin"></temperature>
<humidity value="87" unit="%"></humidity>
<pressure unit="hPa" value="1014.0"></pressure>
<wind>
<speed value="3.1" name="Light breeze"></speed>
<gusts></gusts>
<direction value="110.0" code="ESE" name="East-southeast"></direction>
</wind>
<clouds value="12" name="few clouds"></clouds>
<visibility value="8000"></visibility>
<precipitation mode="no" unit="3h" value="0.0"></precipitation>
<weather number="721" value="haze" icon="50d"></weather>
<lastupdate value="2018-10-10T09:20:00"></lastupdate>
</current>

forecast:

<?xml version="1.0" encoding="UTF-8"?>
<weatherdata>
<location>
<name>Castle Donington</name>
<type></type>
<country>GB</country>
<timezone></timezone>
<location altitude="0.0" latitude="52.8429" longitude="-1.3419" geobase="geonames" geobaseid="2653591"></location>
</location>
<credit></credit>
<meta>
<lastupdate></lastupdate>
<calctime>0.223</calctime>
<nextupdate></nextupdate>
</meta>
<sun rise="2018-10-10T06:22:54" set="2018-10-10T17:20:41"></sun>
<forecast>
<time from="2018-10-10T09:00:00" to="2018-10-10T12:00:00">
<symbol name="clear sky" number="800" var="01d"></symbol>
<precipitation unit="3h" value="0.0"></precipitation>
<windDirection deg="129.505" code="SE" name="SouthEast"></windDirection>
<windSpeed mps="5.76" name="Moderate breeze"></windSpeed>
<temperature unit="kelvin" value="292.47" min="292.47" max="292.811"></temperature>
<pressure value="1015.01" unit="hPa"></pressure>
<humidity value="74" unit="%"></humidity>
<clouds value="clear sky" all="0" unit="%"></clouds>
</time>
....


but this doesn't:

current conditions:
<?xml version="1.0" encoding="UTF-8"?>
<current>
<city id="0" name="">
<coord lon="-1.38" lat="52.83"></coord>
<country></country>
<sun rise="2018-10-10T06:08:34" set="2018-10-10T20:08:34"></sun>
</city>
<temperature value="288.03302" min="288.03302" max="288.03302" unit="kelvin"></temperature>
<humidity value="26" unit="%"></humidity>
<pressure unit="hPa" value="990.60767"></pressure>
<wind>
<speed value="20.528172" name="gentle breeze"></speed>
<gusts></gusts>
<direction value="302.0" code="E" name="East"></direction>
</wind>
<clouds value="26" name="broken clouds"></clouds>
<visibility value="7603"></visibility>
<precipitation mode="rain" unit="3h" value="2.0"></precipitation>
<weather number="800" value="heavy intensity rain" icon="01n"></weather>
<lastupdate value="2018-10-10T10:08:34"></lastupdate>
</current>

forecast:
<?xml version="1.0" encoding="UTF-8"?>
<weatherdata>
<location>
<name></name>
<type></type>
<country></country>
<timezone></timezone>
<location altitude="0.0" latitude="52.83" longitude="-1.38" geobase="geonames" geobaseid=""></location>
</location>
<credit></credit>
<meta>
<lastupdate></lastupdate>
<calctime>0.01</calctime>
<nextupdate></nextupdate>
</meta>
<sun rise="2018-10-10T06:08:34" set="2018-10-10T20:08:34"></sun>
<forecast>
<time from="2018-10-10T13:18:34" to="2018-10-10T16:18:34">
<symbol name="light rain" number="500" var="10n"></symbol>
<precipitation unit="3h" value="0.0" type="no"></precipitation>
<windDirection deg="302.0" code="NNE" name="North-northeast"></windDirection>
<windSpeed mps="20.518131" name="gentle Breeze"></windSpeed>
<temperature unit="kelvin" value="288.02045" min="288.02045" max="288.02045"></temperature>
<pressure value="990.2873" unit="hPa"></pressure>
<humidity value="14" unit="%"></humidity>
<clouds value="few clouds" all="27" unit="%"></clouds>
</time>
....



The headers are the same, so I'm wondering if the game is checking the location information. Unless there's something else I've missed?

[edit] i also aligned the forecast timings so they're on the hour, every 3 hours. No change.

So it's either condition name / codes / weather symbols that I need to implement (lots of lookups and faffing) or proper location information (lots more lookups and faffing). Grrr.

Asturbo
10-10-2018, 10:50
There're some differences but probably doesn't affect:

<name>Castle Donington</name>
<country>GB</country>
geobaseid=""

Other one is the forecast pattern. If you see how is generated, the slots are fixed with 3 hours time: 0:00 to 3:00, 3:00 to 6:00, 6:00 to 9:00...

Probably you need the next fixed cicle to the current time. In your example:

<forecast>
<time from="2018-10-10T15:00:00" to="2018-10-10T18:00:00">

In this post (http://forum.projectcarsgame.com/showthread.php?58197-Real-weather&p=1502109&viewfull=1#post1502109) is a theory of how weather slots are filled using weathermap info.

mr_belowski
10-10-2018, 10:57
Ah, i think it's the

<weather number="721" value="haze" icon="50d"></weather>

element

mr_belowski
10-10-2018, 12:38
ok, i think i have this working now. The generated weather now needs some attention (and testing, obviously), so there's still a lot to do. I'll focus on driving it with some external inputs next, and see if I can make the transitions happen faster than real time so we can have random 'slots' like the game UI provides (but without all the silly extremes).

I'll change the random weather generator to have 3 overall weather types - good, changeable and bad. At them moment the generator is always creating changeable weather, which is nice but it means there's usually rain at some point, which isn't right.

Won't be long till this little experiment is ready to be tested - I'll package it up at some point. It'll require a JRE installation.

Zeratall
11-10-2018, 06:03
ok, i think i have this working now. The generated weather now needs some attention (and testing, obviously), so there's still a lot to do. I'll focus on driving it with some external inputs next, and see if I can make the transitions happen faster than real time so we can have random 'slots' like the game UI provides (but without all the silly extremes).

I'll change the random weather generator to have 3 overall weather types - good, changeable and bad. At them moment the generator is always creating changeable weather, which is nice but it means there's usually rain at some point, which isn't right.

Won't be long till this little experiment is ready to be tested - I'll package it up at some point. It'll require a JRE installation.

nooooooooooo java =P , all jokes aside, great work bud!! Love this man in the middle re route tactic!

mr_belowski
11-10-2018, 07:55
Here's the repo, with a readme and a pre-built jar file if anyone wants a look:

https://github.com/mrbelowski/PCars2OpenweatherServer

this is still work in progress, but should work

Asturbo
11-10-2018, 07:58
Tested the initial beta yesterday and it works perfectly. The real weather using my own key, get real weather data and applies correctly in-game. Tested with several locations and always got real weather.

Tested also the random weather and looks working too.

Great job, Belowski

mr_belowski
11-10-2018, 08:08
thanks dude. If anyone wants to contribute, now would be a good time.

Stuff to do...

Testing
Maybe some kind of GUI
Better auto generation of weather
Make the random weather generation location-specific (i.e. use the latitude and longitude to create more realistic conditions for the location)

Asturbo
11-10-2018, 08:17
More stuff to do:

- Change the title of the thread. [Done]
- Add a contributors link for the programmer [Your work :very_drunk:]

I was sure that my original idea should work, but you make it real. Many thanks, Belowski

Let's continue testing...

mr_belowski
11-10-2018, 08:27
To keep everything in one place, it's probably best to raise bugs in the GitHub repo so I can keep track of them all

mr_belowski
11-10-2018, 19:19
looks like this isn't going to work as well as we'd hoped. The game will ask for the weather data at the start of a session but doesn't request any more data for at least an hour (not tested it beyond 1 hour). As far as I can see it doesn't allow for changing conditions as we'd hoped. I'll keep experimenting :(

Asturbo
11-10-2018, 19:31
I think that the game uses actual data and forcast to generate the weather slots.
So probably if you change the "actual weather" in your app, has no effect. I'll make some test too, but if the game works in this way, obviously you can't do anything.
Anyway with your app we recover the real weather as was designed.

Javaniceday
11-10-2018, 19:34
looks like this isn't going to work as well as we'd hoped. The game will ask for the weather data at the start of a session but doesn't request any more data for at least an hour (not tested it beyond 1 hour). As far as I can see it doesn't allow for changing conditions as we'd hoped. I'll keep experimenting :(

Is it possible to focus on requesting % chance of precipitation, and then having the game create the slots based on that %?

morpwr
11-10-2018, 21:44
I think that the game uses actual data and forcast to generate the weather slots.
So probably if you change the "actual weather" in your app, has no effect. I'll make some test too, but if the game works in this way, obviously you can't do anything.
Anyway with your app we recover the real weather as was designed.

That alone would be awesome. I miss using real weather and not knowing what im getting.

mr_belowski
22-10-2018, 12:57
Anyone had a chance to take a look at this?

I did some rework to make the app match the game's expectations a little better, so the forecast is now (by default) in 3 hour slots, starting at midnight. The proxying works well (although there are times when the game doesn't even bother to call the weather API, no idea why).

The latest build is available in the repository and the documentation is up to date

morpwr
24-10-2018, 23:06
Anyone had a chance to take a look at this?

I did some rework to make the app match the game's expectations a little better, so the forecast is now (by default) in 3 hour slots, starting at midnight. The proxying works well (although there are times when the game doesn't even bother to call the weather API, no idea why).

The latest build is available in the repository and the documentation is up to date


I would if I had any idea what you mean by all the things youre talking about. Could we explain it for us non programming savvy could understand.lol Im sure im not alone when I say I have no idea what a jar file is.

Sloskimo
25-10-2018, 18:23
Perhaps you could include an option to set weather in the 4 slots on a dedicated server, if people provide their user/pass/ip/port for the http api on their DS.

It's quite easily set via the http api and next_session, it then allows any slot duration without relying on the game to request it. I've got a rather crude solution going myself via a weather api/php and cron, can not code very well either, but it works amazingly well. If somehow this is already covered, I said nothing, I just browsed around a bit and came across this thread.

Schnizz58
26-10-2018, 16:31
I would if I had any idea what you mean by all the things youre talking about. Could we explain it for us non programming savvy could understand.lol Im sure im not alone when I say I have no idea what a jar file is.

Someone correct me if I'm off base here but what he has done is create a service that intercepts the request that the game makes to get weather information. This type of service is called a proxy because it is going to respond to the request "by proxy" for the real openweather.org service. It will generate random weather and send that to the game and the game never knows that it didn't come from openweather.

There's a programming language called Java and a jar file is a package of Java code and other resources like images and text files. It stands for Java ARchive.

Asturbo
26-10-2018, 19:41
Perhaps you could include an option to set weather in the 4 slots on a dedicated server, if people provide their user/pass/ip/port for the http api on their DS.
Yes that was an option, but restricts the people that can use it.

How is working now, the app works like a ghost weather server, and it could be used offline or online with a DS or P2P using the ingame real weather option. If you play online, only the host of the session (the 1st one who logs) needs to connect to the java applet (DS or P2P) and works exactly as it should work in the game. I'm using this option for the last races of my comunity (with the real weather proxy option) and it worked perfectly with accurate real weather data.

In my case I'm running the java app in the same computer than my DS, but it doesn't comunicate directly with it. The app could be in the same computer where I play, but I don't like other apps in background while playing (but also checked and it works). When I log to the DS and I select the circuit, the game connects to the proxy (also running in the DS machine), and the proxy gets the weather data from the public service with a valid key. Then my computer passes the data to the DS, and the DS to the rest of the players of the session.


Someone correct me if I'm off base here but what he has done is create a service that intercepts the request that the game makes to get weather information. This type of service is called a proxy because it is going to respond to the request "by proxy" for the real openweather.org service. It will generate random weather and send that to the game and the game never knows that it didn't come from openweather.
Yes, that's correct. The app has two different modes:

- Proxy: The app connects to internet and gets the data for you when you start any session with the real weather option. You "cheat" the game (from the OS with the host file trick) to redirect to the APP from the public weather service to your own weather server. The app needs a valid key to get the weather data (user key obtained registering), but the app doesn't use it to pass the data to the game, so it works in the same way as the original server.

- Random: The app generates automatically the weather slots based in your preferences (but still random). In this case, the app doesn't need to connect to the real web server and generates the random slots. I haven't much time to test this option, but if it works well, would be my prefered.

In the link of Mrbelowsky, you have more information: https://github.com/mrbelowski/PCars2OpenweatherServer

morpwr
26-10-2018, 22:53
Someone correct me if I'm off base here but what he has done is create a service that intercepts the request that the game makes to get weather information. This type of service is called a proxy because it is going to respond to the request "by proxy" for the real openweather.org service. It will generate random weather and send that to the game and the game never knows that it didn't come from openweather.

There's a programming language called Java and a jar file is a package of Java code and other resources like images and text files. It stands for Java ARchive.


I got that part. I just don't understand how to use that type of file. It looks very different from the stuff im used to seeing.

Sloskimo
26-10-2018, 23:33
@Asturbo I get your point, but afaik the game likes its weather in rather large chunks, this way provides more granular control. E.g. you can have two rain showers in a 30 minute race with some sun and whatever in between etc.

I do not propose replacing what is there, just giving the option of setting it on a DS.

shovas
28-10-2018, 01:30
Thanks for making that java app. It was very cool to see it fetching weather data when I selected the track and to see when I loaded up the race the correct weather was added. I tried a few places that were either clear or overcast and then tried the Nurburgring which had light rain/overcast in the openweathermap.org data and PC2 chose foggy, which is okay with me.

I did get a crash to desktop in that race, though, and that's a first for me. Not sure if it's the Real Weather or not.

EDIT: Tried Nurburgring again and it didn't crash. Probably just had PC2 running too long before that and it finally bailed.

morpwr
03-11-2018, 16:58
Can somebody help me get this working in proxy mode. I think I have it figured out but I want to make sure because im not familiar with java stuff at all. Do I add those lines highlighted in pink with my information for the ids?

Asturbo
03-11-2018, 19:43
@morpwr, here is a fast video-capture of how configure it:


https://www.youtube.com/watch?v=-2lbQYSpx5A&amp;feature=youtu.be

Some notes:

- The text file with the launch command must be saved with .BAT extension to be executable, and must be in same folder than the app.
- You need Java installed in your computer.
- You need to keep the java app running while playing to answer the game querys when weather data is needed.
- The App could be executed in a different computer (you have to adjust the host file of the computer running PC to point to the IP of the computer running the APP)
- In MP only the host of the online session needs to accees to the Proxy App.
- You have to remove the line in the host file if some day this option works again in-game.
- If your firewall asks for the app trying to connect to internet, allow it, because it needs connection to openweathermap.org to retrieve the data.

morpwr
04-11-2018, 12:26
@morpwr, here is a fast video-capture of how configure it:


https://www.youtube.com/watch?v=-2lbQYSpx5A&feature=youtu.be

Notes:

- You need Java installed
- You need the java app running while playing
- The App could run in a different computer (you have to adjust the host file of the gaming PC to point to the right IP)
- In MP only the host of the online session needs to acceess to the Proxy App.
- You must remove the line in the host file if some day this option works again in-game

You aren't kidding fast.lol Thanks for the video. My only issue is it wont let me save the edit in the host file. Any ideas why?

mr_belowski
04-11-2018, 12:28
hostsfile need to be edited as administrator - run notepad (or whatever) as admin and you'll be able to save it.

Also, thanks for helping out Astro :)

Asturbo
04-11-2018, 12:44
You aren't kidding fast.lol Thanks for the video. My only issue is it wont let me save the edit in the host file. Any ideas why?
Play the video at 0.5 speed :)

You can execute notepad as admin as Belowski said, or save the file to the desktop, and then move to C:\Windows\System32\drivers\etc. Will ask confirmation...

Remember that this file has no extension (no TXT if Notepad asks)

morpwr
04-11-2018, 13:19
Play the video at 0.5 speed :)

You can execute notepad as admin as Belowski said, or save the file to the desktop, and then move to C:\Windows\System32\drivers\etc. Will ask confirmation...

Remember that this file has no extension (no TXT if Notepad asks)


Unfortunately building a pc is easy but learning all this stuff you guys know isn't.lol Thanks again for the help.

thomasjohansen
04-11-2018, 16:09
When using proxy and its saying "No active profile set, falling back to default profiles: default"

is it because the api key is not active yet?

mr_belowski
04-11-2018, 17:29
No, that message can be ignored

Mike Scott
04-11-2018, 20:55
Thank you mr belowski for developing the app and Asturbo for capturing the video tutorial on how to use it. Everything works as advertised on my end. It's good to have real weather back in the game!

morpwr
08-11-2018, 23:54
Play the video at 0.5 speed :)

You can execute notepad as admin as Belowski said, or save the file to the desktop, and then move to C:\Windows\System32\drivers\etc. Will ask confirmation...

Remember that this file has no extension (no TXT if Notepad asks)

Ok I almost got it working. It keeps telling me it cant access the jar file. What did you mean by the .bat extension in notes? Im sorry guys I just have no idea with java.

Asturbo
09-11-2018, 07:16
A BATCH file (BAT extension) is a text file that includes a secuence of commands. If you write that commands in plaint text (with notepad) and save with BAT extension (also CMD works), you could execute from the explorer that file to avoid typing long commands.

morpwr
09-11-2018, 10:48
A BATCH file (BAT extension) is a text file that includes a secuence of commands. If you write that commands in plaint text (with notepad) and save with BAT extension (also CMD works), you could execute from the explorer that file to avoid typing long commands.

Ok im pretty sure I did that part right. It looks like yours in the video except with my ip and key. So any ideas why it cant open OW? My header at the top looks like yours with the cmd line. Is there something I need to do with the open weather download? It tries to work when I click on the start file but doesn't. I really appreciate the help too.

Asturbo
09-11-2018, 12:06
Post your BAT file to try it in my computer. Any error in the CMD screen when launch? If the BAT file closes to fast to see the error, add a final line with "pause" to wait for any key.

morpwr
09-11-2018, 12:24
Post your BAT file to try it in my computer. Any error in the CMD screen when launch? If the BAT file closes to fast to see the error, add a final line with "pause" to wait for any key.

Yes it says it cant open the Openweather file. I tried with and without the pause. Without the pause it doesn't do anything. Im sure its something stupid I did wrong.:(

I cant post the BAT file now im at work.

Asturbo
09-11-2018, 13:04
Yes it says it cant open the Openweather file. I tried with and without the pause. Without the pause it doesn't do anything. Im sure its something stupid I did wrong.:(
Probably it's a problem with the location / name of the java file. In my BAT file, it's in the same folder, so no route needed. If your BAT is in a different location than the java file, you need to specify the folder.

morpwr
09-11-2018, 13:59
Probably it's a problem with the location / name of the java file. In my BAT file, it's in the same folder, so no route needed. If your BAT is in a different location than the java file, you need to specify the folder.

Do I need to take the open weather java file out of the download? I just have the download in the file with the BAT file.

Asturbo
09-11-2018, 14:10
You only need the JAR file from here https://github.com/mrbelowski/PCars2OpenweatherServer/tree/master/build

And the .BAT in same folder as the .JAR file. You can move the BAT to your download folder. In the video both files are in my desktop.

When together, execute the BAT and you should see a DOS window scrolling with a message of "started in XX seconds" at the end. Then it's ready waiting for querys from the game.

You can test also from your browser connecting to http://127.0.0.1 and you'll receive a message of invalid parameters, but that confirms that the server is listening and waiting for a correct query.

morpwr
09-11-2018, 18:42
You only need the JAR file from here https://github.com/mrbelowski/PCars2OpenweatherServer/tree/master/build

And the .BAT in same folder as the .JAR file. You can move the BAT to your download folder. In the video both files are in my desktop.

When together, execute the BAT and you should see a DOS window scrolling with a message of "started in XX seconds" at the end. Then it's ready waiting for querys from the game.

You can test also from your browser connecting to http://127.0.0.1 and you'll receive a message of invalid parameters, but that confirms that the server is listening and waiting for a correct query.


I think that's my issue I didn't take the jar file out of the download file.:cower:

thomasjohansen
09-11-2018, 18:56
Im experimenting with the proxy modeand have my api working.

using accelerated time.

1. Weather is different from clear but dont fit location weather/time according to openweathermap.
2. I dont get any weather change over time (weather slots).

Example:

At redbull, openweather says light rain.
in the java output it says


2018-11-09 20:48:48.596 INFO 9304 --- [p-nio-80-exec-6] o.b.w.controller.WeatherController : <?xml version="1.0" encoding="UTF-8"?>
<weatherdata>
<location>
<name>Flatschach</name>
<type></type>
<country>AT</country>
<timezone></timezone>
<location altitude="0.0" latitude="47.2167" longitude="14.75" geobase="geonames" geobaseid="2779506"></location>
</location>
<credit></credit>
<meta>
<lastupdate></lastupdate>
<calctime>0.0034</calctime>
<nextupdate></nextupdate>
</meta>
<sun rise="2018-11-09T05:56:58" set="2018-11-09T15:32:09"></sun>
<forecast>
<time from="2018-11-09T18:00:00" to="2018-11-09T21:00:00">
<symbol name="light rain" number="500" var="10n"></symbol>
<precipitation unit="3h" value="0.13" type="rain"></precipitation>
<windDirection deg="160.002" code="SSE" name="South-southeast"></windDirection>
<windSpeed mps="0.89" name="Calm"></windSpeed>
<temperature unit="kelvin" value="281.32" min="279.219" max="281.32"></temperature>
<pressure value="906.19" unit="hPa"></pressure>
<humidity value="100" unit="%"></humidity>
<clouds value="overcast clouds" all="88" unit="%"></clouds>
</time>
<time from="2018-11-09T21:00:00" to="2018-11-10T00:00:00">
<symbol name="light rain" number="500" var="10n"></symbol>
<precipitation unit="3h" value="0.105" type="rain"></precipitation>
<windDirection deg="187.507" code="S" name="South"></windDirection>
<windSpeed mps="0.73" name="Calm"></windSpeed>
<temperature unit="kelvin" value="280.46" min="278.879" max="280.46"></temperature>
<pressure value="905.43" unit="hPa"></pressure>
<humidity value="100" unit="%"></humidity>
<clouds value="overcast clouds" all="88" unit="%"></clouds>
</time>
<time from="2018-11-10T00:00:00" to="2018-11-10T03:00:00">
<symbol name="light rain" number="500" var="10n"></symbol>
<precipitation unit="3h" value="0.07" type="rain"></precipitation>
<windDirection deg="197.5" code="SSW" name="South-southwest"></windDirection>
<windSpeed mps="0.81" name="Calm"></windSpeed>
<temperature unit="kelvin" value="279.18" min="278.125" max="279.18"></temperature>
<pressure value="904.76" unit="hPa"></pressure>
<humidity value="100" unit="%"></humidity>
<clouds value="broken clouds" all="64" unit="%"></clouds>
</time>
<time from="2018-11-10T03:00:00" to="2018-11-10T06:00:00">
<symbol name="light rain" number="500" var="10d"></symbol>
<precipitation unit="3h" value="0.045" type="rain"></precipitation>
<windDirection deg="218.016" code="SW" name="Southwest"></windDirection>
<windSpeed mps="0.88" name="Calm"></windSpeed>
<temperature unit="kelvin" value="277.45" min="276.92" max="277.45"></temperature>
<pressure value="904.24" unit="hPa"></pressure>
<humidity value="100" unit="%"></humidity>
<clouds value="broken clouds" all="68" unit="%"></clouds>
</time>
<time from="2018-11-10T06:00:00" to="2018-11-10T09:00:00">
<symbol name="light rain" number="500" var="10d"></symbol>
<precipitation unit="3h" value="0.03" type="rain"></precipitation>
<windDirection deg="217.501" code="SW" name="Southwest"></windDirection>
<windSpeed mps="0.99" name="Calm"></windSpeed>
<temperature unit="kelvin" value="278.87" min="278.87" max="278.87"></temperature>
<pressure value="904.5" unit="hPa"></pressure>
<humidity value="93" unit="%"></humidity>
<clouds value="few clouds" all="20" unit="%"></clouds>
</time>
<time from="2018-11-10T09:00:00" to="2018-11-10T12:00:00">
<symbol name="light rain" number="500" var="10d"></symbol>
<precipitation unit="3h" value="0.01" type="rain"></precipitation>
<windDirection deg="179.001" code="S" name="South"></windDirection>
<windSpeed mps="0.99" name="Calm"></windSpeed>
<temperature unit="kelvin" value="282.866" min="282.866" max="282.866"></temperature>
<pressure value="903.63" unit="hPa"></pressure>
<humidity value="79" unit="%"></humidity>
<clouds value="clear sky" all="0" unit="%"></clouds>
</time>
<time from="2018-11-10T12:00:00" to="2018-11-10T15:00:00">
<symbol name="clear sky" number="800" var="01d"></symbol>
<precipitation unit="3h" value="0.0"></precipitation>
<windDirection deg="168.001" code="SSE" name="South-southeast"></windDirection>
<windSpeed mps="0.78" name="Calm"></windSpeed>
<temperature unit="kelvin" value="281.528" min="281.528" max="281.528"></temperature>
<pressure value="903.49" unit="hPa"></pressure>
<humidity value="85" unit="%"></humidity>
<clouds value="clear sky" all="0" unit="%"></clouds>
</time>
<time from="2018-11-10T15:00:00" to="2018-11-10T18:00:00">
<symbol name="clear sky" number="800" var="01n"></symbol>
<precipitation unit="3h" value="0.0"></precipitation>
<windDirection deg="164.5" code="SSE" name="South-southeast"></windDirection>
<windSpeed mps="0.71" name="Calm"></windSpeed>
<temperature unit="kelvin" value="275.719" min="275.719" max="275.719"></temperature>
<pressure value="903.59" unit="hPa"></pressure>
<humidity value="96" unit="%"></humidity>
<clouds value="clear sky" all="0" unit="%"></clouds>
</time>
</forecast>
</weatherdata>




I have set the race to start at 10. nov 2018 at 9.00 am

P.cars2 sets the weather to be foggy!

whats wrong here?
By the way in denmark where I am now, openweather says its foggy atm, is it a coincidence?


how is the weather slots affected over time when using accelerated time?

morpwr
10-11-2018, 01:50
You only need the JAR file from here https://github.com/mrbelowski/PCars2OpenweatherServer/tree/master/build

And the .BAT in same folder as the .JAR file. You can move the BAT to your download folder. In the video both files are in my desktop.

When together, execute the BAT and you should see a DOS window scrolling with a message of "started in XX seconds" at the end. Then it's ready waiting for querys from the game.

You can test also from your browser connecting to http://127.0.0.1 and you'll receive a message of invalid parameters, but that confirms that the server is listening and waiting for a correct query.

ok that was the major problem. I didn't take the jar file out but now its telling me the tomcat configured to listen to port 80 failed to start. The port may be in use already or misconfigured. Again thanks for all the help.

M. -VIPER- Morgan
10-11-2018, 06:28
ok that was the major problem. I didn't take the jar file out but now its telling me the tomcat configured to listen to port 80 failed to start. The port may be in use already or misconfigured. Again thanks for all the help.

In this case it seems that another program or service is already using TCP port 80 (=http) and only one can use it.
Download TCPview from sysinternals and start it. It will show you which binaries (exe-files) using which TCP ports.
In the column "Local Address" you have to search after [your computer name]:http

morpwr
10-11-2018, 14:37
In this case it seems that another program or service is already using TCP port 80 (=http) and only one can use it.
Download TCPview from sysinternals and start it. It will show you which binaries (exe-files) using which TCP ports.
In the column "Local Address" you have to search after [your computer name]:http

That's weird I just tried starting it again after running TCPview and the windows popup for blocking it came up. Didn't do this at all last night.wtf lol Allowed access and now it seems to work. Hopefully it will still work when everything else is running. Thanks again for every ones help.

morpwr
11-11-2018, 12:46
[QUOTE=mr_belowski;1548399]hostsfile need to be edited as administrator - run notepad (or whatever) as admin and you'll be able to save it.

Also, thanks for helping out Astro :)[/QUOTE


Thanks again for making these great apps. It works like a champ.:cool: So nice to have real weather back.

Asturbo
11-11-2018, 14:10
Thanks again for making these great apps. It works like a champ.:cool: So nice to have real weather back.
Great :)

morpwr
11-11-2018, 14:55
Great :)

Yes and thanks again for all your help.

Sean_S36
11-11-2018, 21:41
Great :)

Can make it to a EXE installation for pc illiterate please?

morpwr
11-11-2018, 23:10
Can make it to a EXE installation for pc illiterate please?

Its not that bad if you follow asturbos video just make sure you extract the jar folder from the download.:o Its actually pretty simple if you don't skip that step. That and sign up first so you have a working key for the weather api. Otherwise you may have to wait a couple hours before they activate it.

morpwr
30-11-2018, 10:53
Does Mr Bs app possibly work better then the original pcars version? First time ever I had it start to sprinkle then get a little stronger and stop then start actually raining and thinking oh crap as I half way around Spa on slicks. It was about as much as you could ask for real weather and made for a very real experience. I checked the api and it looked like it followed it correctly. Great job like always Mr B!!!

Konan
30-11-2018, 17:10
Great job like always Mr B!!!

...and Asturbo...:cool:

Asturbo
30-11-2018, 18:26
...and Asturbo...:cool:
Nah, I just diagnosed the problem and proposed a teorical solution, but the merit of making it real is only of Mr Belowsky.

OlivierMDVY
27-01-2019, 13:34
I tried but I've got the error below:
264196

Asturbo
27-01-2019, 14:06
You probably have another service using port 80 and it can't be used by the app.

You can execute in elevated mode if the 80 port is beeing used with:

netstat -a -n -o | find ":80"

Other option is that you don't have permissions to open port. Ejecute in elevated mode and check your firewall.

OlivierMDVY
27-01-2019, 14:19
When you writing: execute in elevated mode, you mean Run as Administrator?
By the way I have several applications which use port 80 (Microsoft Store, Skype, ...)

Asturbo
27-01-2019, 14:28
When you writing: execute in elevated mode, you mean Run as Administrator?
Yes


By the way I have several applications which use port 80 (Microsoft Store, Skype, ...)
The port 80 is used usually by web services. Those applications you comment, connect to the port 80 of remote machines, not to your own IP.
That's not a problem. The app need open the 80 port to listen querys from the game and looks that other software is using this port in your computer.

OlivierMDVY
27-01-2019, 16:00
Running as administrator hasn't solved the issue.
I have also suspended the Kaspersky protection, same issue.

Is there a way to use a different port?

OlivierMDVY
27-01-2019, 16:13
here is the list of applications which uses the port 80:
264197

Asturbo
27-01-2019, 16:15
Is there a way to use a different port?
No, because PCARS2 querys the 80 port to get RW, so you have to listen that port in the host machine.
You can use another computer and change the query with the host file to that computer.

morpwr
28-01-2019, 10:40
Running as administrator hasn't solved the issue.
I have also suspended the Kaspersky protection, same issue.

Is there a way to use a different port?


This looks like the same problem I had if you look back a couple pages. Do you leave your pc on all the time? Id try shutting it down and see if you get a pop up for it from windows on restart. I have no idea why but I went though the same thing as you then all of a sudden I got a windows pop up asking to allow it and it worked fine after that.

morpwr
29-04-2019, 18:55
Is this still working for every one? All of a sudden mine quit working.

Mike Scott
04-05-2019, 12:21
mine stopped working as well about 2 weeks ago. I reverted the Windows hosts file, pinged the weather provider's site, and it turned out the ip address changed. So basically repeat the entire installation procedure and make sure you get the new ip address.

morpwr
04-05-2019, 12:51
mine stopped working as well about 2 weeks ago. I reverted the Windows hosts file, pinged the weather provider's site, and it turned out the ip address changed. So basically repeat the entire installation procedure and make sure you get the new ip address.

That's about when I noticed mine stopped working. Thanks. Hope that's all it is I really miss having the weather just work.

conan_81
26-05-2019, 14:26
Is there a way to change OWM informations? Their weather forecast is really really too "pessimistic"... I usually get heavy rain conditions even if in the real world it doesn't rain (for example, today at Spa I get rain but on the circuit webcam it is only cloudy)

(OT: Is PC2 using informations like Wind, Pressure and Humidity?)