Перенос HTML'a на SD
- Войдите на сайт для отправки комментариев
Втр, 02/05/2017 - 11:59
Приветсвтую!
Необходима конусльтация знатоков. Есть код, взятый на просторах интернета ( при необходимости укажу источник)
#include <SPI.h>
#include <Ethernet.h>
#include <avr/pgmspace.h>
#include <EEPROM.h>
char buffer[110];
prog_char htmla0[] PROGMEM = "<html><body marginwidth=\"0\" marginheight=\"0\" leftmargin=\"0\" style=\"margin: 0; padding: 0;\"><table";
prog_char htmla1[] PROGMEM = " bgcolor=\"#999999\" border=\"0\" width=\"100%\" cellpadding=\"1\" style=\"font-family:Verdana;color:#fff";
prog_char htmla2[] PROGMEM = "fff;font-size:12px;\"><tr><td>  Arduino Ethernet Shield setup page</td></tr></table><br><table border";
prog_char htmla3[] PROGMEM = "=\"0\" style=\"color:#00979d;font-size:24px;font-family:Verdana\"><tr VALIGN=\"baseline\"><td width=110px";
prog_char htmla4[] PROGMEM = "></td><td width=135px><strong>ARDUINO</strong></td><td STYLE=\"font-size:28px;font-family:Courier New;\">";
prog_char htmla5[] PROGMEM = "</td></tr></table><br><table bgcolor=\"#15a8ad\" border=\"0\" width=\"100%\" cellpadding=\"3\" style=\"";
prog_char htmla6[] PROGMEM = "font-size:12px;color:#ffffff;font-family:Verdana;\"><tr><td width=110px></td><td>Current network settin";
prog_char htmla7[] PROGMEM = "gs</td></tr></table><br><table border=\"0\" style=\"color:#999999;\"><tr><td width=110px>TYPE:</td><td>";
PROGMEM const char *string_table1[] = {htmla0, htmla1, htmla2, htmla3, htmla4, htmla5, htmla6, htmla7};
prog_char htmlb0[] PROGMEM = "</td></tr><tr><td width=110px>MAC:</td><td>";
prog_char htmlb1[] PROGMEM = "</td></tr><tr><td width=110px>IP:</td><td>";
prog_char htmlb2[] PROGMEM = "</td></tr><tr><td width=110px>GW:</td><td>";
prog_char htmlb3[] PROGMEM = "</td></tr><tr><td width=110px>MASK:</td><td>";
prog_char htmlb4[] PROGMEM = "</td></tr><tr><td width=110px>Shield Name:</td><td>";
PROGMEM const char *string_table2[] = {htmlb0, htmlb1, htmlb2, htmlb3, htmlb4};
prog_char htmlc0[] PROGMEM = "</td></tr></table><br><table bgcolor=\"#15a8ad\" border=\"0\" width=\"100%\" cellpadding=\"3\" ";
prog_char htmlc1[] PROGMEM = "style=\"font-size:12px;color:#ffffff;font-family:Verdana;\"><tr><td width=110px></td><td>Networ";
prog_char htmlc2[] PROGMEM = "k Setup</td></tr></table><br><table border=\"0\"><form><tr><td width=110px>TYPE:</td><td><selec";
prog_char htmlc3[] PROGMEM = "t name=\"type\"><option>static</option><option>dhcp</option></select></td></tr><tr><td width=110";
prog_char htmlc4[] PROGMEM = "px>MAC:</td><td><input type=\"text\" size=\"1\" maxlength=\"2\" name=\"maci1\">:<input type=\"te";
prog_char htmlc5[] PROGMEM = "xt\" size=\"1\" maxlength=\"2\" name=\"maci2\">:<input type=\"text\" size=\"1\" maxlength=\"2\" ";
prog_char htmlc6[] PROGMEM = "name=\"maci3\">:<input type=\"text\" size=\"1\" maxlength=\"2\" name=\"maci4\">:<input type=\"te";
prog_char htmlc7[] PROGMEM = "xt\" size=\"1\" maxlength=\"2\" name=\"maci5\">:<input type=\"text\" size=\"1\" maxlength=\"2\" ";
PROGMEM const char *string_table3[] = {htmlc0, htmlc1, htmlc2, htmlc3, htmlc4, htmlc5, htmlc6, htmlc7};
prog_char htmld0[] PROGMEM = "name=\"maci6\"></td></tr><tr><td width=110px>IP:</td><td><input type=\"text\" size=\"1\" maxle";
prog_char htmld1[] PROGMEM = "ngth=\"3\" name=\"ipi1\">.<input type=\"text\" size=\"1\" maxlength=\"3\" name=\"ipi2\">.<input";
prog_char htmld2[] PROGMEM = " type=\"text\" size=\"1\" maxlength=\"3\" name=\"ipi3\">.<input type=\"text\" size=\"1\" maxlen";
prog_char htmld3[] PROGMEM = "gth=\"3\" name=\"ipi4\"></td></tr><tr><td width=110px>GW:</td><td><input type=\"text\" size=\"1";
prog_char htmld4[] PROGMEM = "\" maxlength=\"3\" name=\"gwi1\">.<input type=\"text\" size=\"1\" maxlength=\"3\" name=\"gwi2\"";
prog_char htmld5[] PROGMEM = ">.<input type=\"text\" size=\"1\" maxlength=\"2\" name=\"gwi3\">.<input type=\"text\" size=\"1";
prog_char htmld6[] PROGMEM = "\" maxlength=\"3\" name=\"gwi4\"></td></tr><tr><td width=110px>MASK:</td><td><input type=\"tex";
prog_char htmld7[] PROGMEM = "t\" size=\"1\" maxlength=\"3\" name=\"subi1\">.<input type=\"text\" size=\"1\" maxlength=\"3\"";
PROGMEM const char *string_table4[] = {htmld0, htmld1, htmld2, htmld3, htmld4, htmld5, htmld6, htmld7};
prog_char htmle0[] PROGMEM = " name=\"subi2\">.<input type=\"text\" size=\"1\" maxlength=\"3\" name=\"subi3\">.<input type=\"";
prog_char htmle1[] PROGMEM = "text\" size=\"1\" maxlength=\"3\" name=\"subi4\"></td></tr><tr><td width=110px>Shield Name:</td";
prog_char htmle2[] PROGMEM = "><td><input type=\"text\" size=\"25\" name=\"name\"></td></tr><tr><td width=110px></td><td><inp";
prog_char htmle3[] PROGMEM = "ut type=\"submit\" value=\"SUBMIT\"></form></td></tr></table><br><table bgcolor=\"#15a8ad\" bor";
prog_char htmle4[] PROGMEM = "der=\"0\" width=\"100%\" cellpadding=\"3\" style=\"font-size:12px;color:#ffffff;font-family:Ver";
prog_char htmle5[] PROGMEM = "dana;\"><tr><td width=110px></td><td>Reset all settings to predefined values</td></tr></table><";
prog_char htmle6[] PROGMEM = "br><table border=\"0\"><form><tr><td width=110px></td><td><input type=\"hidden\" name=\"reset\"";
prog_char htmle7[] PROGMEM = " value=\"1\"><input type=\"submit\" value=\"RESET\"></form></td></tr></table><br></body></html>";
PROGMEM const char *string_table5[] = {htmle0, htmle1, htmle2, htmle3, htmle4, htmle5, htmle6, htmle7};
const byte ID_ADDR = 0; //the EEPROM adress used to store the ID (to check if sketch already has ran)
const byte MAC_ADDR1 = 1; //the EEPROM adress used to store the first part of the MAC ADDRESS
const byte MAC_ADDR2 = 2; //the EEPROM adress used to store the second part of the MAC ADDRESS
const byte MAC_ADDR3 = 3; //the EEPROM adress used to store the thirth part of the MAC ADDRESS
const byte MAC_ADDR4 = 4; //the EEPROM adress used to store the fourth part of the MAC ADDRESS
const byte MAC_ADDR5 = 5; //the EEPROM adress used to store the fifth part of the MAC ADDRESS
const byte MAC_ADDR6 = 6; //the EEPROM adress used to store the sixth part of the MAC ADDRESS
const byte IP_ADDR1 = 7; //the EEPROM adress used to store the first part of the IP-address
const byte IP_ADDR2 = 8; //the EEPROM adress used to store the second part of the IP-address
const byte IP_ADDR3 = 9; //the EEPROM adress used to store the thirth part of the IP-address
const byte IP_ADDR4 = 10; //the EEPROM adress used to store the fourth part of the IP-address
const byte GW_ADDR1 = 11; //the EEPROM adress used to store the first part of the GATEWAY
const byte GW_ADDR2 = 12; //the EEPROM adress used to store the second part of the GATEWAY
const byte GW_ADDR3 = 13; //the EEPROM adress used to store the thirth part of the GATEWAY
const byte GW_ADDR4 = 14; //the EEPROM adress used to store the fourth part of the GATEWAY
const byte SUB_ADDR1 = 15; //the EEPROM adress used to store the first part of the SUBNETMASK
const byte SUB_ADDR2 = 16; //the EEPROM adress used to store the second part of the SUBNETMASK
const byte SUB_ADDR3 = 17; //the EEPROM adress used to store the thirth part of the SUBNETMASK
const byte SUB_ADDR4 = 18; //the EEPROM adress used to store the fourth part of the SUBNETMASK
const byte TYPE_ADDR = 19; //the EEPROM adress used to store if using STATIC = 1 or DHCP = 2
const byte ID = 0x97; //used to identify if valid date in EEPROM the "know" bit, if this is written in EEPROM the sketch has ran before
byte MAC1 = 0xDE; //the first part of the MAC ADDRESS
byte MAC2 = 0xAD; //the second part of the MAC ADDRESS
byte MAC3 = 0xBE; //the thirth part of the MAC ADDRESS
byte MAC4 = 0xEF; //the fourth part of the MAC ADDRESS
byte MAC5 = 0xFE; //the fifth part of the MAC ADDRESS
byte MAC6 = 0xED; //the sixth part of the MAC ADDRESS
byte IP1 = 192;//the first part of the IP-address
byte IP2 = 168; //the second part of the IP-address
byte IP3 = 2; //the thirth part of the IP-address
byte IP4 = 250; //the fourth part of the IP-address
byte GW1 = 192; //the first part of the GATEWAY
byte GW2 = 168; //the second part of the GATEWAY
byte GW3 = 2; //the thirth part of the GATEWAY
byte GW4 = 1; //the fourth part of the GATEWAY
byte SUB1 = 255; //first part of the SUBNETMASK
byte SUB2 = 255; //the second part of the SUBNETMASK
byte SUB3 = 255; //the thirth part of the SUBNETMASK
byte SUB4 = 0; //the fourth part of the SUBNETMASK
byte TYPE = 1; //the type is set to 1 = static
byte mac[] = { MAC1, MAC2, MAC3, MAC4, MAC5, MAC6};
byte mac_addr[] = { MAC_ADDR1, MAC_ADDR2, MAC_ADDR3, MAC_ADDR4, MAC_ADDR5, MAC_ADDR6};
byte ip[] = { IP1, IP2, IP3, IP4};
byte ip_addr[] = { IP_ADDR1, IP_ADDR2, IP_ADDR3, IP_ADDR4};
byte gateway[] = { GW1, GW2, GW3, GW4};
byte gw_addr[] = { GW_ADDR1, GW_ADDR2, GW_ADDR3, GW_ADDR4};
byte subnet[] = { SUB1, SUB2, SUB3, SUB4};
byte sub_addr[] = { SUB_ADDR1, SUB_ADDR2, SUB_ADDR3, SUB_ADDR4};
EthernetServer server(80);
void setup()
{
Serial.begin(9600); //for debuging on serial
ShieldSetup();
Ethernet.begin(mac, ip, gateway, subnet);
server.begin();
}
void ShieldSetup()
{
byte id = EEPROM.read(ID_ADDR); // set id to the the value from EEPROM address ID_ADDR
if (id == ID) // check if that value = ID (if it does, this sketch has been ran before)
{
Serial.print("ran before"); //just for debuging
byte type = EEPROM.read(TYPE_ADDR); // set type to the value from EEPROM address TYPE_ADDR
if (type == 1) // if type = 1 (static) then read mac, ip, gw and sub from EEPROM en set to use
{
ShieldRead();
}
else // if type is not = 1 then use MAC from preset and get ip, gw, sub from DHCP en set to use
{
MAC1 = EEPROM.read(MAC_ADDR1);
MAC2 = EEPROM.read(MAC_ADDR2);
MAC3 = EEPROM.read(MAC_ADDR3);
MAC4 = EEPROM.read(MAC_ADDR4);
MAC5 = EEPROM.read(MAC_ADDR5);
MAC6 = EEPROM.read(MAC_ADDR6);
}
}
else // the value doesn't = ID (this sketch runs for the first time)
{
Serial.print("didn't ran before"); //just for debuging
ShieldWrite();
ShieldRead();
}
}
void ShieldWrite()
{
for (int i = 0 ; i < 6; i++)
{
EEPROM.write(mac[i],mac_addr[i]);
}
for (int i = 0 ; i < 4; i++)
{
EEPROM.write(ip[i],ip_addr[i]);
}
for (int i = 0 ; i < 4; i++)
{
EEPROM.write(gateway[i],gw_addr[i]);
}
for (int i = 0 ; i < 4; i++)
{
EEPROM.write(subnet[i],sub_addr[i]);
}
EEPROM.write(TYPE_ADDR,TYPE);
EEPROM.write(ID_ADDR, ID);
}
void ShieldRead()
{
MAC1 = EEPROM.read(MAC_ADDR1);
MAC2 = EEPROM.read(MAC_ADDR2);
MAC3 = EEPROM.read(MAC_ADDR3);
MAC4 = EEPROM.read(MAC_ADDR4);
MAC5 = EEPROM.read(MAC_ADDR5);
MAC6 = EEPROM.read(MAC_ADDR6);
IP1 = EEPROM.read(IP_ADDR1);
IP1 = EEPROM.read(IP_ADDR2);
IP1 = EEPROM.read(IP_ADDR3);
IP1 = EEPROM.read(IP_ADDR4);
GW1 = EEPROM.read(GW_ADDR1);
GW1 = EEPROM.read(GW_ADDR2);
GW1 = EEPROM.read(GW_ADDR3);
GW1 = EEPROM.read(GW_ADDR4);
SUB1 = EEPROM.read(SUB_ADDR1);
SUB1 = EEPROM.read(SUB_ADDR2);
SUB1 = EEPROM.read(SUB_ADDR3);
SUB1 = EEPROM.read(SUB_ADDR4);
}
void loop()
{
EthernetClient client = server.available();
// If someone connects to the server...
if (client) {
// Create a variable to hold whether or not we have received a blank
// line from the web browser
boolean current_line_is_blank = true;
// Run the following code as long as the client remains connected
// Learn more about client.connected()
while (client.connected()) {
// If the client has sent us some data...
// Learn more about client.available()
if (client.available()) {
// Keep the last letter of whatever they sent us
// Learn more about client.read()
char c = client.read();
// If we've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so we can send a reply
if (c == 'n' && current_line_is_blank) {
// Send a basic HTTP response header (the blank line at the end
// is required). Learn more about client.println()
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
for (int i = 0; i < 5; i++)
{
strcpy_P(buffer, (char*)pgm_read_word(&(string_table1[i])));
client.print( buffer );
}
client.print("Shield Name"); // shieldname still to define with EEPROM (not done yet, so now just pure html))
for (int i = 5; i < 8; i++)
{
strcpy_P(buffer, (char*)pgm_read_word(&(string_table1[i])));
client.print( buffer );
}
if (TYPE == 1)
{
client.print("STATIC");
}
else
{
if (TYPE == 2)
{
client.print("DHCP");
}
else
{
client.print("UNKNOWN");
}
}
strcpy_P(buffer, (char*)pgm_read_word(&(string_table2[0])));
client.print( buffer );
client.print(mac[0],HEX);
for (int i= 1; i < 6; i++)
{
client.print(":");
client.print(mac[i],HEX);
}
strcpy_P(buffer, (char*)pgm_read_word(&(string_table2[1])));
client.print( buffer );
client.print(ip[0],DEC);
for (int i= 1; i < 4; i++)
{
client.print(".");
client.print(ip[i],DEC);
}
strcpy_P(buffer, (char*)pgm_read_word(&(string_table2[2])));
client.print( buffer );
client.print(gateway[0],DEC);
for (int i= 1; i < 4; i++)
{
client.print(".");
client.print(gateway[i],DEC);
}
strcpy_P(buffer, (char*)pgm_read_word(&(string_table2[3])));
client.print( buffer );
client.print(subnet[0],DEC);
for (int i= 1; i < 4; i++)
{
client.print(".");
client.print(subnet[i],DEC);
}
strcpy_P(buffer, (char*)pgm_read_word(&(string_table2[4])));
client.print( buffer );
client.print("Shield Name"); // shieldname still to define with EEPROM (not done yet, so now just pure html))
for (int i = 0; i < 8; i++)
{
strcpy_P(buffer, (char*)pgm_read_word(&(string_table3[i])));
client.print( buffer );
}
for (int i = 0; i < 8; i++)
{
strcpy_P(buffer, (char*)pgm_read_word(&(string_table4[i])));
client.print( buffer );
}
for (int i = 0; i < 8; i++)
{
strcpy_P(buffer, (char*)pgm_read_word(&(string_table5[i])));
client.print( buffer );
}
client.print("free test SRAM = ");
client.print(availableMemory());
client.print(" / SRAM used = ");
client.print(2048-availableMemory());
break;
}
// If we received a new line character from the client ...
if (c == 'n') {
// Track that the line is blank
current_line_is_blank = true;
// If we don't receive a new line character and don't receive an r
}
else if (c != 'r') {
// Track that we we got some data
current_line_is_blank = false;
}
}
}
// Give the client some time to receive the page
// Learn more about delay()
delay(1);
// Close the connection to the client now that we are finished
// Learn more about client.stop()
client.stop();
}
}
int availableMemory()
{
int size = 2048;
byte *buf;
while ((buf = (byte *) malloc(--size)) == NULL);
free(buf);
return size;
}
Проблема следующая: как перенести функционал таблицы в HTML не потеряв работоспсобности?

