Created
January 8, 2010 10:51
-
-
Save pklaus/271975 to your computer and use it in GitHub Desktop.
Ethersex ECMD via TCP socket communication with PHP, Python, Ruby: 1-wire communication
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<!-- source: <http://www.ethersex.de/index.php/Dallas_1-wire_Bus#PHP> --> | |
<head> | |
<title>ethersex php example</title> | |
</head> | |
<body> | |
<?php | |
define(IP, '192.168.10.9'); // deine ethersex ip adresse | |
define(PORT, 2701); // standart port im image | |
request("1w convert"); | |
$response = request("1w list"); | |
$explode = explode("\n", $response); | |
for ($i=0; $i < count($explode)-2; $i++) { | |
echo "Sensor: " . trim($explode[$i]); | |
echo " -- Wert: " . request("1w get " . $explode[$i]); | |
echo "<br>\n"; | |
} | |
function request($request) { | |
$rs = fsockopen(IP, PORT); | |
if (!$rs) { | |
$response = "Kann Verbindung nicht aufbauen!"; | |
} | |
else { | |
$response =""; | |
$request = "!" . $request . "\r\n"; | |
fputs($rs, $request); | |
while (!feof($rs)) { | |
$response .= fgets($rs, 128); | |
} | |
fclose($rs); | |
} | |
return $response; | |
} | |
?> | |
</body> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl -w | |
# source: <http://www.ethersex.de/index.php/Dallas_1-wire_Bus#Perl> | |
#Auslesen der 1 Wire Sensoren an einem AVR-NET-IO mit ethersex | |
use strict; | |
use Net::Telnet (); | |
my $esexip="192.168.255.90"; | |
my $esexport="2701"; | |
my $esex; | |
my @sensor; | |
my $sensor; | |
my $dummy; | |
my $temp; | |
$esex = Net::Telnet->new || die "kann Ethersex nicht finden";; | |
$esex->open(Host => $esexip, | |
Port => $esexport, | |
Timeout => 2); | |
#Alles Sensor-IDs auslesen und dem Array @sensor zuweisen | |
$esex->print("1w list"); | |
($sensor) = $esex->waitfor(Timeout => 2, | |
String => "OK"); | |
@sensor=split(/\s+/, $sensor); | |
print "@sensor","\n"; #Kontrollausgabe | |
my $zahler=@sensor; | |
print "Anzahl der Elemente :",$zahler,"\n\n"; | |
#Alles Sensore Temperatur einlesen | |
$esex->print("1w convert"); | |
$esex->waitfor(Timeout => 2, | |
String => "OK"); | |
#Sensor ID inklusive Wert ausgeben | |
foreach (@sensor) { | |
$esex->print("1w get $_"); | |
($dummy,$temp)=$esex->waitfor(Match =>'/[-]?\d+\.\d+/', | |
Timeout => 5); | |
print "Temperatur vom ID ",$_,": ",$temp," C°","\n"; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require "socket" | |
addr = "192.168.1.2" | |
port = 23 | |
s = TCPSocket.new(addr, port) | |
puts s.recv(1024) | |
s.puts("login admin password") | |
puts s.recv(1024) | |
s.puts("port list") | |
puts s.recv(1024) | |
s.puts("quit") | |
puts s.recv(1024) | |
s.close |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment