Created
March 25, 2016 15:57
-
-
Save jakalada/9e58681d64cb9dae0ec0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
require 'serialport' | |
port = "/dev/ttyAMA0" | |
bps = 115200 | |
class ESP8266 | |
def initialize(port, bps) | |
@serial_port = SerialPort.new(port, bps) | |
end | |
def command(cmd) | |
puts(cmd) | |
@serial_port.write(cmd + "\r\n") | |
loop do | |
sleep 0.05 | |
res = @serial_port.gets() | |
if res && !res.chomp.empty? | |
puts(res) | |
break if res.include? 'OK' | |
end | |
end | |
end | |
end | |
esp8266 = ESP8266.new(port, bps) | |
esp8266.command('AT') | |
esp8266.command('AT+CWMODE=1') | |
loop do | |
esp8266.command('AT+CWLAP') | |
sleep 1 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment