Weather station and Weather Underground -> Work around

@Kr0llx @drbytes Now I understand why you got lost by my questions, I am sorry :confused: as I was so blind trying to see data from weather stations over lan that I missed the purpose of this web site that provide Home Assistant. I have now created my Home Assistant on a virtual machine (for test purpose). I’ll see later which hardware I dedicate for this purpose. Now I need to figure out next step.

I’m wondering which brand and model of router you’re using. it looks like you can program rules in it.
I’m using TPlink TD W-8968 and I did not figure out how to route the IP adress of PWS else where.
Could you please give more details?

What Kr0llx posts looks like a standard linux system.
I use a Mikrotik router.

Both systems are more advanced than your standard router although consumer routers exist that offer decent packet control.

@ drbytes

Thank you for the answer. I feel some annoyance in Your answer and I’m sorry for that as explained I’m mechanical engineer and beginner in software. For me this programming language or another one could be slightely interpreted but honestly I’m not able to tell who is who.

I was just wondering if I could reuse this device (I did not find and understand what I could do going thru documentation). Or if I will need to by a device that would allow me to properly redirect this IP adress to internal IP adress.

Thx for this post, I have the same PWS and using the PHP script I managed to get the info into HA.
I had to do some other modifications, the bracket mentioned by another user was one. Another was a change in the capitalisation of the MQTT client object and add some code to authenticate to my MQTT broker, because I have my MQTT broker secured with a user and password… Below the changes I made to get the authentication to work (incl the capitalisation when establishing the connection):

use PhpMqtt\Client\ConnectionSettings;
.
$mqttUser = "Username";
$mqttPassword = "Password";
.
$mqtt = new MqttClient($server, $port, $client_id);
$connectionSettings = (new ConnectionSettings)
->setConnectTimeout(3)
->setUsername($mqttUser)
->setPassword($mqttPassword)
$mqtt->connect($connectionSettings, true);

And I also used the phpmqtt/client mentioned in a previous reply, for people trying this and not to familiar with php development, use this command in the same folder that you created the php-script:

composer require php-mqtt/client (if necessary sudo this command)

@drbytes The temperatures in the screenshot of your dashboard for the living and garage where are those comming from? I’m thinking about buying an additional temp/hygro meter for the PWS and wonder how the measurements of that unit will be transmitted.

Greetings from a fellow Belgian :wink:

I’m happy you got it working!

The living temp is coming from the antiquated nest thermostat, it offers temp and relative humidity. The garage is the temperature coming from the actual weather station display. I broke the f’cking screen shortly after my first post, rendering it useless, so I moved it to the garage where it can still serve as temp sensor.

I don’t really need it now I have all the data in HA :slight_smile:

Very nice thread you have going on here.
I would like some help to get this up and running myself.

I am struggling with getting the updateweatherstation.php script output anything to port 1883.

My setup:

  • My Bresser is on 192.168.150.64.
  • My Pfsense router redirects all traffic (with destination port 80) from the Bresser to a port 80 of a Raspberry Pi 3 on 192.168.120.62.
  • My HA instance lives at 192.168.120.63, which runs the Mosquitto broker add-on. I have created an “MQTT user” (non admin and only local login) with username “mqtt_user” and password “mqtt_pass” in HA to use with this MQTT broker.

Using the “packet capture” option in my Pfsense router and Wireshark to display the data, I can see that the data form the Bresser looks like:

GET /weatherstation/updateweatherstation.php?ID=&PASSWORD=&action=updateraww&realtime=1&rtfreq=5&dateutc=now&baromin=30.62&tempf=47.4&dewptf=44.6&humidity=90&windspeedmph=7.6&windgustmph=9.3&winddir=68&rainin=0.0&dailyrainin=0.0&indoortempf=67.2&indoorhumidity=54 HTTP/1.1 

And that data is succesfully redirected to the Pi 3:

20:17:18.654767 IP 192.168.150.64.63894 > 192.168.120.62.80: tcp 334

So far so good.

Now comes the harder part since I have had zero experience with PHP.
I followed this guide (RPi NginX server with PHP7 | Raspberry Pi Tutorials) to install NGINX with PHP7.4. on the Pi 3. But replaced

sudo apt-get install php7.0-fpm

with

sudo apt-get install php7.4-fpm

