0

I have a mqtt + nodejs server for my smart home system. First , I am trying to blink a led from my mqtt + nodejs server.

I made this with nodemcu a board. I used pubsubclient.h for this, but I wanted to add more sensors and leds. Because of that, I decided to use Arduino mega + esp8266. I want to connect to my server via esp8266. The problem is I can't use pubsubclient.h with the Arduino mega + esp8266.

And I started using AT Commands to connect to a wifi. Now, I can connect to wifi, but I don't know how can I use mqtt now.

I found a library espduino, but it needs special connections.

How can I use AT commands and Mqtt for my project?

Ahmad F
  • 30,560
  • 17
  • 97
  • 143
Crazy Coders
  • 133
  • 1
  • 12
  • Possible duplicate of [mqtt between esp8266 and arduino with PubSubclient](http://stackoverflow.com/questions/37030019/mqtt-between-esp8266-and-arduino-with-pubsubclient) – hardillb Jun 05 '16 at 23:13

3 Answers3

0

You should probably try to use a multiplexer instead (like the 4051). You can than expand 4 IO ports to 8 IO's (or 1 analog + 3 IO to 8 analog ports). If you want even more ports get something like a 4067, then you can get 16 ports out of 5.

The esp8266 is much more powerful than a normal Arduino (with an ATMEGA328 chip), it's also cheaper than the ArduinoMega, so try to keep it as your microcontroller (if you are already using it).

Cristóvão Trevisan
  • 1,775
  • 17
  • 18
0

You need to denote a WiFi or Ethernel client instance to establish connection to the broker via MQTT libraries. So, while doing serial communication, you need to have a serial Arduino library which work with ESP and implements protocol headers and stacks.

You can use WiFiEsp library to create a client instance of WiFi. So you will be able to pass your client as parameter to the PubSubClient constructor. Here is example :

WiFiEspClient espClient;
PubSubClient client(espClient);

Another serial library is espduino as you mentioned. You can follow its guide and use the MQTT library of Arduino like that :

#include <SoftwareSerial.h>
#include <espduino.h>
#include <mqtt.h>

SoftwareSerial debugPort(2, 3); // RX, TX
ESP esp(&Serial, &debugPort, 4);
MQTT mqtt(&esp);

Good luck!

cagdas
  • 1,634
  • 2
  • 14
  • 27
0

I will suggest that you try Homie-esp8266. I think it will fit your current setup. It supports MQTT, easy wifi configuration and Over The Air (OTA) firmware update. The documentation is pretty straight forward as well. It's what I use currently in my smart home project.

Temi Adeyeri
  • 47
  • 1
  • 5