Arduino MEGA passing data to an 8266 using MQTT for Home Assistant

Hi,

I have an Arduino MEGA doing lots of tasks with other devices, all running nicely for years.
I now want to this data to appear in Home Assistant but all tutorials I am seeing are very confusing...

Would this be the easiest?

Use ESP8266 to handle wifi as it seems to have powerful libraries.
MEGA to forward data to ESP8266 (how to do this?)
8266 to connect to MQTT server and handle data transfer

Not sure where to start with the code for this, any help appreciated.

Thanks

first learn to work with a esp8266 module. buy a esp8266 board with USB (Wemos D1 mini or NodeMCu) or use a USB-to-TTL-Serial adapter with esp-01 module. I can guide you.

Juraj:
first learn to work with a esp8266 module. buy a esp8266 board with USB (Wemos D1 mini or NodeMCu) or use a USB-to-TTL-Serial adapter with esp-01 module. I can guide you.

Hi,
I have one of these on order, https://www.ebay.com.au/itm/USB-to-ESP8266-ESP-01-ESP-01S-Serial-Wireless-Wifi-Adapter-CH340G-Driver-Module/143149758885
I am comfortable with the 8266, I have used them before in AT command mode but not sure how to actually move data from the MEGA to the 8266 in webserver mode?

Thanks

dudester:
Hi,
I have one of these on order, https://www.ebay.com.au/itm/USB-to-ESP8266-ESP-01-ESP-01S-Serial-Wireless-Wifi-Adapter-CH340G-Driver-Module/143149758885
I am comfortable with the 8266, I have used them before in AT command mode but not sure how to actually move data from the MEGA to the 8266 in webserver mode?

Thanks

your options are

  • use AT firmware
  • plain
  • with WiFiEsp library (has problem to reliably receive more the 64 bytes)
  • use WiFiLink firmware (with this you have the additional option to upload sketch over network)
  • with WiFiLink library (UDP is buggy)
  • write your own sketch for the esp8266 and handle the network communication in esp8266
  • you must then code the data exchange over Serial between MCUs

the WiFiEsp and the WiFiLink library have the same API (taken from the Arduino WiFi library) so it is easy to switch between this libraries (and firmwares). and the code is easy to port to Ethernet library

Whats the easiest method to connect with Home Assistants MQTT?
Last time I used these with the AT method I remember it was very unreliable and very code heavy, Im looking for a much easier method now.

dudester:
Whats the easiest method to connect with Home Assistants MQTT?
Last time I used these with the AT method I remember it was very unreliable and very code heavy, Im looking for a much easier method now.

it should be PubSubClient library over WiFiEsp library with AT firmware in esp-01.

if the responses are small it will work good. If we can't solve it with WiFiEsp then we can switch to WiFiLink without changes in sketch.

I connected an esp8266 to a mega and uploaded the adjusted code here: