I am using ESP8266 and Arduino with SoftwareSerial
. My requirement is to use MQTT protocol with it. So I am using an MQTT library named pubSubClient
but the problem is it doesn't support SoftwareSerial
. Could anyone tell me how can I use MQTT protocol with it?
#include
#include
SoftwareSerial esp(2, 3); // RX, TX
PubSubClient client(esp);
The error I get is: no matching function for call to 'PubSubClient::PubSubClient(SoftwareSerial&)
2 Answers 2
In order to use the ESP8266 WiFi module with pubSubCient
, you need a library that interfaces with the module with the usual AT commands, while presenting an Arduino Client
interface on the surface. A while back, I found this library after a great deal of searching. It supports SoftwareSerial
as well as HardwareSerial
objects. Its ESP8266 interface provides the standard Client
methods of write()
, read()
, connected()
, etc. There are some issues, of course, but its the best I've found so far. You can pass the created Client
object to the pubSubClient
constructor and you're good to go.
Not sure what you're trying to do - but thought I would offer this since I just spend some time on getting my esp8266 to act as a wifi shield for my arduino. Basically I wanted to subscribe to an mqtt channel and send the payload to my arduino. So the esp8266 connected to a broker, upon reading a message, it would simply write it via serial to the arduino (I used software serial on the arduino side so I could use the standard serial for debugging). If it helps, check out http://mganis.blogspot.com for the details
--Matt
PubSubClient
. A brief google failed to find any SoftwareSerial clients but there is a ESP8266 PubSubClient here : github.com/knolleary/pubsubclient