473,396 Members | 1,900 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Reading a file

Hi,
I have a Temperature sensor with internal web server that provide the data
in a text format.
When quering the ip(ttp://192.168.10.220/temp) of the sensor i get that kind
of reply:
Probe 1|82.2|Probe 2|80.8|Probe 3|-99.9|Probe 4|-99.9
I woud like to import the result into my mysql database.
What is the best way to do this?
Should i use a fopen() ?
I have try with this but i don't know how get just the value data....

Is there a simple way of achieving this?
thanks for your help.
VooDoo
Jul 17 '05 #1
29 2688
VooDoo wrote:
Hi,
I have a Temperature sensor with internal web server that provide the data
in a text format.
When quering the ip(ttp://192.168.10.220/temp) of the sensor i get that
kind of reply:
Probe 1|82.2|Probe 2|80.8|Probe 3|-99.9|Probe 4|-99.9
I woud like to import the result into my mysql database.
What is the best way to do this?
Should i use a fopen() ?
I have try with this but i don't know how get just the value data....

Is there a simple way of achieving this?
thanks for your help.
VooDoo


Hi Voodoo,

1) just fopen the file
$handle = fopen("http://192.168.10.220/temp", "r");

2) read the line and store it in a var.
$myTempLine = fgets($handle);

3) close the file.
fclose($handle);

4) explode the var with | as seperator. (check www.php.net, find explode)
It will return an array of all elements.
$myElements = explode("|", $myTempLine );

5) store them in your database.

Good luck,

Regards,
Erwin Moller

Jul 17 '05 #2
.oO(VooDoo)
I have a Temperature sensor with internal web server that provide the data
in a text format.
When quering the ip(ttp://192.168.10.220/temp) of the sensor i get that kind
of reply:
Probe 1|82.2|Probe 2|80.8|Probe 3|-99.9|Probe 4|-99.9
I woud like to import the result into my mysql database.
What is the best way to do this?
Should i use a fopen() ?
I have try with this but i don't know how get just the value data....


$data = file_get_contents('http://192.168.10.220/temp');
preg_match_all('#probe (\d+)\|([^|]+)#i', $data, $m);

PHP5:
$result = array_combine($m[1], $m[2]);

PHP4:
$result = array();
for ($i = 0; $i < count($m[1]); $i++) {
$result[$m[1][$i]] = $m[2][$i];
}

The result:

Array
(
[1] => 82.2
[2] => 80.8
[3] => -99.9
[4] => -99.9
)

HTH
Micha
Jul 17 '05 #3
Hi guys!
Thanks a lot for your help i will try all your solution and see wich one i
like the most.
I really appreciated your fast help.
Rgds,
VooDoo
"Michael Fesser" <ne*****@gmx.net> a écrit dans le message de
news:c2********************************@4ax.com...
.oO(VooDoo)
I have a Temperature sensor with internal web server that provide the datain a text format.
When quering the ip(ttp://192.168.10.220/temp) of the sensor i get that kindof reply:
Probe 1|82.2|Probe 2|80.8|Probe 3|-99.9|Probe 4|-99.9
I woud like to import the result into my mysql database.
What is the best way to do this?
Should i use a fopen() ?
I have try with this but i don't know how get just the value data....


$data = file_get_contents('http://192.168.10.220/temp');
preg_match_all('#probe (\d+)\|([^|]+)#i', $data, $m);

PHP5:
$result = array_combine($m[1], $m[2]);

PHP4:
$result = array();
for ($i = 0; $i < count($m[1]); $i++) {
$result[$m[1][$i]] = $m[2][$i];
}

The result:

Array
(
[1] => 82.2
[2] => 80.8
[3] => -99.9
[4] => -99.9
)

HTH
Micha

Jul 17 '05 #4
Hi,
I have try yours first and other reply code also but none are working.
All the values are blank. the array seems always to be empty...
Any idea?
"Erwin Moller"
<si******************************************@spam yourself.com> a écrit dans
le message de news:41***********************@news.xs4all.nl...
VooDoo wrote:
Hi,
I have a Temperature sensor with internal web server that provide the data in a text format.
When quering the ip(ttp://192.168.10.220/temp) of the sensor i get that
kind of reply:
Probe 1|82.2|Probe 2|80.8|Probe 3|-99.9|Probe 4|-99.9
I woud like to import the result into my mysql database.
What is the best way to do this?
Should i use a fopen() ?
I have try with this but i don't know how get just the value data....

Is there a simple way of achieving this?
thanks for your help.
VooDoo


Hi Voodoo,

1) just fopen the file
$handle = fopen("http://192.168.10.220/temp", "r");

2) read the line and store it in a var.
$myTempLine = fgets($handle);

3) close the file.
fclose($handle);

4) explode the var with | as seperator. (check www.php.net, find explode)
It will return an array of all elements.
$myElements = explode("|", $myTempLine );

5) store them in your database.

Good luck,

Regards,
Erwin Moller

Jul 17 '05 #5
VooDoo wrote:
Hi,
I have try yours first and other reply code also but none are working.
All the values are blank. the array seems always to be empty...
Any idea?


Shame. :-(
1) just fopen the file
$handle = fopen("http://192.168.10.220/temp", "r");

2) read the line and store it in a var.
$myTempLine = fgets($handle);


