Пример #1
0
/** 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();
}
int JSONAPI::request ( js0n_user_cb_t cb ) {
  if (this->hasBody) {
    wifly.println("0");
    wifly.println();
  }
  
  js0n_parser_t parser;
  parser.buffer = this->buffer;
  parser.stream = &wifly;
  parser.user_cb = cb;
  
  int status_code = 0;
  readResponseHeaders(&status_code, (int *) &parser.length);
  if (status_code != 0 && status_code < 500) {
    int parse_status = js0n_parse ( &parser );
  }
  return status_code;
}
Пример #3
0
/** 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();
}
void JSONAPI::_headerEnd () {
  wifly.println(" HTTP/1.1"); // paste your number here
  wifly.print("Host: ");
  wifly.println(this->host);
  wifly.println("User-Agent: lifegraph/0.0.1");
  if (this->hasBody) {
    wifly.println("Content-Type: application/x-www-form-urlencoded");
    wifly.println("Transfer-Encoding: chunked");
  }
  wifly.println();
}
void JSONAPI::_chunk (const char *str, int len) {
  char lenstr[12];
  sprintf(lenstr, "%X", len);
  wifly.println(lenstr);
  wifly.println(str);
}
Пример #6
0
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();

}