Hi im trying to conect 2 wemos's together through a router on my network. I have written code that takes temp and humidity and a indication if a door is open and the results are passed onto a local web page. The question is how do i get another wemos to get the readings from this web page and display the results on an lcd.
please find attached my code so far
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <DHT.h>
#include <Wire.h>
#include <SPI.h>
const int REED_PIN = D6; // Pin connected to reed switch
#define DHTPIN D3 // what digital pin we're connected to
#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321
const char* ssid = "**************";
const char* password = "*******";
ESP8266WebServer server(80);
DHT dht(DHTPIN, DHTTYPE);
float t;
float h;
float hic;
float minTemp;
float maxTemp;
float Switch;
// Go to http://192.168.1.5 in a web browser connected to this access point to see it.
void setup()
{
delay(1000);
float t = 0.00;
float h = 0.00;
float hic = 0.00;
float minTemp = 0.00;
float maxTemp = 0.00;
dht.begin();
u8g2.begin();
Serial.begin(115200);
pinMode(D3, INPUT);
pinMode(REED_PIN, INPUT_PULLUP);
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LOW);
Serial.println();
Serial.println("Configuring access point...");
WiFi.softAP(ssid, password);
Serial.print("AP Name: ");
Serial.println(ssid);
server.on("/", HTTP_GET, handleRoot);
server.on("/home", Home);
server.on("/door", door);
server.on("/temp", temp);
server.on("/reset", minmax);
server.on("/toggle", toggleLED);
server.onNotFound([](){server.send(404, "text/plain", "404: Not found");});
server.begin();
Serial.println("HTTP server started");
}
void loop()
{
server.handleClient();
}
void handleRoot() {
server.send(200, "text/html", "<form action=\"/home \" method=\"POST\"><input type=\"submit\" value=\"HOME\"></form>");
}
void Home() {
String webpage = "<meta name = 'viewport' content = 'width = device-width'>";
webpage+="<h1>Chicken Shed Home Page</h1>";
webpage+="<form action=\"/toggle\" method=\"POST\"><input type=\"submit\" value=\"TOGGLE LED\"></form>";
webpage+= "<form action=\"/door\" method=\"POST\"><input type=\"submit\" value=\"Door Status\"></form>";
webpage+= "<form action=\"/temp\" method=\"POST\"><input type=\"submit\" value=\"TEMPERATURE\"></form>";
server.send(200, "text/html", webpage);
}
void door() {
int Switch = digitalRead(REED_PIN);
if (Switch <= 0)
{
Serial.println("Door Closed");
Serial.println(Switch);
}
if (Switch > 0)
{
Serial.println("Door Open");
Serial.println(Switch);
}
String webpage = "<head><meta name = 'viewport' content = 'width = device-width'><meta http-equiv='refresh' content='5'>";
webpage+="</head><h1>Chicken Door</h1><h2>";
webpage+= Switch;
webpage+= "<h1> 0 = Door Closed </h1><h2> ";
webpage+= "<h1> 1 = Door Open </h1><h2> ";
webpage+= "<form action=\"/home \" method=\"POST\"><input type=\"submit\" value=\"HOME\"></form>";
webpage+= "<form action=\"/temp\" method=\"POST\"><input type=\"submit\" value=\"TEMPERATURE\"></form>";
server.send(200, "text/html", webpage);
}
void temp() {
h = dht.readHumidity();
t = dht.readTemperature();
hic = dht.computeHeatIndex(t, h, false);
if (isnan(h) || isnan(t)) {
Serial.println("Failed to read from DHT sensor!");
}
if (minTemp > t) {
minTemp = t;
}
if (maxTemp < t) {
maxTemp = t;
}
Serial.print("Temperature: ");
Serial.print(t);
Serial.print(" *C\t");
Serial.print("Humidity: ");
Serial.print(h);
Serial.print(" %\t");
Serial.print("Heat index: ");
Serial.print(hic);
Serial.println(" *C ");
Serial.print("Min Temp: ");
Serial.print(minTemp);
Serial.print(" *C\t");
Serial.print("Max Temp: ");
Serial.print(maxTemp);
Serial.println(" *C\t");
String webpage = "<head><meta name = 'viewport' content = 'width = device-width'><meta http-equiv='refresh' content='20'>";
webpage+="</head><h1>Temperature</h1><h2>";
webpage+= t;
webpage+=" *C</h2>";
webpage+="<h1>Humidity</h1><h2>";
webpage+= h;
webpage+=" %</h2>";
webpage+="<h1>Feels Like</h1><h2>";
webpage+= hic;
webpage+= " *C</h2>";
webpage+="<h1>Min Temp</h1><h2>";
webpage+= minTemp;
webpage+=" *C</h2>";
webpage+="<h1>Max Temp</h1><h2>";
webpage+= maxTemp;
webpage+= " *C</h2>";
webpage+= "<form action=\"/home \" method=\"POST\"><input type=\"submit\" value=\"HOME\"></form>";
webpage+= "<form action=\"/door\" method=\"POST\"><input type=\"submit\" value=\"DOOR STATUS\"></form>";
webpage+= "<form action=\"/reset\" method=\"POST\"><input type=\"submit\" value=\"RESET MIN/MAX\"></form>";
server.send(200, "text/html", webpage);
}
void minmax() {
minTemp = t;
maxTemp = t;
server.sendHeader("Location","/temp"); // Add a header to respond with a new location for the browser to go to the home page again
server.send(303); // Send it back to the browser with an HTTP status 303 (See Other) to redirect
}
void toggleLED() {
digitalWrite(LED_BUILTIN,!digitalRead(LED_BUILTIN));
server.sendHeader("Location","/home"); // Add a header to respond with a new location for the browser to go to the home page again
server.send(303); // Send it back to the browser with an HTTP status 303 (See Other) to redirect
}
I have been told to use post but not sure how to go about it. I presume (which like normal, is wrong to do) what i have done is to send the data to a local web page then use the second wemos to pull the data from the webpage. Is this the right or wrong way to do it