Web Server. Using 2 buttons to inc or dec a value.

:frowning:

Please help, I have almost finished my Simple Thermostat Project.
Code is below.

Temperature is measured using a LM35, and is known as temperatureC in my program, I also have a setpoint. I have this working so that it controls the relay depending on the value of the setpoint.

I had a keypad which called incUP() and incdown() which worked fine. But I removed the keypad I want to set the setpoint remotley via web page.

I have managed to display the temperature and Setpoint on a webpage after a good explanation of Pauls.

But know I'm truly stuck.

I need a Inc and dec button in my webpage function to toggle a flag or state on off so to call the IncUp or Down Fucntion.

Please help.

Code below. Thanks Andy

//Headers
#include <EtherCard.h>
#include <EEPROM.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
//option #include <HCMatrixKeypad.h>

//Webpage
boolean toggle;
static uint8_t IPaddress[] = { 192,168,1,225 };
static uint8_t GatewayIP[] = { 192,168,1,1 };
static uint8_t MACAddress[6] = {0x54, 0x55, 0x58, 0x10, 0x00, 0x24};
byte Ethernet::buffer[500];
BufferFiller bfill;


 /* Initialise the LiquidCrystal library */
LiquidCrystal_I2C lcd(0x27,20,4);
/* Optional Keypad */
const int DEBOUNCE = 10;
//const byte Left = 4;  // Column number of Left key
//const byte Right = 3;  // Column number of Right key
//Declare Variables
float setpoint;
char temp_str[10];
char setpoint_str[10];
float temperatureC;
const int sensorPin = A2;
void setup()

{
  Serial.begin(9600);
  setupnic();
  lcd.init();
  EEPROM.read (1); // make the eeprom or atmega328 memory address 1
  setpoint = EEPROM.read(1);
  setpoint = 20;
  lcd.begin(16, 2);
  lcd.print("Deg C");
  lcd.setCursor(6, 0);
  lcd.print("SetP");
  pinMode(13, OUTPUT);
  pinMode(9, OUTPUT); 

}

 

  /* Main program */
void loop() {

 
  
  web();
  lcd.backlight();
  temperatureC = gettemp();
  dtostrf(temperatureC,6,2,temp_str);
  dtostrf(setpoint,6,2,setpoint_str);
  lcd.setCursor(0, 1);
  lcd.print(temperatureC);
  lcd.setCursor(6, 1);
  lcd.print (setpoint);
    if (temperatureC +0.5 < setpoint)
        digitalWrite(9, HIGH);
  if (temperatureC -0.5 > setpoint)
    digitalWrite(9, LOW);
    
}

void setupnic(){
 
  Serial.print ("INIT");
  if (ether.begin(sizeof Ethernet::buffer, MACAddress) == 0) 
  {
    /* If it failed to initialise then do nothing */
    while(1);
  }
  /* Else set up a fixed IP address */
  ether.staticSetup(IPaddress, GatewayIP); 
}


void web(){
 /* Get length of recived packet */
  word PacketLength = ether.packetReceive();
  word pos = ether.packetLoop(PacketLength);
  /* Has a valid packet been received? If so, then send the web page */
  if (ether.packetLoop(PacketLength))  
    ether.httpServerReply(ExampleContenet()); 



}
static word ExampleContenet() 
        
   {
  
     BufferFiller bfill = ether.tcpOffset();
      bfill.emit_p(PSTR(
    "HTTP/1.0 200 OK\r\n"
        "Content-Type: text/html\r\n"
        "Pragma: no-cache\r\n\r\n"
// if you want to enable the auto refresh mode
//      "<meta http-equiv='refresh' content='5'/>"
        "<html><head><title>Web Control</title></head><body>"
        "<body bgcolor=""#ccccff"">"
        "<font size=""6"">"
        "<center>
"
        "Temperature... : "
        "<b> $S &deg;C </b> 
"
        "Desired Temperature... : "
        "<b> $S &deg;C </b> 
"
        "____________________
"
        "
"),
        temp_str,setpoint_str);
        return bfill.position();

}
     
      
float gettemp() {
  // converting an analog reading to a voltage,
  // for 3.3v arduino use 3.3
  float voltage = (analogRead(sensorPin));
float millivolts= (voltage/1024.0) * 5000;
float celsius= millivolts/10;
  //converting from 10 mv per degree C with 500 mV offset
  //to degrees ((voltage - 500mV) times 100)
  delay(10);
  return (celsius) ;
  }
void incUP() {
  setpoint = setpoint + 1;
  EEPROM.write (1, setpoint);
}

void incDown() {
  setpoint = setpoint - 1;
  EEPROM.write (1, setpoint);
}

I don't understand the point of sending old crap to the client and then getting new data. Please explain why the call to getTemp() is after the call to web().

I need a Inc and dec button in my webpage

So put them there. The process of doing that is EXACTLY the same as doing it on a PC. This is NOT the place to ask about how to write html.

HTML Tutorial is.

I need a Inc and dec button in my webpage function to toggle a flag or state on off so to call the IncUp or Down Fucntion.

Make buttons that sends + and - characters (or similar "raise" and "lower"), then look for these in the GET request from the browser. If they are present, increase or decrease the desired value.