If you print out the $myTempLine, what do you see?
Is it empty?

Regards,
Erwin Moller
Jul 17 '05 #6
yes...
"Erwin Moller"
<si******************************************@spam yourself.com> a écrit dans
le message de news:41***********************@news.xs4all.nl...
VooDoo wrote:
Hi,
I have try yours first and other reply code also but none are working.
All the values are blank. the array seems always to be empty...
Any idea?


Shame. :-(
1) just fopen the file
$handle = fopen("http://192.168.10.220/temp", "r");

2) read the line and store it in a var.
$myTempLine = fgets($handle);


If you print out the $myTempLine, what do you see?
Is it empty?

Regards,
Erwin Moller

Jul 17 '05 #7
.oO(VooDoo)
I have try yours first and other reply code also but none are working.
All the values are blank. the array seems always to be empty...
Any idea?


Check your php.ini:

Is allow_url_fopen enabled?
Is error_reporting set to E_ALL?

Micha
Jul 17 '05 #8
yes for both.
If i use the url http://192.168.10.220/
wich is the main page for the sensor view the it works....
The page http://192.168.10.220/temp/ only contain this:
Probe 1|82.2|Probe 2|80.8|Probe 3|-99.9|Probe 4|-99.9
with no html code at all, is that the problem???
The main page is full off html and other code....
Thanks for your help.
VooDoo
"Michael Fesser" <ne*****@gmx.net> a écrit dans le message de
news:t0********************************@4ax.com...
.oO(VooDoo)
I have try yours first and other reply code also but none are working.
All the values are blank. the array seems always to be empty...
Any idea?


Check your php.ini:

Is allow_url_fopen enabled?
Is error_reporting set to E_ALL?

Micha

Jul 17 '05 #9
VooDoo wrote:
yes...


Ok,

Probably that internal webserver send a lot back. Many lines.
(In my example I expected only one line back.)

Let's check that first by getting the WHOLE response in:

