Skip to content

mruby-esp32/mruby-esp32-mqtt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mruby-esp32-mqtt

MQTT library for mruby-esp32.

Installation

You need esp-idf v5.0 to use this mrbgems.

Add the line below to your build_config.rb:

  conf.gem :github => 'mruby-esp32/mruby-esp32-mqtt'

In addition, you may need to add mqtt to the component linking mruby.

idf_component_register(
  # ...
  REQUIRES esp_wifi esp_hw_support esp_rom mqtt # <- add
)

add_prebuilt_library(
  # ...
  PRIV_REQUIRES esp_wifi esp_hw_support esp_rom mqtt # <- add
)

Examples

Connect MQTT.

mqtt = ESP32::MQTT::Client.new('test.mosquitto.org', 1883)
mqtt.connect

Connect MQTT + TLS.

mqtt = ESP32::MQTT::Client.new('test.mosquitto.org', 8883)
mqtt.ssl = true
mqtt.ca = IO.read('root-ca.pem')
mqtt.cert = IO.read('certificate.pem.crt')
mqtt.key = IO.read('private.pem.key')
mqtt.connect

Publish message to topic.

mqtt.publish("topic", 'message')

Subscribe to topic and get message.

mqtt.subscribe("topic")
topic, message = mqtt.get

Disconnect.

mqtt.disconnect

LICENSE

MIT License.

About

MQTT library for mruby-esp32.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published