Webserver and timer functions

HI I adopted the code that was posted by @zoomkat and tried to extend it a bit by using adding a timed function.

My project in a nutshel, my aim is to control lights from the internet and put them in timed control as well. I will be switching between two modes using a physical button to start with. I have the timed control working separately and the webserver working separately. The problem I am having is combining the two codes. When the switch is high its supposed to go to the timed function and turn on/off the lights according to the set times, its not doing so at the moment. Please help any pointers?

The other problem is I can access the web page on my laptop but not on my phone pr any other laptop. The ES is stacked on to the UNO and the uno is connected to my laptop via ethernet cable and laptop is connect to a wireless network. The code is below:

I have attached the code

Webserver___Timer_forum.ino (7.59 KB)

Serial.print() statements would help identify the problem. Is the switch being read correctly?

The other problem is I can access the web page on my laptop but not on my phone pr any other laptop. The ES is stacked on to the UNO and the uno is connected to my laptop via ethernet cable and laptop is connect to a wireless network.

How are you accessing the Arduino from the PC?
How is the PC configured, as far as internet sharing?

Why is the Arduino not connected to the router?
How is the router configured, as far as port forwarding?

PaulS:
Serial.print() statements would help identify the problem. Is the switch being read correctly?

The other problem is I can access the web page on my laptop but not on my phone pr any other laptop. The ES is stacked on to the UNO and the uno is connected to my laptop via ethernet cable and laptop is connect to a wireless network.

How are you accessing the Arduino from the PC?
How is the PC configured, as far as internet sharing?

Why is the Arduino not connected to the router?
How is the router configured, as far as port forwarding?

I download the program using the USB cable and I am accessing wifi in my Uni as the internet is provided that way, I am not doing it at home unfortunately.

Thanks for taking time to read

Yes I did try that and the switch is being recognised but does not seem to be going into the interrupt function for the time. Below is what I tried to debug the problem: I have attached it because of the character limit. Thanks again

The forum is amazing

forum_server_timer.ino (10.1 KB)

   while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  
  
  cli();//stop or disable interrupts

  //setting timer1 to interrupt at 1Hz
  TCCR1A = 0;// setting entire TCCR1A register to 0
  TCCR1B = 0;// setting entire TCCR1A register to 0
  TCNT1  = 0;//initialize counter value to 0

    // set compare match register for 1hz increments
  OCR1A = 15624;// = (16*10^6) / (1*1024) - 1 (must be <65536)
  // turn on CTC mode
  TCCR1B |= (1 << WGM12);
  // Set CS10 and CS12 bits for 1024 prescaler
  TCCR1B |= (1 << CS12) | (1 << CS10);  
  // enable timer compare interrupt
  TIMSK1 |= (1 << OCIE1A);

  sei();//enable interrupts
  X10.init(RTS_PIN, DTR_PIN, BIT_DELAY);
  }

99% of this stuff does not belong in the while loop. The body of the while loop is SUPPOSED to be that ;.

Thanks will try this and let you know how it goes.

PaulS:

   while (!Serial) {

; // wait for serial port to connect. Needed for Leonardo only
 
 
  cli();//stop or disable interrupts

//setting timer1 to interrupt at 1Hz
  TCCR1A = 0;// setting entire TCCR1A register to 0
  TCCR1B = 0;// setting entire TCCR1A register to 0
  TCNT1  = 0;//initialize counter value to 0

// set compare match register for 1hz increments
  OCR1A = 15624;// = (1610^6) / (11024) - 1 (must be <65536)
  // turn on CTC mode
  TCCR1B |= (1 << WGM12);
  // Set CS10 and CS12 bits for 1024 prescaler
  TCCR1B |= (1 << CS12) | (1 << CS10); 
  // enable timer compare interrupt
  TIMSK1 |= (1 << OCIE1A);

sei();//enable interrupts
  X10.init(RTS_PIN, DTR_PIN, BIT_DELAY);
  }



99% of this stuff does not belong in the while loop. The body of the while loop is SUPPOSED to be that ;.