Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

4 channel iot controller sketches not compiling

Status
Not open for further replies.

sribangaram

Full Member level 5
Joined
Apr 29, 2012
Messages
297
Helped
7
Reputation
14
Reaction score
7
Trophy points
1,298
Location
INDIA.:/;:'" VIJAYAWADA
Activity points
3,754
4 chanal iot controller sketch not compilling

Dear friends i start the project 4 relay controlling through internet
link : https://iot-playground.com/blog/2-uncategorised/92-esp8266-internet-connected-4-relay-switch#program

but this program is not compelling
error : 'MQTT' does not name a type
PHP:
#include <ESP8266WiFi.h>
#include <MQTT.h>

#define AP_SSID     "xxx"
#define AP_PASSWORD "xxx"  

#define EIOTCLOUD_USERNAME "xxx"
#define EIOTCLOUD_PASSWORD "xxx"

// create MQTT object
#define EIOT_CLOUD_ADDRESS "cloud.iot-playground.com"

#define DO_TOPIC        "/Sensor.Parameter1"

#define PIN_DO_1         D0  // DO pin1 
#define MODULE_ID_1     1


#define PIN_DO_2         D1  // DO pin2 
#define MODULE_ID_2     2


#define PIN_DO_3         D2  // DO pin3 
#define MODULE_ID_3     3


#define PIN_DO_4         D3  // DO pin4 
#define MODULE_ID_4     4


MQTT myMqtt("", EIOT_CLOUD_ADDRESS, 1883);


void setup() {
  Serial.begin(115200);

  WiFi.mode(WIFI_STA);  
  WiFi.begin(AP_SSID, AP_PASSWORD);
 
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(AP_SSID);
    
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  };

  Serial.println("WiFi connected");
  Serial.println("Connecting to MQTT server");  

  //set client id
  // Generate client name based on MAC address and last 8 bits of microsecond counter
  String clientName;
  uint8_t mac[6];
  WiFi.macAddress(mac);
  clientName += macToStr(mac);
  clientName += "-";
  clientName += String(micros() & 0xff, 16);
  myMqtt.setClientId((char*) clientName.c_str());

  Serial.print("MQTT client id:");
  Serial.println(clientName);

  // setup callbacks
  myMqtt.onConnected(myConnectedCb);
  myMqtt.onDisconnected(myDisconnectedCb);
  myMqtt.onPublished(myPublishedCb);
  myMqtt.onData(myDataCb);
  
  //////Serial.println("connect mqtt...");
  myMqtt.setUserPwd(EIOTCLOUD_USERNAME, EIOTCLOUD_PASSWORD);  
  myMqtt.connect();

  delay(500);

  pinMode(PIN_DO_1, OUTPUT); 
  pinMode(PIN_DO_2, OUTPUT); 
  pinMode(PIN_DO_3, OUTPUT); 
  pinMode(PIN_DO_4, OUTPUT); 

  subscribe();
}

void loop() {
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
}


String macToStr(const uint8_t* mac)
{
  String result;
  for (int i = 0; i < 6; ++i) {
    result += String(mac[i], 16);
    if (i < 5)
      result += ':';
  }
  return result;
}


void subscribe()
{
    myMqtt.subscribe("/" + String(MODULE_ID_1) + DO_TOPIC); //DO 1
    myMqtt.subscribe("/" + String(MODULE_ID_2) + DO_TOPIC); //DO 2
    myMqtt.subscribe("/" + String(MODULE_ID_3) + DO_TOPIC); //DO 3
    myMqtt.subscribe("/" + String(MODULE_ID_4) + DO_TOPIC); //DO 4
}


void myConnectedCb() {
  Serial.println("connected to MQTT server");
  subscribe();
}

void myDisconnectedCb() {
  Serial.println("disconnected. try to reconnect...");
  delay(500);
  myMqtt.connect();
}

void myPublishedCb() {
  Serial.println("published.");
}

void myDataCb(String& topic, String& data) {  
  if (topic == String("/"+String(MODULE_ID_1)+ DO_TOPIC))
  {
    if (data == String("1"))
      digitalWrite(PIN_DO_1, HIGH);     
    else
      digitalWrite(PIN_DO_1, LOW);

    Serial.print("Do 1:");
    Serial.println(data);
  }


  if (topic == String("/"+String(MODULE_ID_2)+ DO_TOPIC))
  {
    if (data == String("1"))
      digitalWrite(PIN_DO_2, HIGH);     
    else
      digitalWrite(PIN_DO_2, LOW);

    Serial.print("Do 2:");
    Serial.println(data);
  }


  if (topic == String("/"+String(MODULE_ID_3)+ DO_TOPIC))
  {
    if (data == String("1"))
      digitalWrite(PIN_DO_3, HIGH);     
    else
      digitalWrite(PIN_DO_3, LOW);

    Serial.print("Do 3:");
    Serial.println(data);
  }

  if (topic == String("/"+String(MODULE_ID_4)+ DO_TOPIC))
  {
    if (data == String("1"))
      digitalWrite(PIN_DO_4, HIGH);     
    else
      digitalWrite(PIN_DO_4, LOW);

    Serial.print("Do 4:");
    Serial.println(data);
  }
  
}
Please tell me ware i am mistake
 

Re: 4 chanal iot controller sketch not compilling

Do you really have these MQTT.h and MQTT.c files at the folder where your Arduino code is ? Perhaps not the case, but whenever I add files to the project folder, I do this by using #include "FILE" instead of #include <FILE>
 

Re: 4 chanal iot controller sketch not compilling

Yes friend i have to added MQTT library files but i dont know that files are correct or wrong i am attaching that library file pls once check your end
 

Attachments

  • MQTT-2.3.3.zip
    33.3 KB · Views: 87

Re: 4 chanal iot controller sketch not compilling

It do not seem the correct usage on your code.
Why don't you have a look at the examples on the attached file ?

There, at a random example, it is being declared the type:

Code:
MQTTClient client;

instead the way as you did:

Code:
MQTT myMqtt("", EIOT_CLOUD_ADDRESS, 1883);
 

Re: 4 chanal iot controller sketch not compilling

OK got it thanks to your reply But how i will change the code like that please explain to me
 

Re: 4 chanal iot controller sketch not compilling

how i will change the code like that please explain to me

The initial question was answered; now you expect someone to make the necessary modifications to change your program to work with the correct library...are you serious?
 

Re: 4 chanal iot controller sketch not compilling

Friend i am not getting correct library please atleest provide the correct library files Please excuse me my poor english

- - - Updated - - -

Friend i am not getting correct library please atleest provide the correct library files Please excuse me my poor english
 

Re: 4 chanal iot controller sketch not compilling

i am not getting correct library please atleest provide the correct library files

You have the correct library and associated examples, all within the above compressed file.
What else do you need to start making your own experiments ?
 

Re: 4 chanal iot controller sketch not compilling

Friend i am try to lode this files for arduino library but it says this is not library files this files i am getting from GitHub
 

Attachments

  • esp_mqtt-master.zip
    47 KB · Views: 96
  • mqtt.zip
    22.2 KB · Views: 96

Re: 4 chanal iot controller sketch not compilling

Hi,

Read about ".zip" format.

It is a packed file. There are many real files within this zip file. You need to "extract" the real files first.

Klaus
 

Re: 4 chanal iot controller sketch not compilling

Friend thanks to your reply I have to done like that after then also I am getting same error
'MQTT' does not name a type
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top