Try this first:
(Straight from http://nl.php.net/manual/en/function.file.php)
$lines = file('http://192.168.10.220/temp');

foreach ($lines as $line_num => $line) {
echo "Line #<b>{$line_num}</b> : " . htmlspecialchars($line) . "<br>\n";
}
do you get a response that makes sense?
If so, try to find the linenumber that contains the information you need.

Keep me informed. We'll fix this. :-)

Regards,
Erwin

Jul 17 '05 #10
Thanks erwin.
No apparently the web server only send out this line:
Probe 1|82.2|Probe 2|80.8|Probe 3|-99.9|Probe 4|-99.9
nothing else, no html code at all.
If i use the default page of the server (192.168.10.220) where there is a
full of other caracter, then it works fine...
the constructo said that the page192.168.10.220/temp has been designed to
fit custom application, and it just provided the value of the different
probe...
i try out your new code and let you know...

"Erwin Moller"
<si******************************************@spam yourself.com> a écrit dans
le message de news:41***********************@news.xs4all.nl...
VooDoo wrote:
yes...
Ok,

Probably that internal webserver send a lot back. Many lines.
(In my example I expected only one line back.)

Let's check that first by getting the WHOLE response in:

Try this first:
(Straight from http://nl.php.net/manual/en/function.file.php)
$lines = file('http://192.168.10.220/temp');

foreach ($lines as $line_num => $line) {
echo "Line #<b>{$line_num}</b> : " . htmlspecialchars($line) .

"<br>\n"; }
do you get a response that makes sense?
If so, try to find the linenumber that contains the information you need.

Keep me informed. We'll fix this. :-)

Regards,
Erwin

Jul 17 '05 #11
same thing with thte new code..... :(
"VooDoo" <cr*******@ifrance.com> a écrit dans le message de
news:cf**********@reader1.imaginet.fr...
Thanks erwin.
No apparently the web server only send out this line:
Probe 1|82.2|Probe 2|80.8|Probe 3|-99.9|Probe 4|-99.9
nothing else, no html code at all.
If i use the default page of the server (192.168.10.220) where there is a
full of other caracter, then it works fine...
the constructo said that the page192.168.10.220/temp has been designed to
fit custom application, and it just provided the value of the different
probe...
i try out your new code and let you know...

"Erwin Moller"
<si******************************************@spam yourself.com> a écrit dans le message de news:41***********************@news.xs4all.nl...
VooDoo wrote:
yes...


Ok,

Probably that internal webserver send a lot back. Many lines.
(In my example I expected only one line back.)

Let's check that first by getting the WHOLE response in:

Try this first:
(Straight from http://nl.php.net/manual/en/function.file.php)
$lines = file('http://192.168.10.220/temp');

foreach ($lines as $line_num => $line) {
echo "Line #<b>{$line_num}</b> : " . htmlspecialchars($line) .

"<br>\n";
}
do you get a response that makes sense?
If so, try to find the linenumber that contains the information you need.
Keep me informed. We'll fix this. :-)

Regards,
Erwin


Jul 17 '05 #12
VooDoo wrote:
same thing with thte new code..... :(
"VooDoo" <cr*******@ifrance.com> a �rit dans le message de
news:cf**********@reader1.imaginet.fr...
Thanks erwin.
No apparently the web server only send out this line:
Probe 1|82.2|Probe 2|80.8|Probe 3|-99.9|Probe 4|-99.9
nothing else, no html code at all.
If i use the default page of the server (192.168.10.220) where there is a
full of other caracter, then it works fine...
the constructo said that the page192.168.10.220/temp has been designed to
fit custom application, and it just provided the value of the different
probe...
i try out your new code and let you know...
Hi VooDoo,

Let me recap the situation.
Just to be sure we understand each other.

You say: No apparently the web server only send out this line:
Probe 1|82.2|Probe 2|80.8|Probe 3|-99.9|Probe 4|-99.9


Question: How do you know this?

Is this what our testscript also produces?
I mean:
$lines = file('http://192.168.10.220/temp');
foreach ($lines as $line_num => $line) {
echo "Line #<b>{$line_num}</b> : " . htmlspecialchars($line) . "<br>\n";
}

produces nothing?

And when you visit the same address with your webbrowser you get:
Probe 1|82.2|Probe 2|80.8|Probe 3|-99.9|Probe 4|-99.9

???

Is that true?

Because when that is the case, PHP somehow cannot grab the output produced
by that internal webserver, which is strange.

Can you test this by trying to query google, like this:

$lines = file('http://www.google.com');
foreach ($lines as $line_num => $line) {
echo "Line #<b>{$line_num}</b> : " . htmlspecialchars($line) . "<br>\n";
}

Does that produce many lines of code?

Regards,
Erwin Moller
Jul 17 '05 #13
reply below
"Erwin Moller"
<si******************************************@spam yourself.com> a écrit dans
le message de news:41***********************@news.xs4all.nl...
VooDoo wrote:
same thing with thte new code..... :(
"VooDoo" <cr*******@ifrance.com> a ?rit dans le message de
news:cf**********@reader1.imaginet.fr...
Thanks erwin.
No apparently the web server only send out this line:
Probe 1|82.2|Probe 2|80.8|Probe 3|-99.9|Probe 4|-99.9
nothing else, no html code at all.
If i use the default page of the server (192.168.10.220) where there is a full of other caracter, then it works fine...
the constructo said that the page192.168.10.220/temp has been designed to fit custom application, and it just provided the value of the different
probe...
i try out your new code and let you know...
Hi VooDoo,

Let me recap the situation.
Just to be sure we understand each other.

You say: No apparently the web server only send out this line:
Probe 1|82.2|Probe 2|80.8|Probe 3|-99.9|Probe 4|-99.9

Question: How do you know this?

That is what i get when typing these url on IE:
http://192.168.10.220/temp or http://192.168.10.220/temp/
Is this what our testscript also produces?
I mean:
$lines = file('http://192.168.10.220/temp');
foreach ($lines as $line_num => $line) {
echo "Line #<b>{$line_num}</b> : " . htmlspecialchars($line) . "<br>\n"; }

produces nothing? Yes ! And when you visit the same address with your webbrowser you get:
Probe 1|82.2|Probe 2|80.8|Probe 3|-99.9|Probe 4|-99.9

???

Is that true? YES Because when that is the case, PHP somehow cannot grab the output produced
by that internal webserver, which is strange.

Can you test this by trying to query google, like this:

$lines = file('http://www.google.com');
foreach ($lines as $line_num => $line) {
echo "Line #<b>{$line_num}</b> : " . htmlspecialchars($line) . "<br>\n"; }

Does that produce many lines of code?
YES that works fine....

It's very strange, i don't what's wrong...
I have contacted the support of the temp sensor to see if it's a issue for
them...
But as far as i get the right content on that page: 192.168.200.10/temp i
imagine they will say it's working...
It's also strange that your code is working on the main page....
((192.168.200.10)
Any more ideas?
Thanks a lot for your support!
Cedric

Jul 17 '05 #14
VooDoo wrote:
reply below
"Erwin Moller"
<si******************************************@spam yourself.com> a �rit
dans le message de news:41***********************@news.xs4all.nl...
VooDoo wrote:
> same thing with thte new code..... :(
> "VooDoo" <cr*******@ifrance.com> a ?rit dans le message de
> news:cf**********@reader1.imaginet.fr...
>> Thanks erwin.
>> No apparently the web server only send out this line:
>> Probe 1|82.2|Probe 2|80.8|Probe 3|-99.9|Probe 4|-99.9
>> nothing else, no html code at all.
>> If i use the default page of the server (192.168.10.220) where there
>> is a >> full of other caracter, then it works fine...
>> the constructo said that the page192.168.10.220/temp has been designed to >> fit custom application, and it just provided the value of the
>> different probe...
>> i try out your new code and let you know...


Hi VooDoo,

Let me recap the situation.
Just to be sure we understand each other.

You say:
>> No apparently the web server only send out this line:
>> Probe 1|82.2|Probe 2|80.8|Probe 3|-99.9|Probe 4|-99.9


Question: How do you know this?

That is what i get when typing these url on IE:
http://192.168.10.220/temp or http://192.168.10.220/temp/

Is this what our testscript also produces?
I mean:
$lines = file('http://192.168.10.220/temp');
foreach ($lines as $line_num => $line) {
echo "Line #<b>{$line_num}</b> : " . htmlspecialchars($line) .

"<br>\n";
}

produces nothing?

Yes !
And when you visit the same address with your webbrowser you get:
Probe 1|82.2|Probe 2|80.8|Probe 3|-99.9|Probe 4|-99.9

???

Is that true?

YES
Because when that is the case, PHP somehow cannot grab the output
produced by that internal webserver, which is strange.

Can you test this by trying to query google, like this:

$lines = file('http://www.google.com');
foreach ($lines as $line_num => $line) {
echo "Line #<b>{$line_num}</b> : " . htmlspecialchars($line) .

"<br>\n";
}

Does that produce many lines of code?
YES that works fine....

It's very strange, i don't what's wrong...
I have contacted the support of the temp sensor to see if it's a issue for
them...
But as far as i get the right content on that page: 192.168.200.10/temp
i imagine they will say it's working...
It's also strange that your code is working on the main page....
((192.168.200.10)
Any more ideas?
Thanks a lot for your support!
Cedric

Hi Cedric,

This is strange indeed!
What *could* produce this behaviour is a possible session started by:
192.168.200.10

which sets a cookie.

192.168.200.10/temp TEST for that cookie, and when it is not there, it
refuses to answer.
(I am guessing)

Try this:
1) In your browser: delete all content AND cookies.
2) restart your browser
3) go DIRECTLY to 192.168.200.10/temp without visiting 192.168.200.10 first.

Do you get an answer?

Regards,
Erwin Moller

Jul 17 '05 #15

"Erwin Moller"
<si******************************************@spam yourself.com> a écrit dans
le message de news:41***********************@news.xs4all.nl...
VooDoo wrote:
reply below
"Erwin Moller"
<si******************************************@spam yourself.com> a ?rit
dans le message de news:41***********************@news.xs4all.nl...
VooDoo wrote:

> same thing with thte new code..... :(
> "VooDoo" <cr*******@ifrance.com> a ?rit dans le message de
> news:cf**********@reader1.imaginet.fr...
>> Thanks erwin.
>> No apparently the web server only send out this line:
>> Probe 1|82.2|Probe 2|80.8|Probe 3|-99.9|Probe 4|-99.9
>> nothing else, no html code at all.
>> If i use the default page of the server (192.168.10.220) where there
>> is a
>> full of other caracter, then it works fine...
>> the constructo said that the page192.168.10.220/temp has been
designed to
>> fit custom application, and it just provided the value of the
>> different probe...
>> i try out your new code and let you know...

Hi VooDoo,

Let me recap the situation.
Just to be sure we understand each other.

You say:
>> No apparently the web server only send out this line:
>> Probe 1|82.2|Probe 2|80.8|Probe 3|-99.9|Probe 4|-99.9

Question: How do you know this?

That is what i get when typing these url on IE:
http://192.168.10.220/temp or http://192.168.10.220/temp/

Is this what our testscript also produces?
I mean:
$lines = file('http://192.168.10.220/temp');
foreach ($lines as $line_num => $line) {
echo "Line #<b>{$line_num}</b> : " . htmlspecialchars($line) .

"<br>\n";
}

produces nothing?

Yes !
And when you visit the same address with your webbrowser you get:
Probe 1|82.2|Probe 2|80.8|Probe 3|-99.9|Probe 4|-99.9

???

Is that true?

YES
Because when that is the case, PHP somehow cannot grab the output
produced by that internal webserver, which is strange.

Can you test this by trying to query google, like this:

$lines = file('http://www.google.com');
foreach ($lines as $line_num => $line) {
echo "Line #<b>{$line_num}</b> : " . htmlspecialchars($line) .

"<br>\n";
}

Does that produce many lines of code?
YES that works fine....

It's very strange, i don't what's wrong...
I have contacted the support of the temp sensor to see if it's a issue for them...
But as far as i get the right content on that page: 192.168.200.10/temp
i imagine they will say it's working...
It's also strange that your code is working on the main page....
((192.168.200.10)
Any more ideas?
Thanks a lot for your support!
Cedric

Hi Cedric,

This is strange indeed!
What *could* produce this behaviour is a possible session started by:
192.168.200.10

which sets a cookie.

192.168.200.10/temp TEST for that cookie, and when it is not there, it
refuses to answer.
(I am guessing)

Try this:
1) In your browser: delete all content AND cookies.
2) restart your browser
3) go DIRECTLY to 192.168.200.10/temp without visiting 192.168.200.10

first.
Do you get an answer?

Regards,
Erwin Moller


Yes i get the page with the result....
weird!
Jul 17 '05 #16
http://195.68.51.202
here you can find the sensor page
if that can you give more ideas...
thanks a lot again for helping me on this
"Erwin Moller"
<si******************************************@spam yourself.com> a écrit dans
le message de news:41***********************@news.xs4all.nl...
VooDoo wrote:
reply below
"Erwin Moller"
<si******************************************@spam yourself.com> a ?rit
dans le message de news:41***********************@news.xs4all.nl...
VooDoo wrote:

> same thing with thte new code..... :(
> "VooDoo" <cr*******@ifrance.com> a ?rit dans le message de
> news:cf**********@reader1.imaginet.fr...
>> Thanks erwin.
>> No apparently the web server only send out this line:
>> Probe 1|82.2|Probe 2|80.8|Probe 3|-99.9|Probe 4|-99.9
>> nothing else, no html code at all.
>> If i use the default page of the server (192.168.10.220) where there
>> is a
>> full of other caracter, then it works fine...
>> the constructo said that the page192.168.10.220/temp has been
designed to
>> fit custom application, and it just provided the value of the
>> different probe...
>> i try out your new code and let you know...

Hi VooDoo,

Let me recap the situation.
Just to be sure we understand each other.

You say:
>> No apparently the web server only send out this line:
>> Probe 1|82.2|Probe 2|80.8|Probe 3|-99.9|Probe 4|-99.9

Question: How do you know this?

That is what i get when typing these url on IE:
http://192.168.10.220/temp or http://192.168.10.220/temp/

Is this what our testscript also produces?
I mean:
$lines = file('http://192.168.10.220/temp');
foreach ($lines as $line_num => $line) {
echo "Line #<b>{$line_num}</b> : " . htmlspecialchars($line) .

"<br>\n";
}

produces nothing?

Yes !
And when you visit the same address with your webbrowser you get:
Probe 1|82.2|Probe 2|80.8|Probe 3|-99.9|Probe 4|-99.9

???

Is that true?

YES
Because when that is the case, PHP somehow cannot grab the output
produced by that internal webserver, which is strange.

Can you test this by trying to query google, like this:

$lines = file('http://www.google.com');
foreach ($lines as $line_num => $line) {
echo "Line #<b>{$line_num}</b> : " . htmlspecialchars($line) .

"<br>\n";
}

Does that produce many lines of code?
YES that works fine....

It's very strange, i don't what's wrong...
I have contacted the support of the temp sensor to see if it's a issue for them...
But as far as i get the right content on that page: 192.168.200.10/temp
i imagine they will say it's working...
It's also strange that your code is working on the main page....
((192.168.200.10)
Any more ideas?
Thanks a lot for your support!
Cedric

Hi Cedric,

This is strange indeed!
What *could* produce this behaviour is a possible session started by:
192.168.200.10

which sets a cookie.

192.168.200.10/temp TEST for that cookie, and when it is not there, it
refuses to answer.
(I am guessing)

Try this:
1) In your browser: delete all content AND cookies.
2) restart your browser
3) go DIRECTLY to 192.168.200.10/temp without visiting 192.168.200.10

first.
Do you get an answer?

Regards,
Erwin Moller

Jul 17 '05 #17
VooDoo wrote:
<snip>
Hi Cedric,

This is strange indeed!
What *could* produce this behaviour is a possible session started by:
192.168.200.10

which sets a cookie.

192.168.200.10/temp TEST for that cookie, and when it is not there, it
refuses to answer.
(I am guessing)

Try this:
1) In your browser: delete all content AND cookies.
2) restart your browser
3) go DIRECTLY to 192.168.200.10/temp without visiting 192.168.200.10

first.

Do you get an answer?

Regards,
Erwin Moller


Yes i get the page with the result....
weird!


Hi,

Yes, weird.

It seems that PHP cannot handle the content of that internal webserver the
right way.
I have never seen this before.
In my experience PHP is always extremely flexible.

We must be overlooking something.

I am out of options. :-(

I think I go home, and, who knows, tomorrow I'll have a flash or insight.
:-)
Hee, I was getting my coat on when it struck me that MAYBE the response of
the webserver doesn't have an END-OF-LINE.
Suppose it just ends with an END-OF-FILE??

That would explain why the code you tried didn't recognize anything because
it looks for end-of-lines!!

Try file_get_contents("http://192.168.200.10/temp") to see if anything
returns.
Or maybe a socketfunction.
I am unfamiliar with them because I always use file(), so please check
www.php.net for details.

Good luck and keep me informed.
Regards,
Erwin Moller

Jul 17 '05 #18
VooDoo wrote:
http://195.68.51.202
here you can find the sensor page
if that can you give more ideas...
thanks a lot again for helping me on this


Hi,

Great, now you got me addicted to this little problem. :P
*takes coat off*

I'll be back soon. :-)

Regards,
Erwin

Jul 17 '05 #19
.oO(VooDoo)
http://195.68.51.202
here you can find the sensor page


The main page works, but I can't access http://195.68.51.202/temp/ with
a lynx-browser. Web-sniffer also shows nothing:

<http://web-sniffer.net/?url=http%3A%2F%2F195.68.51.202%2Ftemp%2F>

No response ... strange. So I would rather parse the main page to get
the results, shouldn't be too difficult, something like

$data = file_get_contents('http://195.68.51.202/');
preg_match_all('#>([^>]+?) &deg#', $data, $matches);
print_r($matches[1]);

HTH
Micha
Jul 17 '05 #20
Hi Cedric,

I found something.

I ALWAYS get this error:
Inappropriate ioctl for device

I googled for it but didn't find a clear solution, allthough it can have to
do with redirects by the webserver with or without trailing slashes.

http://aspn.activestate.com/ASPN/Mai...php-Dev/763315

That article is from 2001, so I am unsure if it is still relevant.

I think you maybe better use the page without /temp and do some parsing.
The same data is there and that page works fine.

Anyway, here follows some (stinking) code that gets the info out:
I guess somebody who knows regexpressions better than I can code it more
elegant. :P

The 4 echo's at the end include the celcius still.
You could rip that too of course.

<?

$lines = file("http://195.68.51.202");

// it is all on one line, so:
$line = $lines[0];

// this is the essential part:
// <td>Probe 4</td></tr><tr><td>27.5 &deg;C</td><td>23.6
&deg;C</td><td>-99.9 &deg;C</td><td>-99.9 &deg;C</td></tr></tbody></table>

// we want this part:
// 27.5 &deg;C</td><td>23.6 &deg;C</td><td>-99.9 &deg;C</td><td>-99.9 &deg;C

$boundary1 = "Probe 4</td></tr><tr><td>";
$boundary2 = "</td></tr></tbody></table>";

$pos1 = strpos($line, $boundary1);
$pos2 = strpos($line,$boundary2 );
$temps = substr ( $line, $pos1+strlen($boundary1),
($pos2-$pos1-strlen($boundary2)+1));

$tempArr = explode ("</td><td>",$temps);

echo htmlentities($temps)."<br>";

echo $tempArr[0]."<br>";
echo $tempArr[1]."<br>";
echo $tempArr[2]."<br>";
echo $tempArr[3]."<br>";
?>
I am sorry I couldn't help you the right way (by getting the /temp working)
but this gets the job done. :-)

