File tree Expand file tree Collapse file tree 4 files changed +32
-2
lines changed
components/mruby_component Expand file tree Collapse file tree 4 files changed +32
-2
lines changed Original file line number Diff line number Diff line change @@ -36,6 +36,7 @@ The valiable `YOU_WISH_TO_TRY_FILE` can be replaced with one of the following:
36
36
* _ simplest_mrb.rb_ - Simply prints two strings
37
37
* _ wifi_example_mrb.rb_ - An example of connecting to WiFi, you will need to
38
38
modify this file to include your SSID and password
39
+ * _ mqtt_publish.rb_ - An sample of publishing to MQTT broker
39
40
* _ system_mrb.rb_ - Examples of most of the system APIs
40
41
41
42
The clean command will clean both the ESP32 build and the mruby build:
@@ -50,5 +51,6 @@ configuration file found in
50
51
51
52
* _ mruby-esp32-system_ - ESP32 system calls
52
53
* _ mruby-esp32-wifi_ - ESP32 WiFi
54
+ * _ mruby-esp32-mqtt_ - ESP32 MQTT library
53
55
54
56
Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ set(MRUBY_CONFIG ${COMPONENT_DIR}/esp32_build_config.rb)
4
4
5
5
idf_component_register (
6
6
INCLUDE_DIRS mruby/include
7
- REQUIRES esp_wifi esp_hw_support esp_rom
7
+ REQUIRES esp_wifi esp_hw_support esp_rom mqtt
8
8
)
9
9
10
10
add_custom_command (
@@ -17,7 +17,7 @@ add_custom_command(
17
17
18
18
add_prebuilt_library (
19
19
libmruby ${LIBMRUBY_FILE}
20
- PRIV_REQUIRES esp_wifi esp_hw_support esp_rom
20
+ PRIV_REQUIRES esp_wifi esp_hw_support esp_rom mqtt
21
21
)
22
22
target_link_libraries (${COMPONENT_LIB} INTERFACE libmruby )
23
23
Original file line number Diff line number Diff line change 63
63
conf . gem :core => "mruby-compiler"
64
64
conf . gem :github => "mruby-esp32/mruby-esp32-system"
65
65
conf . gem :github => "mruby-esp32/mruby-esp32-wifi"
66
+ conf . gem :github => "mruby-esp32/mruby-esp32-mqtt"
67
+ conf . gem :github => "mruby-esp32/mruby-io" , :branch => 'esp32'
66
68
end
Original file line number Diff line number Diff line change
1
+ wifi = ESP32 ::WiFi . new
2
+
3
+ wifi . on_connected do |ip |
4
+ puts "Connected: #{ ip } "
5
+
6
+ mqtt = ESP32 ::MQTT ::Client . new ( 'test.mosquitto.org' , 1883 )
7
+ mqtt . connect
8
+ mqtt . publish ( "mruby-esp32-mqtt" , '{ "hello": "world." }' )
9
+ mqtt . disconnect
10
+ end
11
+
12
+ wifi . on_disconnected do
13
+ puts 'Disconnected'
14
+ end
15
+
16
+ puts 'Connecting to wifi'
17
+ wifi . connect ( 'SSID' , 'password' )
18
+
19
+ #
20
+ # Loop forever otherwise the script ends
21
+ #
22
+ while true do
23
+ mem = ESP32 ::System . available_memory ( ) / 1000
24
+ puts "Free heap: #{ mem } K"
25
+ ESP32 ::System . delay ( 10000 )
26
+ end
You can’t perform that action at this time.
0 commit comments