I have a DHT22 connected to an Arduino Uno with a simple DHT sketch. Also connected is an ESP8266-01 that has been flashed and an AP +STA mode program uploaded to it. I'm wanting to use a RPI 3 to retrieve temp and humidity data from the Arduino and display it in a spreadsheet.
I have successfully pinged my ESP from my RPI.
I know similar projects have been done but they either use a webpage on the internet (I don't want to do) or a USB connection (also don't want to do), I want to stay on my local network without having to use the internet. Also, my Arduino, DHT, & ESP are about 30 feet from my wifi router and my RPI is another 15 feet the other direction.
I have installed MQTT on my RPI but I don't understand it. It has been years since I did anything with python scripts and honestly I barely remember anything. With that said, I know that python scripts would be the best and easiest way for me on the RPI.
Arduino code :
#include Adafruit_Sensor.h
#include DHT.h
//Constants
#define DHTPIN 2 // what pin we're connected to
#define DHTTYPE DHT11 // DHT 11 (AM2302)
//#define DHTTYPE DHT22 // DHT 22 (AM2302)
DHT dht(DHTPIN, DHTTYPE); //// Initialize DHT sensor for normal 16mhz Arduino
float hum; //Stores humidity value
float temp; //Stores temperature value
void setup() {
Serial.begin(115200);
dht.begin();
}
void loop() {
/////////////////////////////////DHT22///////////////////////////////
{
Serial.println(" Temperature and Humidity (DHT22)");
//Serial.println("");
delay(1000); //Delay 1 sec.
//Read data and store it to variables hum and temp
hum = dht.readHumidity();
temp = dht.readTemperature() * 1.8 + 32.1;
//Fahrenheit = (Celsius * 9 + 2) / 5 + 32; // The +2 takes care of the better rounding
// or you can use-> Celsius * 1.8 + 32
//Print temp and humidity values to serial monitor
Serial.print("Humidity = ");
Serial.print(hum);
Serial.println(" %");
Serial.print("Temp = ");
Serial.print(temp);
Serial.println(" degrees Fahrenheit");
Serial.println("");
Serial.println("");
delay(2000); // waits 2000 milliseconds (2 sec).
}
}
ESP code:
#include <ESP8266WiFi.h> // Include the Wi-Fi library
const char* ssid = "ssid"; // The SSID (name) of the Wi-Fi network you want to connect to
const char* password = "passwrd"; // The password of the Wi-Fi network
const char *ssid2 = "ssid"; // The name of the Wi-Fi network that will be created
const char *password2 = "passwrd"; // The password required to connect to it, leave blank for an open network
void setup() {
Serial.begin(115200); // Start the Serial communication to send messages to the computer
delay(10);
Serial.println('\n');
////////////////////////////**** Station mode ****///////////////////////////////////////////
WiFi.begin(ssid, password); // Connect to the network
Serial.print("Connecting to ");
Serial.print(ssid); Serial.println(" ...");
int i = 0;
while (WiFi.status() != WL_CONNECTED) { // Wait for the Wi-Fi to connect
delay(1000);
Serial.print(++i); Serial.print(' ');
}
Serial.println('\n');
Serial.println("Connection established!");
Serial.print("IP address:\t");
Serial.println(WiFi.localIP()); // Send the IP address of the ESP8266 to the computer
/////////////////////////////**** Access Point mode ****/////////////////////////////////////
WiFi.softAP(ssid2, password2); // Start the access point
Serial.print("Access Point \"");
Serial.print(ssid2);
Serial.println("\" started");
Serial.print("IP address:\t");
Serial.println(WiFi.softAPIP()); // Send the IP address of the ESP8266 to the computer
}
void loop() { }