Regards,
Erwin Moller
Jul 17 '05 #21
Michael Fesser wrote:
.oO(VooDoo)
http://195.68.51.202
here you can find the sensor page


The main page works, but I can't access http://195.68.51.202/temp/ with
a lynx-browser. Web-sniffer also shows nothing:

<http://web-sniffer.net/?url=http%3A%2F%2F195.68.51.202%2Ftemp%2F>

No response ... strange. So I would rather parse the main page to get
the results, shouldn't be too difficult, something like

$data = file_get_contents('http://195.68.51.202/');
preg_match_all('#>([^>]+?) &deg#', $data, $matches);
print_r($matches[1]);

HTH
Micha


LOL!

Micha, I just posted a script of a lot more lines.
Do you also give classes? I want to come. :-)
Regards,
Erwin Moller
Jul 17 '05 #22
VooDoo wrote:
http://195.68.51.202
here you can find the sensor page
if that can you give more ideas...
thanks a lot again for helping me on this
"Erwin Moller"
<si******************************************@spam yourself.com> a écrit dans
le message de news:41***********************@news.xs4all.nl...


This worked for me. The code is from the docs for fsockopen:

$fp = fsockopen("195.68.51.202", 80, $errno, $errstr, 30);
if (!$fp) {
echo "$errstr ($errno)<br />\n";
} else {
$out = "GET /temp/ HTTP/1.1\r\n";
$out .= "Host: 195.68.51.202\r\n";
$out .= "Connection: Close\r\n\r\n";

fwrite($fp, $out);
while (!feof($fp)) {
echo fgets($fp, 128);
}
fclose($fp);
}

Using fopen worked OK for http://195.68.51.202/, but failed on
http://195.68.51.202/temp/. Also, tcpdump showed checksum errors when
connecting with fopen. Anyone experience the same (PHP 4.3.2 on OS X)?

Regards, Anders
VooDoo wrote:

reply below
"Erwin Moller"
<si******************************************@s pamyourself.com> a ?rit
dans le message de news:41***********************@news.xs4all.nl...

VooDoo wrote:
>same thing with thte new code..... :(
>"VooDoo" <cr*******@ifrance.com> a ?rit dans le message de
>news:cf**********@reader1.imaginet.fr...
>
>>Thanks erwin.
>>No apparently the web server only send out this line:
>>Probe 1|82.2|Probe 2|80.8|Probe 3|-99.9|Probe 4|-99.9
>>nothing else, no html code at all.
>>If i use the default page of the server (192.168.10.220) where there
>>is

a

>>full of other caracter, then it works fine...
>>the constructo said that the page192.168.10.220/temp has been
designed
to

>>fit custom application, and it just provided the value of the
>>different probe...
>>i try out your new code and let you know...

Hi VooDoo,

Let me recap the situation.
Just to be sure we understand each other.

You say:

>>No apparently the web server only send out this line:
>>Probe 1|82.2|Probe 2|80.8|Probe 3|-99.9|Probe 4|-99.9

Question: How do you know this?

That is what i get when typing these url on IE:
http://192.168.10.220/temp or http://192.168.10.220/temp/

Is this what our testscript also produces?
I mean:
$lines = file('http://192.168.10.220/temp');
foreach ($lines as $line_num => $line) {
echo "Line #<b>{$line_num}</b> : " . htmlspecialchars($line) .

"<br>\n";

}

produces nothing?

Yes !

And when you visit the same address with your webbrowser you get:
Probe 1|82.2|Probe 2|80.8|Probe 3|-99.9|Probe 4|-99.9

???

Is that true?

YES

Because when that is the case, PHP somehow cannot grab the output
produced by that internal webserver, which is strange.

Can you test this by trying to query google, like this:

$lines = file('http://www.google.com');
foreach ($lines as $line_num => $line) {
echo "Line #<b>{$line_num}</b> : " . htmlspecialchars($line) .

"<br>\n";

}

Does that produce many lines of code?
YES that works fine....

It's very strange, i don't what's wrong...
I have contacted the support of the temp sensor to see if it's a issue
for
them...
But as far as i get the right content on that page: 192.168.200.10/temp
i imagine they will say it's working...
It's also strange that your code is working on the main page....
((192.168.200.10)
Any more ideas?
Thanks a lot for your support!
Cedric

Hi Cedric,

This is strange indeed!
What *could* produce this behaviour is a possible session started by:
192.168.200.10

which sets a cookie.

192.168.200.10/temp TEST for that cookie, and when it is not there, it
refuses to answer.
(I am guessing)

Try this:
1) In your browser: delete all content AND cookies.
2) restart your browser
3) go DIRECTLY to 192.168.200.10/temp without visiting 192.168.200.10


