[Emergency] Arduino Webserver Help.....

"Entry lights" button is named pin8 worldwide.
"Entry lights2" can be created, considering how the second toggle button. How to control the second button can be connected to the analog input. (PIN9 should work.)

#include <SPI.h>
#include <Ethernet.h>
#include <OneButton.h>
#include <Timer.h>
#include <WebServer.h>

// IO pins
// Pins for the expand module
// Pins for the relays
const int relayAPin = 8;
const int relayBPin = 9;

// Set up the button. I'm connecting pin to +5V when button pressed.
// I *think* that means the active flag needs to be false.
OneButton lightButton(A0, false);
long buttonDelay = 0;

// Ethernet constants
static uint8_t mac[] = { 0x06, 0x17, 0x17, 0x17, 0x17, 0x17 };
static uint8_t ip[] = { 192, 168, 1, 200 };
WebServer webserver ("", 5555);

// HTTP variables
char credentials[] = "ZWZlOjE1MTU=";
const int attribLen = 8; // Buffer length for URL attributes.
const int valueLen = 8; // Buffer length for URL values.

int externLightState = LOW; // State of external lights
// Values to write to shift register to turn power points on

// Values to write to shift register to turn power points off


// Timer variables
Timer timer;

// Yes, I put a web page here.
P(index_htm) = "<!DOCTYPE html>"
  "<html>"
  "<head>"
  "<title>Remote control</title>"
  "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">"
  "<link rel=\"stylesheet\" href=\"http://code.jquery.com/mobile/1.1.1/jquery.mobile-1.1.1.min.css\" />"
  "<script src=\"http://code.jquery.com/jquery-1.7.1.min.js\"></script>"
  "<script src=\"http://code.jquery.com/mobile/1.1.1/jquery.mobile-1.1.1.min.js\"></script>"
  "</head>"
  "<body>"
  "<div data-role=\"page\" id=\"page1\" data-theme=\"a\">"
  "<div data-role=\"header\">"
  "<h3>Remote Control</h3>"
  "</div>"
  "<div data-role=\"content\" style=\"padding: 15px\">"
  "<div class=\"ui-grid-b\">"
  "<div class=\"ui-block-a\">"
  "</div>"
  "<div class=\"ui-block-b\">"
  "<div data-role=\"fieldcontain\">"
  "<fieldset data-role=\"controlgroup\">"
  "<label for=\"extern\">Entry lights</label>"
  "<select name=\"extern\" id=\"extern\" data-theme=\"\" data-role=\"slider\">"
  "<option value=\"off\">Off</option>"
  "<option value=\"on\">On</option>"
  "</select>"
  "</fieldset>"
  "</div>"
  "</div>"
  "</div>"
  "</div>"
  "</div>"
  "<script>"
  "function updateControls() {"
  "$.getJSON(\"/status.json\", function(json) {"
  "$.each(json, function(key, value) {"
  "$(\"#\"+key).val(value).slider(\"refresh\");"
  "});"
  "});"
  "}"
  "$('select').bind('change', function(event) {"
  "element = event.target.id;"
  "if (element.substr(0, 6) == \"outlet\") {"
  "eleid = element.substr(6, 1);"
  "} else {"
  "eleid = 0;"
  "}"
  "command = event.target.value;"
  "$.get('/cmd', { 'eleid' : eleid, 'cmd' : command });"
  "});"
  "$('#page1').bind('pageinit', updateControls);"
  "</script>"
  "</body>"
  "</html>";

boolean authorise(WebServer &server) {
  if (server.checkCredentials(credentials)) {
    server.httpSuccess();
    return true;
  } else {
    server.httpUnauthorized();
    return false;
  }
}

void sendStatus(WebServer &server) {
  server.print("{ \"extern\" : ");
  if (externLightState) {
    server.print("\"on\"");
  } else {
    server.print("\"off\"");
  }
    
  server.println(" }");
}

void statusCmd(WebServer &server, WebServer::ConnectionType type,
	       char *, bool) {
  if (authorise(server)) {
    sendStatus(server);
  }
}

void defaultPage(WebServer &server, WebServer::ConnectionType type,
		 char *, bool) {
  if (authorise(server)) {
    server.printP(index_htm);
  }
}
 
void cmdParser(WebServer &server, WebServer::ConnectionType type,
	       char *url_tail, bool tail_complete) {
  if (authorise(server)) {
    if (type != WebServer::GET) {
      return;
    }

    URLPARAM_RESULT rc;
    char name[attribLen];
    char value[valueLen];
    int eleid;
    bool cmd;

    while (strlen(url_tail)) {
      rc = server.nextURLparam(&url_tail, name, attribLen, value, valueLen);
      if (rc != URLPARAM_EOS) {
	if (strcmp(name, "eleid") == 0) {
	  eleid = atoi(value);
	} else if (strcmp(name, "cmd") == 0) {
	  if (strcmp(value, "on") == 0) {
	    cmd=true;
	  } else {
	    cmd=false;
	  }
	} else if (strcmp(name, "timer") == 0) {
	  long timeDelay = atol(value) * 1000;
	  timer.after(timeDelay, externTimerCallBack);
	}
      }
    }

    if (eleid == 0) {
      if (cmd) {
	externlights(HIGH);
      } else {
	externlights(LOW);
      }
    } else {
      powerswitch(eleid, cmd);
    }
  }
  sendStatus(server);
}

// Timer callback that will
// turn off extern outputs.
void externTimerCallBack() {
  externlights(LOW);
}

void externlights(int state) {
  digitalWrite(relayAPin, state);
  digitalWrite(relayBPin, state);
  externLightState = state;
}

// Timer callback that will send 0 to shift register,
// "releasing" the button we pushed.
void powerTimerCallBack() {
  sendShiftCmd(0);
}

void powerswitch(int outlet, bool state) {
  timer.after(500, powerTimerCallBack);
}

void sendShiftCmd(int cmd) {}

// On single click, turn the lights on
// with a five-minute timer.
void singleClickCallback() {
  if (externLightState) {
    // turn lights off if on
    externlights(LOW);
  } else {
    externlights(HIGH);
    timer.after(300000, externTimerCallBack);
  }
}

// On double click, turn the lights on
// indefinitely.
void doubleClickCallback() {
  if (externLightState) {
    // turn lights off if on
    externlights(LOW);
  } else {
    externlights(HIGH);
  }
}

void setup() {

  pinMode(relayAPin, OUTPUT);
  pinMode(relayBPin, OUTPUT);

  // Flush the expand module
  sendShiftCmd(0);

  // Set up button callbacks
  lightButton.attachClick(&singleClickCallback);
  lightButton.attachDoubleClick(&doubleClickCallback);

  // Initialise the Ethernet adapter
  Ethernet.begin(mac, ip);

  // Initialise the web server
  webserver.setDefaultCommand(&defaultPage);
  webserver.addCommand("index.html", &defaultPage);
  webserver.addCommand("cmd", &cmdParser);
  webserver.addCommand("status.json", &statusCmd);
  webserver.begin();
}

void loop() {
  char buff[64];
  int len = 64;
  webserver.processConnection(buff, &len);
  timer.update();
  // Only check button state periodically
  if (millis() - buttonDelay > 50) {
    lightButton.tick();
    buttonDelay = millis();
  }
}

It's hard to understand your description of the problem. From what I can see, there is a web server in your sketch which controls two output pins (but does the same thing to both of them). However, your question is not about the web server, it is only how to read the state of a physical switch and do (something) with it. You already have one switch connected to A0 and I suppose you want to connect a second switch.

Is that correct?

What is the emergency, exactly?

How to control the second button can be connected to the analog input.

What does that mean?

What is the emergency, exactly?

Quote
How to control the second button can be connected to the analog input.

What does that mean?

yeah right, took care of some of the key. sliderstatus of all page don't updating Json :frowning:

DimmerDeneme.ino (17.3 KB)

sw33tking:
yeah right, took care of some of the key. sliderstatus of all page don't updating Json :frowning:

Absolutely.

why other page don't working script "$.getJSON(\"/status.json\", function(json) {"

why other page don't working script
Code:

"$.getJSON("/status.json", function(json) {"

Couldn't agree more.