Error: 'MQTT' does not name a type - Help please

Hi, I hope this is the correct forum to post this.

You may have dealt with this issue before. I am a newbie to this environment and struggling to resolve this issue. I have implement a DHT22 temperature sensor. I used platformio from the beginning and I find a good environment to work with.

I am using the example code below but I am unable to resolve it. I get this compilation error: All I am looking for is a clean compile. Maybe you can try it on your environment to see if you get the same error.

BasicOTA.ino:18:21: error: ‘MQTT’ does not name a type
BasicOTA.ino:18:34: error: expected unqualified-id before ‘&’ token
BasicOTA.ino:18:34: error: expected ‘)’ before ‘&’ token
BasicOTA.ino:18:36: error: expected initializer before 'pub’
BasicOTA.ino:23:36: error: no matching function for call to ‘PubSubClient::PubSubClient(WiFiClient&, IPAddress&)’

Your help would really be appreciated.
Cheers Bruno

I have these two libraries installed:

[ 89 ] PubSubClient
[ 127 ] ESP8266


platform = espressif
framework = arduino
board = nodemcu

This is the code

 Basic MQTT example

  - connects to an MQTT server
  - publishes "hello world" to the topic "outTopic"
  - subscribes to the topic "inTopic"

#include <ESP8266WiFi.h>
#include <PubSubClient.h>

const char *ssid =	"xxxxxxxx";		// cannot be longer than 32 characters!
const char *pass =	"yyyyyyyy";		//

// Update these with values suitable for your network.
IPAddress server(172, 16, 0, 2);

void callback(const MQTT::Publish& pub) {
  // handle message arrived

WiFiClient wclient;
PubSubClient client(wclient, server);

void setup() {
  // Setup console


hi @bzanin !
Where did you get this example? Here is correct Basic MQTT example.
Please take a look at current PubSubClient API as well.

Hi Valeros,

Thanks for your replay.

I managed to sort out the issues using the Arduino IDE.



What did ya do…? I am facing the same error.