first.
Do you get an answer?

Regards,
Erwin Moller





Jul 17 '05 #23
.oO(Erwin Moller)
Micha, I just posted a script of a lot more lines.
Do you also give classes? I want to come. :-)


*g*

Nope, sorry. ;D

Micha
Jul 17 '05 #24
I was interesting too!! ;)
Anyway thanks a lot to both of you, you have been very very helpfull on
that!!
Your last solutions worked fine, so i am parsing the main page... wich was
not designed for that but it's working fine so....
Just for your info here is the response of the constructor:
Bizarre,

Sounds like a problem with fopen()....might be because the /temp is like

a .cgi script....not a static index page like temp.html. Can you use

something like netcat (http://netcat.sourceforge.net/). What do you

think? There is another utility out there to retrieve URL's...wget I

beleive is the name of it...and it doesn't work with the /temp URL

neither. Could also be because the /temp URL doesn't return any HTML

encoding.

Looks like he does not know also the reason of that problem...

Another big thanks for you guys.

Thanks

Hope i will help you one day;)

Rdgs,

voodoO
"Michael Fesser" <ne*****@gmx.net> a écrit dans le message de
news:jb********************************@4ax.com...
.oO(Erwin Moller)
Micha, I just posted a script of a lot more lines.
Do you also give classes? I want to come. :-)


