BSD socket interface for mruby on ESP32, compatible with ESP-IDF version 5 and mruby 3.2.
This gem is a modification of the mruby-socket gem from mruby 3.2.0. It depends on the IO
class from mruby-io, also modified for the ESP32.
API is compatible with CRuby's socket
library.
Add the line below to your build_config.rb
:
conf.gem :github => 'mruby-esp32/mruby-socket', :branch => '0.5'
If stack overflow occurs, increase the stack size
-
mruby_task: 8192 => 32768
xTaskCreate()
inmain/mruby_main.c
-
eventTask: 4096 => 32768
$ make menuconfig Component config ---> ESP32-specific ---> Event loop task stack size
puts "Getting ready to start Wi-Fi"
wifi = ESP32::WiFi.new
wifi.on_connected do |ip|
puts "Wi-Fi Connected: #{ip} (#{Socket.gethostname})"
soc = TCPSocket.open("www.kame.net", 80)
msg = "HEAD / HTTP/1.1\r\nHost: www.kame.net\r\nConnection: close\r\n\r\n"
msg.split("\r\n").each do |e|
puts ">>> #{e}"
end
soc.send(msg, 0)
puts "--------------------------------------------------------------------------------"
loop do
buf = soc.recv(128, 0)
break if buf.length == 0
print buf
end
puts ""
puts "--------------------------------------------------------------------------------"
end
wifi.on_disconnected do
puts "Wi-Fi Disconnected"
end
puts "Connecting to Wi-Fi"
wifi.connect('SSID', 'PASSWORD')
#
# Loop forever otherwise the script ends
#
while true do
ESP32::System.delay(1000)
end
- mruby-esp32/mruby-io mrbgem
- mruby-pack from core mrbgems
- system must have RFC3493 basic socket interface
- and some POSIX API...
- add missing methods
- fix possible descriptor leakage (see XXX comments)