since php-mqtt/client requires at least PHP 7.4
I tested this PHP webserver like suggested with an index.php file with the following content in the var/www/html/ directory:

<?php 
phpinfo(); 
?>

This works, the browser shows the PHP info at 192.168.120.62

Next I installed composer as a system wide service using this guide by lindevs.com/install-composer-on-raspberry-pi/

After that I made the “weatherstation” directory, thus creating the folder structure:
var/www/html/weatherstation
A test php-file Hello.php in this directory is successfully accessible at 192.168.120.132/weatherstation/Hello.php:

<html>
 <head>
  <title>PHP Test</title>
 </head>
 <body>
 <?php echo '<p>Hello World</p>'; ?> 
 </body>
</html>

Next I replaced the Hello.php file with the updateweatherstation.php file. I used the script of
drbytes with the supplements of mossc001 and GuyDB21, ending up with this:

<?php

require __DIR__ . '/vendor/autoload.php';

use PhpMqtt\Client\Exceptions\ConnectingToBrokerFailedException;
use PhpMqtt\Client\Exceptions\DataTransferException;
use PhpMqtt\Client\Exceptions\UnexpectedAcknowledgementException;
use PhpMqtt\Client\MqttClient;
use PhpMqtt\Client\ConnectionSettings;

$server = "192.168.120.63";
$port = 1883;
$client_id = "weather-data-publisher";
$mqttRoot = "pws/sensors/";
$mqttUser = "mqtt_user";
$mqttPassword = "mqtt_pass";

// OVERLY VERBOSE HELPER STUFF
function RoundIt($ee){
  return round($ee, 2);
}
function toKM( $a) {
  return  RoundIt( floatval($a)*1.60934);
}
function toC( $a) {
  return RoundIt(  (floatval($a)-32) * (5/9) );
}
function toMM( $a) {
    return RoundIt( floatval($a)*25.4);
}
  
function toHPA( $a) {
  return RoundIt((floatval($a)*33.8639));
}
// FOUND THIS ON THE NET IN SOME PASTEBIN
function wind_cardinal( $degree ) { 
  switch( $degree ) {
      case ( $degree >= 348.75 && $degree <= 360 ):
          $cardinal = "N";
      break;
      case ( $degree >= 0 && $degree <= 11.249 ):
          $cardinal = "N";
      break;
      case ( $degree >= 11.25 && $degree <= 33.749 ):
          $cardinal = "N NO";
      break;
      case ( $degree >= 33.75 && $degree <= 56.249 ):
          $cardinal = "NO";
      break;
      case ( $degree >= 56.25 && $degree <= 78.749 ):
          $cardinal = "O NO";
      break;
      case ( $degree >= 78.75 && $degree <= 101.249 ):
          $cardinal = "O";
      break;
      case ( $degree >= 101.25 && $degree <= 123.749 ):
          $cardinal = "O ZO";
      break;
      case ( $degree >= 123.75 && $degree <= 146.249 ):
          $cardinal = "ZO";
      break;
      case ( $degree >= 146.25 && $degree <= 168.749 ):
          $cardinal = "N";
      break;
      case ( $degree >= 168.75 && $degree <= 191.249 ):
          $cardinal = "Z";
      break;
      case ( $degree >= 191.25 && $degree <= 213.749 ):
          $cardinal = "Z ZW";
      break;
      case ( $degree >= 213.75 && $degree <= 236.249 ):
          $cardinal = "ZW";
      break;
      case ( $degree >= 236.25 && $degree <= 258.749 ):
          $cardinal = "W ZW";
      break;
      case ( $degree >= 258.75 && $degree <= 281.249 ):
          $cardinal = "W";
      break;
      case ( $degree >= 281.25 && $degree <= 303.749 ):
          $cardinal = "W NW";
      break;
      case ( $degree >= 303.75 && $degree <= 326.249 ):
          $cardinal = "NW";
      break;
      case ( $degree >= 326.25 && $degree <= 348.749 ):
          $cardinal = "N NW";
      break;
      default:
          $cardinal = null;
  }
 return $cardinal;
}

// SHUFF IT TO MQTT
$mqtt = new MqttClient($server, $port, $client_id);
$connectionSettings = (new ConnectionSettings)
->setConnectTimeout(3)
->setUsername($mqttUser)
->setPassword($mqttPassword)
$mqtt->connect($connectionSettings, true);

