Skip to content

Latest commit

 

History

History
70 lines (49 loc) · 1.14 KB

README.md

File metadata and controls

70 lines (49 loc) · 1.14 KB

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.