safiraaa
Posts: 1
Joined: Wed Dec 11, 2019 12:46 pm

How to connect with ESP8266 and Raspberry pi

Wed Dec 11, 2019 1:10 pm

Hi guys,

I have a project about security access with RFID card reader. I have codes to work the RFID card read system but the main problem I want to use the wireless connection between RFID card reader (rc522) and raspberry pi. I decided to use ESP8266 for this connect. And I guess, I should use the MQTT protocol for communication between ESP8266 and raspberry pi. But in this way my code will be work? And how? Because the esp should take the card uid from rc522 after transmit to the raspberry pi. And the raspberry should take the card uid and execute the code and my door will open. Or do you have any different idea?

Thank you

User avatar
neilgl
Posts: 1392
Joined: Sun Jan 26, 2014 8:36 pm
Location: Near Aston Martin factory

Re: How to connect with ESP8266 and Raspberry pi

Wed Dec 11, 2019 9:00 pm

Yes that will work. Install mqtt on the esp8266 and get it to publish topics about the rfid reader. Install mqtt (mosquitto) on the pi and set it to be the mqtt server (mqtt broker). Have a python script on the pi that listens for topics (messages) that the esp8266 publishes. Whne the relevant topic is received, the pi can "open the door".
I use the Arduino IDE to program the esp8266 (install correct board support for esp8266 and the mqtt pubsub library). The library for mqtt can then be included in the sketch

Code: Select all

#include <PubSubClient.h>
with your code to read the RFID card reader.

User avatar
DougieLawson
Posts: 37083
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: How to connect with ESP8266 and Raspberry pi

Thu Dec 12, 2019 4:46 am

I've got some code that does precisely what Neil is suggesting at: https://github.com/DougieLawson/Wemos_Arduino_MQTT
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

DangerousThing
Posts: 5
Joined: Mon Feb 03, 2014 7:17 pm

Re: How to connect with ESP8266 and Raspberry pi

Thu Dec 12, 2019 4:57 am

Hello,

For a while I was using the mosquito server on a pi zero to handle communication between a robot and my laptop. MQTT is a very lightweight protocol and great for things like that.

You would need to write the code on the ESP8266 to publish to the MQTT server.

Jay

MarkDH102
Posts: 377
Joined: Fri Feb 13, 2015 3:18 pm

Re: How to connect with ESP8266 and Raspberry pi

Thu Dec 12, 2019 7:23 am

I too use MQTT with a Pi2B and a few ESP8266.
My PI is connected to my amplifier and runs "OK GOOGLE" voice recognition software that allows me to play locally stored music.
The ESP8266 are embedded within plastic pattress boxes along with a small PSU and a relay and allow me to switch mains to the socket mounted on the pattress box. So I just say socket 1 on/off socket 2 on/off etc. They all connect to my local network along with the Pi.
It's all very neat and simple. The code is simple. MQTT is the way for you to go with this...

And before anyone asks, I am competent to deal with the mains side of things. It is all properly fused/isolated etc. :D

Return to “Beginners”