Class: Wifly::Connection
- Inherits:
-
Object
- Object
- Wifly::Connection
- Defined in:
- lib/wifly/connection.rb
Instance Attribute Summary collapse
-
#address ⇒ Object
Returns the value of attribute address.
-
#port ⇒ Object
Returns the value of attribute port.
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(address, port) ⇒ Connection
constructor
address => the hostname or IP address of the wifly device port => the port for communicating with the wifly.
-
#send_command(str) ⇒ Object
str => the command to send to the wifly, without any carriage return [return_len] => the expected length of the return string; defaults to 0.
- #socket ⇒ Object
Constructor Details
#initialize(address, port) ⇒ Connection
address => the hostname or IP address of the wifly device port => the port for communicating with the wifly
8 9 10 11 |
# File 'lib/wifly/connection.rb', line 8 def initialize(address, port) self.address = address self.port = port end |
Instance Attribute Details
#address ⇒ Object
Returns the value of attribute address.
3 4 5 |
# File 'lib/wifly/connection.rb', line 3 def address @address end |
#port ⇒ Object
Returns the value of attribute port.
3 4 5 |
# File 'lib/wifly/connection.rb', line 3 def port @port end |
Instance Method Details
#close ⇒ Object
29 30 31 |
# File 'lib/wifly/connection.rb', line 29 def close socket.close end |
#send_command(str) ⇒ Object
str => the command to send to the wifly, without any carriage return
- return_len
-
> the expected length of the return string; defaults to 0
The wifly will echo back the command (with carriage return) along with another CRLF and the command prompt string. Something like “litesrrn<2.32> ”
21 22 23 24 25 26 |
# File 'lib/wifly/connection.rb', line 21 def send_command(str) str += "\r" write(socket, str) # the write is blocking sleep(0.2) read(socket).gsub(prompt,'') end |
#socket ⇒ Object
33 34 35 |
# File 'lib/wifly/connection.rb', line 33 def socket @socket ||= initialize_socket end |