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?

1

3 Answers 3

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).

Sign up to request clarification or add additional context in comments.

Comments

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!

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.