/** Send an index HTML page with an input box for a username */ void sendPong() { /* Send the header direclty with print */ wifly.println(F("HTTP/1.1 200 OK")); wifly.println(F("Content-Type: text/xml")); wifly.println(F("Transfer-Encoding: chunked")); wifly.println(); /* Send the body using the chunked protocol so the client knows when * the message is finished. * Note: we're not simply doing a close() because in version 2.32 * firmware the close() does not work for client TCP streams. */ wifly.sendChunkln(F("<?xml version=\"1.0\" encoding=\"UTF-8\"?>")); snprintf_P(wbuf, sizeof(wbuf), PSTR("<pong>%s</pong>"), macaddr); wifly.sendChunkln(wbuf); wifly.sendChunkln(); }
/** Send a 404 error */ void send404() { wifly.println(F("HTTP/1.1 404 Not Found")); wifly.println(F("Content-Type: text/html")); wifly.println(F("Transfer-Encoding: chunked")); wifly.println(); wifly.sendChunkln(F("<html><head>")); wifly.sendChunkln(F("<title>404 Not Found</title>")); wifly.sendChunkln(F("</head><body>")); wifly.sendChunkln(F("<h1>Not Found</h1>")); wifly.sendChunkln(F("<hr>")); wifly.sendChunkln(F("</body></html>")); wifly.sendChunkln(); }
void sendSensorsDataXML() { /* Send the header directly with print */ wifly.println(F("HTTP/1.1 200 OK")); wifly.println(F("Content-Type: text/xml")); wifly.println(F("Transfer-Encoding: chunked")); wifly.println(); /* Send the body using the chunked protocol so the client knows when * the message is finished. */ wifly.sendChunkln(F("<?xml version=\"1.0\" encoding=\"UTF-8\"?>")); wifly.sendChunkln(F("<datacollector>")); snprintf_P(wbuf, sizeof(wbuf), PSTR("<dcid>%s</dcid>"), macaddr); wifly.sendChunkln(wbuf); wifly.sendChunkln(F("<geoloc>")); int ind; char scanbufcpy[500]; strncpy(scanbufcpy, scanbuf, 500); char *ap, *oap; char *apdesctok, *apdesc; ap = strtok_r(scanbufcpy, "|", &oap); while(ap != NULL) { wifly.sendChunkln(F("<ap>")); ind = 0; apdesctok = strtok_r(ap, " ", &apdesc); while(apdesctok != NULL) { ind++; switch(ind) { case 3: snprintf_P(wbuf, sizeof(wbuf), PSTR("<channel>%s</channel>"), apdesctok); wifly.sendChunkln(wbuf); break; case 4: snprintf_P(wbuf, sizeof(wbuf), PSTR("<rssi>%s</rssi>"), apdesctok); wifly.sendChunkln(wbuf); break; case 6: snprintf_P(wbuf, sizeof(wbuf), PSTR("<mac>%s</mac>"), apdesctok); wifly.sendChunkln(wbuf); break; default: ; } apdesctok = strtok_r(NULL, " ", &apdesc); } wifly.sendChunkln(F("</ap>")); //Serial.println(); ap = strtok_r(NULL, "|", &oap); } wifly.sendChunkln(F("</geoloc>")); wifly.sendChunkln(F("<sensors>")); /* Include readings from Analog pins */ dtostrf(Thermistor(analogRead(ThermistorPIN)), 5,2, convbuf); snprintf_P(wbuf, sizeof(wbuf), PSTR("<sensor><type>temp</type><value>%s</value></sensor>"), convbuf); #ifdef DEBUG Serial.println(wbuf); #endif wifly.sendChunkln(wbuf); dtostrf(Photoresistor(analogRead(PhotoresistorPIN)), 5,2, convbuf); snprintf_P(wbuf, sizeof(wbuf), PSTR("<sensor><type>light</type><value>%s</value></sensor>"), convbuf); #ifdef DEBUG Serial.println(wbuf); #endif wifly.sendChunkln(wbuf); sprintf(convbuf,"NA"); snprintf_P(wbuf, sizeof(wbuf), PSTR("<sensor><type>humidity</type><value>%s</value></sensor>"), convbuf); #ifdef DEBUG Serial.println(wbuf); #endif wifly.sendChunkln(wbuf); sprintf(convbuf,"NA"); snprintf_P(wbuf, sizeof(wbuf), PSTR("<sensor><type>pressure</type><value>%s</value></sensor>"), convbuf); #ifdef DEBUG Serial.println(wbuf); #endif wifly.sendChunkln(wbuf); wifly.sendChunkln(F("</sensors>")); wifly.sendChunkln(F("</datacollector>")); wifly.sendChunkln(); }