*g*

Nope, sorry. ;D

Micha

Jul 17 '05 #25
.oO(VooDoo)
I was interesting too!! ;)
Anyway thanks a lot to both of you, you have been very very helpfull on
that!!
Your last solutions worked fine, so i am parsing the main page... wich was
not designed for that but it's working fine so....
You can also use the solution posted by Anders Lövgren (connect with
fsockopen and manually send a GET request), this works with the /temp
file.
Just for your info here is the response of the constructor:
Bizarre,
Sounds like a problem with fopen()....might be because the /temp is like
a .cgi script....not a static index page like temp.html. Can you use
something like netcat (http://netcat.sourceforge.net/).
netcat works:

$ nc 195.68.51.202 80
GET /temp HTTP/1.1

returns the data.
What do you
think? There is another utility out there to retrieve URL's...wget I
beleive is the name of it...and it doesn't work with the /temp URL
neither.
wget fails:

$ wget -t1 http://195.68.51.202/temp
--16:01:15-- http://195.68.51.202/temp
=> `temp'
Connecting to 195.68.51.202:80... connected.
HTTP request sent, awaiting response...
End of file while parsing headers.
Giving up.
lynx also fails:

$ lynx -head http://195.68.51.202/temp
Looking up 195.68.51.202
Making HTTP connection to 195.68.51.202
Sending HTTP request.
HTTP request sent; waiting for response.
Alert!: Unexpected network read error; connection aborted.
Can't Access `http://195.68.51.202/temp'
Alert!: Unable to access document.
Could also be because the /temp URL doesn't return any HTML
encoding.


I think there's a little problem with the built-in webserver, looks like
some specific request headers causes it to fail (simple requests work),
but I haven't investigated any further.

Micha
Jul 17 '05 #26
<snip>
You say:
>> No apparently the web server only send out this line:
>> Probe 1|82.2|Probe 2|80.8|Probe 3|-99.9|Probe 4|-99.9

Sniffing with IE6 and a nice little gem called HTTPWatch reveals that
this is *all* that is sent.
Question: How do you know this?

That is what i get when typing these url on IE:
http://192.168.10.220/temp or http://192.168.10.220/temp/

Is this what our testscript also produces?
I mean:
$lines = file('http://192.168.10.220/temp');
foreach ($lines as $line_num => $line) {
echo "Line #<b>{$line_num}</b> : " . htmlspecialchars($line) .

"<br>\n";
}

produces nothing?

Yes !
And when you visit the same address with your webbrowser you get:
Probe 1|82.2|Probe 2|80.8|Probe 3|-99.9|Probe 4|-99.9
Not apparently in all web browsers. IE6 and Firefox show content --
Lynx does not.

???

Is that true?

YES
Because when that is the case, PHP somehow cannot grab the output
produced by that internal webserver, which is strange.


The fact is that NO HTTP headers are being sent as part of the
response. As such, PHP's fopen URL wrappers parse the response, but
do not find valid "content" since no headers exist to describe the
delivered payload.

Hope this is understandable and clears it up why PHP showed nothing
using the fopen functions.
heyster
Jul 17 '05 #27
heyster wrote:
<snip>
You say:
>> No apparently the web server only send out this line:
>> Probe 1|82.2|Probe 2|80.8|Probe 3|-99.9|Probe 4|-99.9

Sniffing with IE6 and a nice little gem called HTTPWatch reveals that
this is *all* that is sent.
Question: How do you know this?
That is what i get when typing these url on IE:
http://192.168.10.220/temp or http://192.168.10.220/temp/

Is this what our testscript also produces?
I mean:
$lines = file('http://192.168.10.220/temp');
foreach ($lines as $line_num => $line) {
echo "Line #<b>{$line_num}</b> : " . htmlspecialchars($line) .
"<br>\n";
}

produces nothing?
Yes !
And when you visit the same address with your webbrowser you get:
Probe 1|82.2|Probe 2|80.8|Probe 3|-99.9|Probe 4|-99.9
Not apparently in all web browsers. IE6 and Firefox show content --
Lynx does not.

???

Is that true?
YES
Because when that is the case, PHP somehow cannot grab the output
produced by that internal webserver, which is strange.


The fact is that NO HTTP headers are being sent as part of the
response. As such, PHP's fopen URL wrappers parse the response, but
do not find valid "content" since no headers exist to describe the
delivered payload.

Hope this is understandable and clears it up why PHP showed nothing
using the fopen functions.
heyster


Hi heyster,

I found out the same results. No headers, just a line.
Question:
Could we use a straight socketconnection on that x.x.x.x/temp to get the
line in?

Regards,
Erwin Moller
Jul 17 '05 #28
On Mon, 23 Aug 2004 11:30:29 +0200, Erwin Moller
<si******************************************@spam yourself.com> wrote:

Hi heyster,

I found out the same results. No headers, just a line.
Question:
Could we use a straight socketconnection on that x.x.x.x/temp to get the
line in?

Regards,
Erwin Moller


Erwin,

Yes, and it looks like that's what worked for Anders Lövgren based on
his post of a few days ago.

Too bad the device doesn't use valid headers when addressed at
"/temp", but good to know the nut wasn't too tough to crack.

heyster
Jul 17 '05 #29
Check out iewatch.com for a great tool to debug HTTP...
heyster <he***********@eysterengineered.com> wrote in message news:<vh********************************@4ax.com>. ..
<snip>
You say:
>> No apparently the web server only send out this line:
>> Probe 1|82.2|Probe 2|80.8|Probe 3|-99.9|Probe 4|-99.9

Sniffing with IE6 and a nice little gem called HTTPWatch reveals that
this is *all* that is sent.
Question: How do you know this?
That is what i get when typing these url on IE:
http://192.168.10.220/temp or http://192.168.10.220/temp/

Is this what our testscript also produces?
I mean:
$lines = file('http://192.168.10.220/temp');
foreach ($lines as $line_num => $line) {
echo "Line #<b>{$line_num}</b> : " . htmlspecialchars($line) . "<br>\n"; }

produces nothing? Yes ! And when you visit the same address with your webbrowser you get:
Probe 1|82.2|Probe 2|80.8|Probe 3|-99.9|Probe 4|-99.9
Not apparently in all web browsers. IE6 and Firefox show content --
Lynx does not.

???

Is that true? YES Because when that is the case, PHP somehow cannot grab the output
produced by that internal webserver, which is strange.


The fact is that NO HTTP headers are being sent as part of the
response. As such, PHP's fopen URL wrappers parse the response, but
do not find valid "content" since no headers exist to describe the
delivered payload.

Hope this is understandable and clears it up why PHP showed nothing
using the fopen functions.
heyster

Jul 17 '05 #30

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Xah Lee | last post by:
# -*- coding: utf-8 -*- # Python # to open a file and write to file # do f=open('xfile.txt','w') # this creates a file "object" and name it f. # the second argument of open can be
1
by: fabrice | last post by:
Hello, I've got trouble reading a text file (event viewer dump) by using the getline() function... After 200 - 300 lines that are read correctly, it suddenly stops reading the rest of the...
19
by: Lionel B | last post by:
Greetings, I need to read (unformatted text) from stdin up to EOF into a char buffer; of course I cannot allocate my buffer until I know how much text is available, and I do not know how much...
4
by: Oliver Knoll | last post by:
According to my ANSI book, tmpfile() creates a file with wb+ mode (that is just writing, right?). How would one reopen it for reading? I got the following (which works): FILE *tmpFile =...
6
by: Rajorshi Biswas | last post by:
Hi folks, Suppose I have a large (1 GB) text file which I want to read in reverse. The number of characters I want to read at a time is insignificant. I'm confused as to how best to do it. Upon...
1
by: Need Helps | last post by:
Hello. I'm writing an application that writes to a file a month, day, year, number of comments, then some strings for the comments. So the format for each record would look like:...
7
by: John Dann | last post by:
I'm trying to read some binary data from a file created by another program. I know the binary file format but can't change or control the format. The binary data is organised such that it should...
5
blazedaces
by: blazedaces | last post by:
Ok, so you know my problem, java is running out of memory reading with SAX, the event-based xml parser intended more-so than DOM for extremely large files. I'll try to explain what I've been doing...
6
by: efrenba | last post by:
Hi, I came from delphi world and now I'm doing my first steps in C++. I'm using C++builder because its ide is like delphi although I'm trying to avoid the vcl. I need to insert new features...
2
by: Derik | last post by:
I've got a XML file I read using a file_get_contents and turn into a simpleXML node every time index.php loads. I suspect this is causing a noticeable lag in my page-execution time. (Or the...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.