$mqtt->publish($mqttRoot .'baromin', toHPA($_GET["baromin"]), 0);
$mqtt->publish($mqttRoot .'temp', toC($_GET["tempf"]), 0);
$mqtt->publish($mqttRoot .'dewpt', toC($_GET["dewptf"]), 0);
$mqtt->publish($mqttRoot .'humidity', $_GET["humidity"], 0);
$mqtt->publish($mqttRoot .'windspeedkph', toKM($_GET["windspeedmph"]), 0);
$mqtt->publish($mqttRoot .'windgustkph', toKM($_GET["windgustmph"]), 0);
$mqtt->publish($mqttRoot .'winddir',wind_cardinal( $_GET["winddir"]), 0);
$mqtt->publish($mqttRoot .'rainmm', toMM($_GET["rainin"]), 0);
$mqtt->publish($mqttRoot .'dailyrainmm', toMM($_GET["dailyrainin"]), 0);
$mqtt->publish($mqttRoot .'indoortemp', toC($_GET["indoortempf"]), 0);
$mqtt->publish($mqttRoot .'indoorhumidity', $_GET["indoorhumidity"], 0);

$mqtt->close();

// POST TO WU .. OPTIONAL, I SHOULD JUST NOT BECAUSE THEY PULLED A FREE SERVICE AND STILL LEECH DATA OF OF MY INVESTMENT WITHOUT ANY REAL RETURN.
$xml = file_get_contents("http://169.47.111.60/weatherstation/updateweatherstation.php?".$_SERVER['QUERY_STRING']);

?>
success

In the SSH terminal I navigated to the directory var/www/html/updateweatherstation and installed the php-mqtt/client. So now this directory contains the “vendor” directory.

To conclude I added the sensors to the sensor.yaml file in HA, like in the first post of this thread.

As far as my understanding goes this should conclude the whole setup.
However, no sensor data arrives in HA and judging from the capture data in Pfsense, my Pi is not outputting anything at port 1883.

What am I missing here? Do I still need to activate the php-mqtt/client somehow?

If it helps anybody, I’ve created a revised version of the original post that works for me and have documented it slightly different. I’ve also got it posting to Met Office as well as Wunderground.

1 Like

Did you manage to get it work? I want to go your way but have limited knowledge. Thanks !

ask @mossc001, he took it upon himself to copy the code and solution without crediting anyone. He can support it.

@drbytes, this was not my intention; please provide me your handle for GitHub?

Dear @drbytes, thank you for your nice hack!

Wireshark is also telling me the http traffic from my Bresser weather station via fritzbox-tracking.

No NAT rules at fritz!

Unfortunately, my fritz!box 7530AX has no port forwarding options from one IP to another IP (just the classic Port Sharing).

Do you have an idea how to root the traffic from my weather station 192.168.178.36 to my Homeassistant instance 192.168.178.39?
Are there linux based wifi sniff softwares listing in the whole local network which I could install an my Homeeassistant instance?
Or is there a possibility to direct connect constantly (live) to the fritzbox-tracking?

In case anyone is interested I have created a bridge for the Bresser Weather Station and, as it happens, the Holman weather station is the same. The bridge is made up of two ESP32s one that acts as a pass through access point that the weather station connects to that in turn connects to your home WiFi network to virtually connect the weather station to the internet. This first ESP32 also allows the clock on the weather station to be correct as it performs the required NTP functions. The ESP32 ‘bridge’ then outputs the weather station data out one of its serial ports that is read by the second ESP32 that is coded using ESPHome to interface with Home Assistant. The setup works flawlessly and even corrects for wind direction errors if you don’t mount the weather station perfectly North-South. If anyone is interested I can GitHub my solutions.

Please do, i’m verry interested.

Hello, just bought a WPS Bresser 5 in 1 wifi and would like to survey evolution of 2 additional places with extra temp/humidity sensors in my house (important conservation places).
It looks not possible from WU.
Your solution seems very interesting but I’m not competent enough, I don’t understand how to capture data from the WPS with packet sniffer, also how to know WPS IP (IP scanner don’t “see” it).
Any explanation are welcome.
Sincerely
Yvan