Okay so I'm new to C and I'm really struggling on how to get my head around this.
I want to keep all my webserver code neat and out of the main script so I've started creating a library, and I realise it has heaps of errors and is allover the place but would
really appreciate some help on how I should be structuring this.
main script (WebPages is my new library, could be named better but trying to work this out first):
#include "WebPages.h"
#include "SPI.h"
#include "Ethernet.h"
#include "WebServer.h"
WebPages server;
void setup()
{
server.setup();
}
void loop()
{
server.servProcess();
}
WebPages.h
#ifndef WebPages_h
#define WebPages_h
#include "WebPages.h"
#include "SPI.h"
#include "Ethernet.h"
#include "WebServer.h"
#include "Arduino.h"
class WebPages
{
public:
WebPages();
void setup();
void servProcess();
void defaultCmd(WebServer &server, WebServer::ConnectionType type, char *url_tail, bool tail_complete);
private:
};
#endif
WebPages.ccp
#include "WebPages.h"
#include "SPI.h"
#include "Ethernet.h"
#include "WebServer.h"
#include "Arduino.h"
template<class T>
inline Print &operator <<(Print &obj, T arg)
{ obj.print(arg); return obj; }
static uint8_t mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
static uint8_t ip[] = { 192, 168, 1, 210 };
#define PREFIX ""
WebServer webserver(PREFIX, 80);
void defaultCmd(WebServer &server, WebServer::ConnectionType type, char *url_tail, bool tail_complete)
{
P(htmlHead) =
"<html>"
"<head>"
"<title>Arduino Web Server</title>"
"<style type=\"text/css\">"
"BODY { font-family: sans-serif }"
"H1 { font-size: 14pt; text-decoration: underline }"
"P { font-size: 10pt; }"
"</style>"
"</head>"
"<body>"
"TEST"
"</body>";
server.httpSuccess();
server.printP(htmlHead);
}
WebPages::WebPages()
{
//created
}
void WebPages::setup()
{
Ethernet.begin(mac, ip);
webserver.begin();
webserver.setDefaultCommand(&defaultCmd);
}
void WebPages::servProcess()
{
webserver.processConnection();
}
So I'm not sure if I should be reincluding libraries in .h and .ccp.
And why &defaultCmd in webserver.setDefaultCommand(&defaultCmd); is the wrong parameter type.
And just how I should go about using another library in a library and if this is the correct way of going about it.
Any help or reference to a tutorial on this would be great! I've done the arduino creating library tutorial, although it dosnt help much when it comes to refering to other libraries within.