0

I'm having a hard time trying to understand how I can use my Raspberry Pi to retrieve and display data from my Arduino that has an ESP8266 WiFi module and a DHT temp and humidity sensor connected to it.

My Arduino is outside connected to my bee hives and my Pi3 is in my room. I can ping the ESP's IP address with success. It's been years since I did anything with Python and I'm trying to relearn on my Pi. I don't want to stream to a website and back to my Pi, just want to stay on my home network. Can anyone help me understand how to write a simple script for my Pi? Ps. I'm new to posting questions on forums, arduino, raspberry pi, and networking.

1

You could write something to communicate directly between the ESP8266 and RPi, but a flexible option is to use something like a MQTT broker. The broker itself can run on your RPi, or on another computer. Writing clients to talk to the MQTT broker is trivial on both the ESP8266 (using Arduino IDE) and on the RPi using a variety of libraries, including python. The beauty of this approach is that you can easily add clients and features using the publish and subscribe mode of communications.

  • But wouldn't that make the Pi the Server and not the Arduino? – oibdrew Sep 17 '17 at 1:14
  • 1
    You'd run the MQTT server (Mosquitto) "somewhere". If that somewhere is the RPi, yes, it's the server. But your python code would be written as an MQTT client, subscribing to notifications from, and publishing to topics that the Arduino client is also programmed for. So "yes", in the sense that the RPi can run both the MQTT server and client software at the same time. MQTT is designed specifically for this sort of communication, and is well supported in both python and Arduino. You could, of course, run the MQTT broker elsewhere if desired. – bobstro Sep 17 '17 at 2:27
  • Thanks for your input. This sounds very interesting and I'm going to research this idea more along with trying it out. – oibdrew Sep 17 '17 at 3:32
  • Everything I've researched either uses USB or a website for communication. I'm confused as to how to get the pi to retrieve the data and put it into a spreadsheet by those examples. I have the MQTT installed on my RPI 3. I've flashed the ESP-01 along with putting it in both AP and STA modes. I have successfully ping it but not sure how to connect it to a certain port. – oibdrew Oct 21 '17 at 12:53
  • You need to load some MQTT client software on the RPi. The pubsub client (github.com/knolleary/pubsubclient) is one that I've played with a bit. Once you have that loaded, the ESP can both publish messages and subscribe to topics. I'm no expert, but there are plenty of examples out there. I've generally used WeMos and Adafruit ESP-12-based boards, so don't have any tips on using the ESP-01. – bobstro Oct 24 '17 at 18:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.