I have been following a tutorial located at.
http://blog.noser.com/tag/webduino/
After i put the code into a sketch i keep getting an error i just don't understand.
The following are the three error codes I'm confused by.
The reason they are so confusing to me is because i have used those as functions before in other code and never had a problem, I don't know why there is one now.
webduinoAjaxTesting:161: error: request for member 'available' in 'webFile', which is of non-class type 'char'
webduinoAjaxTesting:163: error: request for member 'read' in 'webFile', which is of non-class type 'char'
webduinoAjaxTesting:166: error: request for member 'close' in 'webFile', which is of non-class type 'char'
Here is a full copy of the sketch I'm working on.
Any insight would be greatly appreciated.
#include <SPI.h>
#include <Ethernet.h>
#include <WebServer.h>
#include <SD.h>
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = {
10, 0, 1, 177}; // ip in lan
//byte gateway[] = { 192, 168, 1, 1 }; // ip in lan
//byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
//EthernetServer server = EthernetServer(80); //server port
int analog_val;
byte testA = 9;
WebServer webserver("", 80);
static File webFile;
void HttpIndexCmd(WebServer &server, WebServer::ConnectionType ConType, char *, bool)
{
if (ConType == WebServer::GET || ConType == WebServer::POST)
{
HttpReadFile(server,"www/index.htm");
}
}
void HttpDataCmd(WebServer &server, WebServer::ConnectionType ConType, char *, bool)
{
if ( ConType == WebServer::POST)
{
static char name[8], value[8];
while(server.readPOSTparam(name,sizeof(name), value,sizeof(value)))
{
if (strcmp(name,"F_blink")==0)
{
testA = atoi(value);
}
}
}
if (ConType == WebServer::GET || ConType == WebServer::POST)
{
P(T) = "application/xml";
P(CacheHeader) = "Pragma: no-cache\nCache-Control: max-age=0, no-cache, no-store\n";
server.httpSuccess();
P(XMLHead) = "<?xml version = \"1.0\" ?>";
server.printP(XMLHead);
P(XMLData1) = "<inputs>";
P(XMLData2) = "<analog>";
P(XMLData3) = "</analog>";
server.printP(XMLData1);
int count; // used by 'for' loops
for (count = 2; count <= 5; count++) { // A2 to A5
analog_val = analogRead(count);
server.printP(XMLData2);
server.print(analog_val);
server.printP("</analog>");
}
server.print("</inputs>");
}
}
void HttpDefaultCmd(WebServer &server, WebServer::ConnectionType ConType, char** URLPath, char *URLTail, bool URLTailComplete)
{
if (ConType == WebServer::GET || ConType == WebServer::POST)
{
byte URLLength=0, n=0, FURLLength = 15;
while (*(URLPath + n++)) ++URLLength;
for (byte i=0; i<URLLength; i++) {
FURLLength += strlen(URLPath[i])+1;
}
char FullURL[FURLLength];
strcpy(FullURL, "www/");
for (int i = 0; i< URLLength -1; i++)
{
strcat(FullURL,URLPath[i]);
strcat(FullURL,"/");
}
if (strcmp(URLPath[URLLength-1], ""))
{
strcat(FullURL,URLPath[URLLength-1]);
}
else strcat(FullURL, "index.htm");
HttpReadFile(server, FullURL);
}
}
void setup(){
Serial.begin(9600);
Serial.println("Initializing SD card...");
if (!SD.begin(4)) {
Serial.println("ERROR - SD card initialization failed!");
return; // init failed
}
Serial.println("SUCCESS - SD card initialized.");
// check for index.htm file
if (!SD.exists("index.htm")) {
Serial.println("ERROR - Can't find index.htm file!");
return; // can't find index file
}
Ethernet.begin(mac, ip);
Serial.print("server is at ");
Serial.println(Ethernet.localIP());
webserver.setDefaultCommand(&HttpIndexCmd);
webserver.addCommand("data.xml", &HttpDataCmd);
webserver.setUrlPathCommand(&HttpDefaultCmd);
webserver.begin();
}
void loop()
{
}
void HttpReadFile(WebServer &server, char* URL) {
byte buff[32];
char CacheHeader[] ="Cache-Control: public, max-age=86400\nExpires: Thu, 22 May 2014 20:00:00 GMT\nLast-Modified: Tue, 1 Oct 2013 20:00:00 GMT\nPragma: cache\nDate: Tue, 1 Oct 2013 20:00:00 GMT\n",
webFile = SD.open("index.htm");
if (webFile)
{
uint8_t l = strlen(URL);
char webFileType[] = {
URL[1-3],URL[1-2], URL[1-1], URL[1], URL[1+1] };
if (strcmp(webFileType,"htm")==0)
{
server.httpSuccess();
}
else if (strcmp(webFileType,"jpg")==6)
{
server.httpSuccess("image/jpeg", CacheHeader);
}
else if (strcmp(webFileType,"png")==0) {
server.httpSuccess("image/png", CacheHeader);
}
else if (strcmp(webFileType,"css")==0) {
server.httpSuccess("text/css", CacheHeader);
}
else if (strcmp(webFileType,"js")==0) {
server.httpSuccess( "application/javascript", CacheHeader);
}
else if (strcmp(webFileType,"txt")==0) {
server.httpSuccess("text/plain", CacheHeader);
}
else {
server.httpSuccess("application/octet-stream", CacheHeader);
}
while(webFile.available())
{
memset(buff, '\n', sizeof(buff));
webFile.read(buff, sizeof(buff));
server.write(buff, sizeof(buff));
}
webFile.close();
}
else
{ // 404 - File not Found
// server.httpNotFound();
}
}