How do I use MQTTClient library on Arduino to publish and subscribe to the MQTT broker installed on a Mac using Homebrew?

56 views Asked by At

I have create a MQTT system using MQTTClient library on my Arduino IDE for ESP8266 to publish and subscribe to io.Adafruit. Everything is working great except there is some functionality that I can't get on an app I developed for my iPhone/iPad using MQTT. So I have installed a Mosquitto broker on an old MacBook pro using Homebrew. When I look at the Publish and Subscribe code for the broker on the MacBook it looks different than that I use on the Arduino and iPhone app.

//this is on the arduino using MQTTClient library
//connect
Adafruit_MQTT_Client mqtt(&client, AIO_SERVER, AIO_SERVERPORT, AIO_USERNAME, AIO_KEY);
//publish
Adafruit_MQTT_Publish temperature = Adafruit_MQTT_Publish(&mqtt, AIO_USERNAME "/feeds/temperature");
//subscribe
Adafruit_MQTT_Subscribe trip2 = Adafruit_MQTT_Subscribe(&mqtt, AIO_USERNAME "/feeds/temperature");

On the local Mosquitto on MacBook I use this it subscribe

mosquitto_sub -t topic/state

//and this to publish

mosquitto_pub -t topic/state -m "hello World"

Is there a way to reconcile these so they work together? Can someone recommend a book or website or tutorial that will help me do this?

0

There are 0 answers