Skip to content

Instantly share code, notes, and snippets.

@exiva
Created June 30, 2012 03:41
Show Gist options
  • Save exiva/3022071 to your computer and use it in GitHub Desktop.
Save exiva/3022071 to your computer and use it in GitHub Desktop.
#define WEBDUINO_FAVICON_DATA "" //save 198 bytes.
#include <SPI.h>
#include <Ethernet.h>
#include <WebServer.h>
//config ehternet
static uint8_t mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
static uint8_t ip[] = { 192, 168, 1, 210 };
#define PREFIX ""
#define NAMELEN 32
#define VALUELEN 500
WebServer webserver(PREFIX, 80);
void codeCmd(WebServer &server, WebServer::ConnectionType type, char *url_tail, bool tail_complete) {
char param[NAMELEN];
char value[VALUELEN];
char *rawCode;
int rawLen;
server.httpSuccess();
if (type == WebServer::POST) {
server.readPOSTparam(param, NAMELEN, value, VALUELEN);
if(strcmp(param,"type") == 0) {
if(strcmp(value,"raw") == 0) {
server.readPOSTparam(param, NAMELEN, value, VALUELEN);
if(strcmp(param,"code") == 0) {
rawCode=value;
Serial.print("1 ");
Serial.println(rawCode);
}
Serial.print("2 ");
Serial.println(rawCode);
server.readPOSTparam(param, NAMELEN, value, VALUELEN);
Serial.print("3 ");
Serial.println(rawCode);
if(strcmp(param,"len") == 0) {
Serial.print("4 ");
Serial.println(rawCode);
rawLen = atoi(value);
}
}
Serial.println(rawCode);
Serial.println(rawLen);
parseData(rawCode, rawLen);
}
}
}
void parseData(char* raw, int leng) {
const char *t = raw;
int x=0;
char f[10];
int n;
while(sscanf(t, "%31[^,]%n", f, &n) == 1) {
t+=n;
//blah blah blah. getting to this.
if(*t != ',') {
break;
}
++t;
x++;
}
x=0;
}
void setup() {
Ethernet.begin(mac, ip);
webserver.addCommand("ir", &codeCmd);
webserver.begin();
}
void loop() {
char buff[64];
int len = 64;
webserver.processConnection(buff, &len);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment