0

I am trying to fetch data from my weatherstation sending this every second

Data from tcpdump;

> 
> E..(......^............P...2;2YrP.......
> 04:59:10.442725 IP WeatherStation.53724 > raspberrypi.http: Flags [F.], seq 630, ack 485, win 5276, length 0
> E..(......^............P...2;2YrP.......
> 
> 04:59:10.608802 IP WeatherStation.61637 > 192.168.1.255.59387: UDP, length 47
> E..K......]..............7......,..M..........EasyWeatherPro-10EED6 V5.1.1.

the above line repeats every second

This every 10'th seconds

> E..(......^............P....O...P....k..
> 04:59:26.403455 IP WeatherStation.53725 > raspberrypi.http: Flags [P.], seq 0:630, ack 1, win 5760, length 630: HTTP: POST easyweather HTTP/1.1
> E.........\,...........P....O...P...#...POST easyweather HTTP/1.1

This is the data i want:

> HOST: 192.168.1.21
> Connection: Close
> Content-Type: application/x-www-form-urlencoded
> Content-Length:492
> 
> PASSKEY=F33E247FAB61AEBFC52270E8FA784A8F&stationtype=EasyWeatherPro_V5.1.1&runtime=4&dateutc=2023-08-01+03:59:25&tempinf=70.3&humidityin=46&baromrelin=29.834&baromabsin=29.264&tempf=49.6&humidity=95&winddir=198&windspeedmph=0.00&windgustmph=0.00&maxdailygust=0.00&solarradiation=10.04&uv=0&rainratein=0.000&eventrainin=0.000&hourlyrainin=0.000&dailyrainin=0.000&weeklyrainin=0.020&monthlyrainin=0.000&yearlyrainin=0.020&totalrainin=0.020&wh65batt=0&freq=868M&model=WS2900_V2.01.18&interval=10**

This curl code is similar to the thread; PHP file_get_contents() returns "failed to open stream: HTTP request failed!"

PhP Code

<?php
header("Refresh: 1");
$lurl=get_fcontent("http://WeatherStation");
print_r($lurl);

function get_fcontent( $url,  $javascript_loop = 0, $timeout = 5 ) {
    $url = str_replace( "&amp;", "&", urldecode(trim($url)) );
    $ch = curl_init();
    curl_setopt( $ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; rv:1.7.3) Gecko/20041001 Firefox/0.10.1" );
    curl_setopt( $ch, CURLOPT_URL, $url );
    curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, true );
    curl_setopt( $ch, CURLOPT_ENCODING, "" );
    curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
    curl_setopt( $ch, CURLOPT_AUTOREFERER, true );
    curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false );
    curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, $timeout );
    curl_setopt( $ch, CURLOPT_TIMEOUT, $timeout );
    curl_setopt( $ch, CURLOPT_MAXREDIRS, 10 );
    curl_setopt( $ch, CURLOPT_RETURNTRANSFER,true);
    $content = curl_exec( $ch );
    $response = curl_getinfo( $ch );
    curl_close ( $ch );
    return array( $content, $response );
}

It seams to only output the header;

[1] => Array ( [url] => http://WeatherStation/ [content_type] => text/html [http_code] => 200 [header_size] => 90 [request_size] => 183 [filetime] => -1 [ssl_verify_result] => 0 [redirect_count] => 0 [total_time] => 0.115851 [namelookup_time] => 0.088763 [connect_time] => 0.091165 [pretransfer_time] => 0.091338 [size_upload] => 0 [size_download] => 1480 [speed_download] => 12869 [speed_upload] => 0 [download_content_length] => 1480 [upload_content_length] => -1 [starttransfer_time] => 0.100347 [redirect_time] => 0 [redirect_url] => [primary_ip] => 192.168.1.7 [certinfo] => Array ( ) [primary_port] => 80 [local_ip] => 192.168.1.103 [local_port] => 45696 [http_version] => 2 [protocol] => 1 [ssl_verifyresult] => 0 [scheme] => HTTP [appconnect_time_us] => 0 [connect_time_us] => 91165 [namelookup_time_us] => 88763 [pretransfer_time_us] => 91338 [redirect_time_us] => 0 [starttransfer_time_us] => 100347 [total_time_us] => 115851 [effective_method] => GET ) )
Barmar
  • 741,623
  • 53
  • 500
  • 612
JanB
  • 13
  • 4
  • What's the exact endpoint URL? It would be needed for debugging. – nice_dev Aug 01 '23 at 07:07
  • What happened to your earlier question? – Barmar Aug 01 '23 at 07:07
  • The response will be in the `[0]` element of `$lurl`. You only posted `[1]`. – Barmar Aug 01 '23 at 07:10
  • Bamar, I struggled to edit my post with my PhP code. It's my first q here, – JanB Aug 01 '23 at 07:16
  • I'm pretty sure I edited an almost identical post a few hours ago. But I can't find it now, it must have been deleted. Are you working with someone else? – Barmar Aug 01 '23 at 07:17
  • Anyway, it doesn't look like the weather station is running an HTTP server. It's periodically sending the data to the RPi using HTTP. So the RPi needs to run an HTTP server with a page named `easyweather` that collects the data. – Barmar Aug 01 '23 at 07:18
  • See this in the tcpdump: `WeatherStation.53725 > raspberrypi.http` – Barmar Aug 01 '23 at 07:19
  • Barmar, had to delete my first q as I couldn't find a way to insert my php code properly – JanB Aug 01 '23 at 07:28
  • Sorry, to 192.168.1.21. Weatherstation is 192.168.1.7, Raspberry PI, 192.168.1.21 – JanB Aug 01 '23 at 07:40
  • @JanB: Make yourself comfortable with the editing tools, that's what they are for. [help] is around the corner, also if you've got questions how to improve a question. Do not delete your question only because you can't edit them, it's the same functionality but you remove the history of the question incl. it's comments and that will lead to more issues and less useful feedback (for you). – hakre Aug 01 '23 at 07:53
  • @hakre, got it to next time:) – JanB Aug 01 '23 at 08:00
  • Well, now it's too late, but for this question you still have the option. Please see the linked duplicate, it shows how you can check within PHP already what is getting send and received incl. the message bodies and connection details like DNS resolution etc. . – hakre Aug 01 '23 at 08:06

0 Answers0