Skip to content

Instantly share code, notes, and snippets.

@jakalada
Created March 25, 2016 15:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jakalada/9e58681d64cb9dae0ec0 to your computer and use it in GitHub Desktop.
Save jakalada/9e58681d64cb9dae0ec0 to your computer and use it in GitHub Desktop.
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