hallo weer een vraagje.
ik wil via mijn webserver met htm index pagina via een button een binaire code zenden naar de data pin (11)van mijn 433mhz zender.
ik heb 2 voorbeelden van buttons en het idee hoe ik dacht dat het moest.
maar ik krijg het niet voor elkaar.
button 1 (html)(mijn voorkeur "http://www.engineerathome.com/")
<span>Lamp TV</span>
<div class="bulb"></div>
<p>
<a href="?1=03" class="">Aan</a>
<a href="?1=03" class="">Uit</a>
</p>
.ino code van engineerathome (deze ino code krijg ik niet aan de praat hij komt niet voorbij : )(
if (c == '\n' && currentLineIsBlank) {
if (page == '1') {
) waardoor ik de hele hml site niet eens te zien krijg maar de 403 error.
/********************************************************************************************/
/* */
/* Domotica Web Interface door EngineerAtHome.com */
/* http://www.engineerathome.com/elektronica/maak+een+web+interface+voor+je+arduino/26 */
/* */
/********************************************************************************************/
#include <SPI.h>
#include <Ethernet.h>
SdFat SD; // SD instance voor lib
SdFile myFile; // file variabele voor sd-library
char buffer; // SD read buffer
char page; // nummer van aangeroepen pagina
int command; // nummer van aangeroepen commando
boolean Status = false; // huisstatus false = Afwezig, true = Aanwezig
byte Switches[15]; // waardes van de verschillende switches
byte mac[] = {0xAE, 0x5D, 0x77, 0xDF, 0xFA, 0xDD};
IPAddress ip(10,0,0,30);
IPAddress gateway(10,0,0,1);
IPAddress subnet(255,255,255,0);
EthernetServer server(80);
EthernetClient client;
void setup() {
pinMode(10, OUTPUT); // ethernet shield uitschakelen
digitalWrite(10, HIGH); // zodat SPI bus vrijkomt
delay(1000);
SD.begin(4, SPI_FULL_SPEED); // om sd-kaart te initialiseren
Ethernet.begin(mac, ip, gateway, gateway, subnet); // start ethernet shield
server.begin(); // start server
}
void loop() {
// listen for incoming clients
client = server.available();
boolean currentLineIsFirst = true;
if (client) {
// an http request ends with a blank line
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
// if you've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so you can send a reply
if (c == '\n' && currentLineIsBlank) {
if (page == '1') {
// print contents of html-page
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
myFile.open("home.htm", O_READ);
Read_File_Upto_FS();
// huismodus
if (Status) {
client.print(F("aan"));
Read_File_Upto_FS();
client.print(F("uit"));
}
else {
client.print(F("uit"));
Read_File_Upto_FS();
client.print(F("aan"));
}
// switches
for (int z = 0; z <= 5; z++) {
Read_File_Upto_FS();
if (Switches[z] == 1) {
client.print(F("aan"));
Read_File_Upto_FS();
client.print(F("uit"));
}
else {
client.print(F("uit"));
Read_File_Upto_FS();
client.print(F("aan"));
}
}
// blijf Read_File_Upto_FS() gebruiken totdat alle FS-posities in je html-pagina zijn gevuld...
Read_File_Upto_End();
myFile.close();
}
else {
client.println("HTTP/1.1 403 FORBIDDEN");
client.println("Content-Type: text/html");
client.println();
client.print("<h1>403 FORBIDDEN</h1>");
}
page = 0; // reset page variabele
break;
}
if (c == '\n') {
// you're starting a new line
currentLineIsBlank = true;
currentLineIsFirst = false;
}
else if (c != '\r') {
// you've gotten a character on the current line
currentLineIsBlank = false;
}
if (currentLineIsFirst && c == '?') {
// found ? so read pagenumber
page = client.read();
}
if (currentLineIsFirst && c == '=') {
// found = so read commandnumber
command = client.read() - 48; // convert char to int!!! 0=0 1=1 2=2 a=49 b=50 c=51
command = (10 * command) + (client.read() - 48); // convert char to int!!! 0=0 1=1 2=2 a=49 b=50 c=51
}
}
}
// give the web browser time to receive the data
delay(1);
// close the connection:
client.stop();
}
}
void Read_File_Upto_FS() {
while ((buffer = myFile.read()) != 28) {
client.print((char)buffer);
}
}
void Read_File_Upto_End() {
while ((buffer = myFile.read()) >= 0) {
client.print((char)buffer);
}
}
void Skip_File_Upto_FS() {
while ((buffer = myFile.read()) != 28) {
// nothing
}
}
button 2 (html)
<button type="button" id="LED3" onClick="GetButton1()">LED 3 is OFF (D8)</button>
.ino code ( //mySwitch.send dacht ik dat er moest staan i.p.v. de digital write maar dan loopt alles vast door 100 tx rx gebruik. terwijl mySwitch als pin 10 0f 11 aangegeven staat.)
// LED 3 (pin 8)
if (StrContains(HTTP_req, "LED3=1")) {
LED_state[2] = 1; // save LED state
digitalWrite(8, HIGH);//mySwitch.send("010100000000000000010101");
}
else if (StrContains(HTTP_req, "LED3=0")) {
LED_state[2] = 0; // save LED state
digitalWrite(8, LOW);//mySwitch.send("010100000000000000010100");
}