Class: Wifly::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/wifly/connection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#addressObject

Returns the value of attribute address.



3
4
5
# File 'lib/wifly/connection.rb', line 3

def address
  @address
end

#portObject

Returns the value of attribute port.



3
4
5
# File 'lib/wifly/connection.rb', line 3

def port
  @port
end

Instance Method Details

#closeObject



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

#socketObject



33
34
35
# File 'lib/wifly/connection.rb', line 33

def socket
  @socket ||= initialize_socket
end