I'm searching now for two weeks and i can't figure it out how to implement it in my code.
I want to be able to adjust the value ZonAAN and ZonUIT on the web page.
Can someone help me with this please?
And possibly also explain why an INT is not shown in an inputTEXT field, in another way I can make it appear, see next to the input text.
The code:
#include <Arduino.h>
#include "config.h"
#include <HardwareSerial.h>
#include <ModbusMaster.h>
#include <SPI.h>
#include <WiFi.h>
#include <AsyncTCP.h>
#include <ESPAsyncWebServer.h>
//Login gegevens van AP
const char* ssid = "CAIRRA";
const char* password = "CAIRRA2022";
WiFiServer server(80);
String header;
HardwareSerial Serial485(2);
ModbusMaster node;
// set pin numbers
const int buttonPin = 18; // the number of the pushbutton pin
// variable for storing the pushbutton status
int buttonState = 0;
//Temperatuur instellingen per status
int zonAAN = 60;
int zonUIT = 50;
//Modbusregister schrijven
int ModRegister = 6;
// Current time
unsigned long currentTime = millis();
// Previous time
unsigned long previousTime = 0;
// Define timeout time in milliseconds (example: 2000ms = 2s)
const long timeoutTime = 2000;
void setup()
{
pinMode(RS485_EN_PIN, OUTPUT);
digitalWrite(RS485_EN_PIN, HIGH);
pinMode(RS485_SE_PIN, OUTPUT);
digitalWrite(RS485_SE_PIN, HIGH);
pinMode(PIN_5V_EN, OUTPUT);
digitalWrite(PIN_5V_EN, HIGH);
Serial.begin(9600);
Serial485.begin(9600, SERIAL_8N1, RS485_RX_PIN, RS485_TX_PIN);
delay(5);
Serial.println("test");
//Slave id = 2
node.begin(2, Serial485);
// initialize the pushbutton pin as an input
pinMode(buttonPin, INPUT);
// Connect to Wi-Fi network with SSID and password
Serial.println("Configuring access point...");
WiFi.mode(WIFI_AP);
WiFi.softAP(ssid, password);
Serial.println("Wait 100 ms for AP_START...");
delay(100);
Serial.println("Set softAPConfig");
IPAddress Ip(192, 168, 1, 1);
IPAddress NMask(255, 255, 255, 0);
WiFi.softAPConfig(Ip, Ip, NMask);
IPAddress myIP = WiFi.softAPIP();
Serial.print("AP IP address: ");
Serial.println(myIP);
server.begin();
}
void loop()
{
WiFiClient client = server.available(); // Listen for incoming clients
if (client) { // If a new client connects,
Serial.println("New Client."); // print a message out in the serial port
String currentLine = ""; // make a String to hold incoming data from the client
while (client.connected()) { // loop while the client's connected
if (client.available()) { // if there's bytes to read from the client,
char c = client.read(); // read a byte, then
Serial.write(c); // print it out the serial monitor
header += c;
if (c == '\n') { // if the byte is a newline character
// if the current line is blank, you got two newline characters in a row.
// that's the end of the client HTTP request, so send a response:
if (currentLine.length() == 0) {
// HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK)
// and a content-type so the client knows what's coming, then a blank line:
client.println("HTTP/1.1 200 OK");
client.println("Content-type:text/html");
client.println("Connection: close");
client.println();
// Display the HTML web page
client.println("<!DOCTYPE html><html>");
client.println("<head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">");
client.println("<link rel=\"icon\" href=\"data:,\">");
// CSS style
// Feel free to change the background-color and font-size attributes to fit your preferences
client.println("<style>html { font-family: Helvetica; display: inline-block; margin: 0px auto; text-align: center;}");
client.println(".button {background-color: #4CAF50; border: none; color: white; padding: 16px 40px; text-decoration: none; font-size: 30px; margin: 2px; cursor: pointer;}");
client.println(".button2 {background-color: #555555;}");
client.println("</style></head>");
// Web Page Heading
client.println("<body><h1>HEATPUMP</h1>");
// Display current state, and settings for watertemp
client.println("<p>Zonnepanelen</p>");
if (buttonState == HIGH) {
client.println("<p><button class=\"button\">AAN</button></p>");
} else {
client.println("<p><button class=\"button button2\">UIT</button></p>");
}
client.println("<p></p>");
client.println("<p>Watertemperatuur bij gesloten contact:</p>");
client.println(zonAAN);
client.println("<label for='WaterHIGH'></label><input type='text' id='WaterHIGH' name='WaterHIGH' maxlength='2' size='4' value=zonAAN>");
client.print((char)176);
client.print("C ");
client.println("<a href=\"/rgbw/apply\"><button class=\"button3\">SET</button></a>");
client.println("<p></p>");
client.println("<p>Watertemperatuur bij open contact:</p>");
client.println(zonUIT);
client.println("<label for='WaterLOW'></label><input type='text' id='WaterLOW' name='WaterLOW' maxlength='2' size='4' value='50'>");
client.print((char)176);
client.print("C ");
client.println("<a href=\"/rgbw/apply\"><button class=\"button3\">SET</button></a>");
client.println("<p></p>");
client.println("</body></html>");
// The HTTP response ends with another blank line
client.println();
// Break out of the while loop
break;
} else { // if you got a newline, then clear currentLine
currentLine = "";
}
} else if (c != '\r') { // if you got anything else but a carriage return character,
currentLine += c; // add it to the end of the currentLine
}
}
}
// Clear the header variable
header = "";
// Close the connection
client.stop();
Serial.println("Client disconnected.");
Serial.println("");
}
// read the state of the pushbutton value
buttonState = digitalRead(buttonPin);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH
if (buttonState == HIGH) {
// turn LED on
Serial.println("Contact gesloten");
node.writeSingleRegister(ModRegister, zonAAN);
} else {
// turn LED off
Serial.println("Contact open");
node.writeSingleRegister(ModRegister, zonUIT);
}
delay(2000);
}