Skip to content

Commit 1a6256e

Browse files
committed
Improve examples and readme
1 parent 26013fd commit 1a6256e

File tree

6 files changed

+56
-6
lines changed

6 files changed

+56
-6
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ idf.py -p $(YOUR_SERIAL_PORT) flash monitor
3333

3434
The valiable `YOU_WISH_TO_TRY_FILE` can be replaced with one of the following:
3535

36-
* _simplest_mrb.rb_ - Simply prints two strings
37-
* _gpio.rb_ - An example of using GPIO
38-
* _wifi_example_mrb.rb_ - An example of connecting to WiFi, you will need to
39-
modify this file to include your SSID and password
40-
* _mqtt_publish.rb_ - An sample of publishing to MQTT broker
41-
* _system_mrb.rb_ - Examples of most of the system APIs
36+
* _simplest.rb_ - Prints two strings
37+
* _system.rb_ - Demonstrates most system APIs
38+
* _gpio.rb_ - GPIO blink example
39+
* _wifi_connect.rb_ - Connects to WiFi. You need to replace your SSID and password in this file.
40+
* _mqtt_publish.rb_ - Publishes to MQTT broker
41+
* _filesystem.rb_ - Write/Append/Read example on the virtual filesystem
4242

4343
The clean command will clean both the ESP32 build and the mruby build:
4444

main/examples/filesystem.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Wait a bit for startup to complete.
2+
ESP32::System.delay(1000)
3+
4+
string1 = "testing "
5+
string2 = "1,2,3..."
6+
7+
puts "Writing to /spiffs/test.txt: \"#{string1}#{string2}\""
8+
File.open('/spiffs/test.txt', 'w') { |f| f.write(string1) }
9+
File.open('/spiffs/test.txt', 'a') { |f| f.write(string2) }
10+
11+
print "Read from /spiffs/text.txt: "
12+
File.open('/spiffs/test.txt', 'r') { |f| f.each_line { |l| puts l } }
File renamed without changes.
File renamed without changes.
File renamed without changes.

main/examples/wifi_socket.rb

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Stack sizes may need to be increased.
2+
# See: https://github.com/mruby-esp32/mruby-socket/blob/0.4/README.md
3+
#
4+
puts "Getting ready to start Wi-Fi"
5+
6+
wifi = ESP32::WiFi.new
7+
8+
wifi.on_connected do |ip|
9+
puts "Wi-Fi Connected: #{ip} (#{Socket.gethostname})"
10+
soc = TCPSocket.open("www.kame.net", 80)
11+
msg = "HEAD / HTTP/1.1\r\nHost: www.kame.net\r\nConnection: close\r\n\r\n"
12+
msg.split("\r\n").each do |e|
13+
puts ">>> #{e}"
14+
end
15+
soc.send(msg, 0)
16+
puts "--------------------------------------------------------------------------------"
17+
loop do
18+
buf = soc.recv(128, 0)
19+
break if buf.length == 0
20+
print buf
21+
end
22+
puts ""
23+
puts "--------------------------------------------------------------------------------"
24+
end
25+
26+
wifi.on_disconnected do
27+
puts "Wi-Fi Disconnected"
28+
end
29+
30+
puts "Connecting to Wi-Fi"
31+
wifi.connect('SSID', 'PASSWORD')
32+
33+
#
34+
# Loop forever otherwise the script ends
35+
#
36+
while true do
37+
ESP32::System.delay(1000)
38+
end

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy