I compiled this sketch and have no errors.
The web buttons appear on the web page and when clicked they do send a code but I cannot figure how to link
the button to the action
I am requesting some basic code /help on how to read the button form displayed on the web server page to turn on digitalwrite pin
Once someone shows me how to do one button , i can work from there....
Thanks,
Joe
/* jb modified - Web_Authentication.ino - */
/* you can change the authentication realm by defining
* WEBDUINO_AUTH_REALM before including WebServer.h */
#define WEBDUINO_AUTH_REALM "Weduino Authentication Example"
#include <Arduino.h>
#include <SPI.h>
#include <Ethernet.h>
#include <WebServer.h>
static uint8_t mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
static uint8_t ip[] = {
192, 168, 1, 136 };
String readString;
boolean tog1 = false; //rf1 on
boolean tog2 = true; //rf2 off
//-----------------------------------------------------------------------
/* This creates an instance of the webserver. By specifying a prefix
* of "", all pages will be at the root of the server. */
#define PREFIX ""
WebServer webserver(PREFIX, 98);
void defaultCmd(WebServer &server, WebServer::ConnectionType type, char *, bool)
{
server.httpSuccess();
if (type != WebServer::HEAD)
{
P(helloMsg) = "<h1>First entry page -Hello, World!</h1><a href=\"private.html\">ACCESS ADMIN CONTROL page</a>";
server.printP(helloMsg);
}
}
void privateCmd(WebServer &server, WebServer::ConnectionType type, char *, bool)
{
/* if the user has requested this page using the following credentials
* username = admin
* password = joe
* display a page saying "Hello User"
*
* the credentials have to be concatenated with a colon like
* username:password
* and encoded using Base64 - this should be done outside of your Arduino
* to be easy on your resources
*
* in other words: "dXNlcjp1c2Vy" is the Base64 representation of "admin:joe"
*
* if you need to change the username/password dynamically please search
* the web for a Base64 library */
if (server.checkCredentials("YWRtaW46am9l"))
{
server.httpSuccess();
if (type != WebServer::HEAD)
{
Serial.println(readString);
// HTML FORM BUTTONS TO TURN ON / OFF ITEM
P(background) = "<body style=background-color:BLACK>"; //set background to BLACK
P(helloMsg) = "<center><font color=’green’> <h1>HOME - INTERNET -- CONTROL </h1></font></center>";
P(FORMOPEN) = "<form method=get name=LED>";
P(button1) = "<center><button name=tog1 value=1 type=submit style=font-weight:bold;color:GREEN;height:70px;width:145px>AC POWER RF FAN On</button>";
P(button2) = "<button name=tog2 value=1 type=submit style=font-weight:bold;color:red;height:70px;width:145px>AC POWER RF FAN Off</button>";
P(FORMCLOSE) = "</form>";
// DISPLAY layout - print items to web page:
server.printP(background);
server.printP(helloMsg);
server.printP(FORMOPEN);
server.printP(button1);
server.printP(button2);
}
}
else
{
// send a 401 error back causing the web browser to prompt the user for credentials
server.httpUnauthorized();
}
}
void setup()
{
Ethernet.begin(mac, ip);
webserver.setDefaultCommand(&defaultCmd);
webserver.addCommand("index.html", &defaultCmd); // FIRST PAGE
webserver.addCommand("private.html", &privateCmd); // ADMIN CONTROL - REQUIRES ACCESS
webserver.begin();
pinMode(5, OUTPUT); //pin selected to control pwr1 ON
pinMode(6, OUTPUT); //pin selected to control pwr1 off
}
void loop()
{
char buff[64];
int len = 64;
// ===============================================================================================
// - PROBLEM AREA - HOW DO GET TOG1 / TOG 2 - TO BE READ - WHEN A WEB PAGE BUTTON IS CLICKED / SELECTED ????
//-----------------------------------------------------------------------------------------------------------------------------------------
if(readString.indexOf("tog1") >0)// on for PWR MODULE ID 1 control
{
digitalWrite(5, HIGH);
tog1 = true;
delay(500);
digitalWrite(5, LOW);
}
if(readString.indexOf("tog2") >0)// off PWR MODULE ID 1 control
{
digitalWrite(6, HIGH);
delay(500);
digitalWrite(6, LOW);
tog1 = false;
}
//=====================================================================================================
// process incoming connections one at a time forever /
webserver.processConnection(buff, &len);
}