void loop() {
  client = server.available();
  if (client) {                
    while (client.connected()) {
      if (client.available()) {
        if (client.find("GET /")) {
          
          //INICIAR CRONOMETRAGEM
          if (client.find("setCron=")) {
            int charReaded = client.read();
			if(charReaded == 49){
              iniciarCronometragem();
            }
          }
		  
		   //RETORNA O TEMPO DESDE O INICIO		  
          if (client.find("getCron=")) {
            int charReaded = client.read();
			if(charReaded == 49){
              getCronometragem();
			}
          }
        }
      }
      Serial.println();
      break;
    }
    client.println(" HTTP/1.1 200 OK ");
  }
  // give the web browser time to receive the data
  delay(1);
  client.stop();
}
String GAE(String link) {
	httpRequest(link);
	delay(10000);

	String readString = ""; //Reset string

	while (client.available() > 0) {

		char s = client.read();
		//Serial.print(s);			//Complete response w/ headers. For dev mode.
		if (s== '\n') {
			char c = client.read();
			//Serial.print(c);			//Parsed response. For dev mode.
			if (c == '\r') {
				while (client.connected()) {
					char z = client.read();
					readString += z;
				}
			}
		}
	}
	client.stop();
	return(readString);

}
Beispiel #3
0
void MyClientManager::read(EthernetClient client)
{
  int data_size = client.available();
  int x = 0;

  if (headeroffset != 3 && data_size + headeroffset >= HEADER_SIZE)
  {
    while (headeroffset != HEADER_SIZE && x < data_size)
    {
      header[headeroffset] = client.read();
      ++headeroffset;
      ++x;
    }

    if (headeroffset == 3 && header[2] + 1 > BUFFER_SIZE)
      reset();
  }
  else if (headeroffset == 3 && bufferoffset != header[2] && data_size + bufferoffset >= header[2])
  {
    while (bufferoffset != header[2] && x < data_size)
    {
      buffer[bufferoffset] = client.read();
      ++bufferoffset;
      ++x;
    }
  }
  else if (headeroffset == 3 && bufferoffset == header[2] && !checksumisset && data_size > 0)
  {
    checksum = client.read();
    checksumisset = true;
  }
}
Beispiel #4
0
void Parser::readStream(EthernetClient client,char* myreadstring) {
  char c = 0; //carctère de lecture
  char tempo[255];
  bool currentLineIsBlank = true;
  int n = 1;
  int flag = 0;

  for (int k = 0; k < 50; k++) tempo[k] = 0;
  c = client.read(); //lecture du premier caractère;
  if (c != (-1)) {
    if ( c == 'G') {
      flag = 1;
      tempo[0] = c;
      while (c != '\n') {
        c = client.read(); //lecture du caractère
        delay(5);
        tempo[n] = c;
        delay(5);
        n++;
      }
    }
    else {
      tempo[0] = '¤';
      tempo[1] = '?';
      while (client.available() > 0) {
        c = client.read();
        if (c == '\n' && currentLineIsBlank) {
          while (c != '\r') { //doute
            c = client.read(); //lecture du caractère

            delay(5);
            if (c == (-1))
              break;
            tempo[n + 1] = c;
            delay(5);
            n++;
          }
        }
        else if (c == '\n') {
          // you're starting a new line
          currentLineIsBlank = true;
        }
        else if (c != '\r') {
          // you've gotten a character on the current line
          currentLineIsBlank = false;
        }
      }
    }
  }

  if (!flag)n++;

  for (int j = 0; j < n; j++)
    myreadstring[j] = tempo[j] ;

}
void printClient(EthernetClient client){
  int i=0;
    char c = client.read();
    while(c != '\n' && c != '\r'){	
    buffer[i] = c;		
    i++;
    c = client.read();		
  }
  for(int j=0; j<i; j++){
  Serial.write(buffer[j]);
  }
}
Beispiel #6
0
void ModbusIP::task() {
    EthernetClient client = _server.available();

    if (client) {
        if (client.connected()) {
            int i = 0;
            while (client.available()){
                _MBAP[i] = client.read();
                i++;
                if (i==7) break;  //MBAP length has 7 bytes size
            }
            _len = _MBAP[4] << 8 | _MBAP[5];
            _len--;  // Do not count with last byte from MBAP

            if (_MBAP[2] !=0 || _MBAP[3] !=0) return;   //Not a MODBUSIP packet
            if (_len > MODBUSIP_MAXFRAME) return;      //Length is over MODBUSIP_MAXFRAME

            _frame = (byte*) malloc(_len);
            i = 0;
            while (client.available()){
                _frame[i] = client.read();
                i++;
                if (i==_len) break;
            }

            this->receivePDU(_frame);
            if (_reply != MB_REPLY_OFF) {
                //MBAP
                _MBAP[4] = (_len+1) >> 8;     //_len+1 for last byte from MBAP
                _MBAP[5] = (_len+1) & 0x00FF;

                byte sendbuffer[7 + _len];

                for (i = 0 ; i < 7 ; i++) {
                    sendbuffer[i] = _MBAP[i];
                }
                //PDU Frame
                for (i = 0 ; i < _len ; i++) {
                    sendbuffer[i+7] = _frame[i];
                }
                client.write(sendbuffer, _len + 7);
            }

#ifndef TCP_KEEP_ALIVE
            client.stop();
#endif
            free(_frame);
            _len = 0;
        }
Beispiel #7
0
void loop() {
  // listen for incoming clients
  EthernetClient client = server.available();

  // we get a request
  if (client) {
    Serial.println(F("Client connected"));
    // an http request ends with a blank line
    boolean done = false;
    while (client.connected() && !done) {
      while (client.available () > 0 && !done) {
        done = processIncomingByte (client.read ());
      }
    }  // end of while client connected

    // get ROV status values as json string
    String rovStatus = getRovStatus();

    // send a standard http response header
    client.println(F("HTTP/1.1 200 OK"));
    client.println(F("Content-Type: text/json"));
    client.println(F("Connection: close"));  // close after completion of the response
    client.println();   // end of HTTP header
    client.println(rovStatus);

    // give the web browser time to receive the data
    delay(10);
    // close the connection:
    client.stop();
    Serial.println(F("Client disconnected"));
  }  // end of got a new client
}  // end of loop
Beispiel #8
0
void efail()
{
  byte thisByte = 0;
  int loopCount = 0;

  eth_client.println(F("QUIT"));

  while(!eth_client.available()) {
    #ifdef WATCHDOG
    wdt_reset();
    #endif
    delay(1);
    loopCount++;

    // if nothing received for 10 seconds, timeout
    if(loopCount > 10000) {
      eth_client.stop();
      Serial.println(F("\r\nTimeout"));
      return;
    }
  }

  while(eth_client.available())
  {
    thisByte = eth_client.read();
    Serial.write(thisByte);
  }

  eth_client.stop();

  Serial.println(F("disconnected"));
}
Beispiel #9
0
void loop() {
  unsigned long time = millis();
  if (next < time) {
    Ethernet.maintain();
    next += send_delay;
    if (next <= time)
      next = time + 1;
    Serial.println("request time !");
    if (client.connected()) {
      Serial.println("already connected");
    } else {
      Serial.print("connecting results : ");
      Serial.println(client.connect("tarzan.info.emn.fr", 80));
    }
    int sent = client.println("GET /ping.php HTTP/1.1");
    sent = client.println(F("Host: tarzan.info.emn.fr"));
    client.println();
  }
  if (client.connected() && client.available() > 0) {
    Serial.println("client received data  : ");
    unsigned char buffer[buff_size + 1];
    while (client.available() > 0) {
      int read = client.read(buffer, buff_size);
      buffer[read] = '\0';
      Serial.println(read);
    }
  }
  if (radio.receiveDone()) {
  }
}
Beispiel #10
0
void loop() {
  // listen for incoming clients
  EthernetClient client = server.available();
  if (client) 
  {
    Serial.println("new client");
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected()) 
    {
      if (client.available()) 
      {
        char c = client.read();
        Serial.write(c);

        //*******************233333333333333333333333333333333333333333333*******
        // if you've gotten to the end of the line (received a newline
        // character) and the line is blank, the http request has ended,
        // so you can send a reply
        if (c == '\n' && currentLineIsBlank) 
        {
          // send a standard http response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: textml");
          client.println("Connection: close");  // the connection will be closed after completion of the response
          client.println("Refresh: 5");  // refresh the page automatically every 5 sec
          client.println();
          client.println("<!DOCTYPE HTML>");
          client.println("<html>");
          // output the value of each analog input pin
          for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
            int sensorReading = analogRead(analogChannel);
            client.print("analog input ");
            client.print(analogChannel);
            client.print(" is ");
            client.print(sensorReading);
            client.println("<br />");
          }
          client.println("<ml>");
          break;
        }
        if (c == '\n')
        {
          // you're starting a new line
          currentLineIsBlank = true;
        }
        else if (c != '\r')
        {
          // you've gotten a character on the current line
          currentLineIsBlank = false;
        }
      }
    }
    // give the web browser time to receive the data
    delay(1);
    // close the connection:
    client.stop();
    Serial.println("client disconnected");
  }
}
bool PyrobarHTTPRequestHandler::parseRequest(EthernetClient client) {
  if (client.available()) {
    if(client.readStringUntil(' ') == "GET") {
      if(client.read() == '/') {
        String dataType = client.readStringUntil('/');
        if (DEBUG_REQUEST_HANDLER) {
          Serial.print("Data Type: ");
          Serial.println(dataType);
        }
        if(dataType == pyrobarDataTypeBuffer) {
          return handleBuffer(client);
        } else if(dataType == pyrobarDataTypeFire) {
          return handleFireSequence(client);
        } else if(dataType == pyrobarDataTypeScalar) {
          return handleScalar(client);
        } else if(dataType == pyrobarDataTypeLights) {
          return handleLightsOnOff(client);
        } else {
          return false;
        }
      }
    } else {
      return false;
    }
  }
}
Beispiel #12
0
void getData(char *dst)
{
  Serial.println("Trying to grab data from server:");
  
  // from the server, read them and print them:
  int i = 0;
  
  while (!client.available());

  while (client.available()) {
    char c = client.read();
    Serial.print(c);
    
    if (i < 10)
    {
      dst[i] = c;
      //dst[i+1] = 0;
    }

    i++;
  }

  // if the server's disconnected, stop the client:
  if (!client.connected()) {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();

    // do nothing forevermore:
    while(true);
  }
}
void loop() {
  // if there's incoming data from the net connection.
  // send it out the serial port.  This is for debugging
  // purposes only:
  if (client.available()) {
    char c = client.read();
    Serial.print(c);
  }

  // if there's no net connection, but there was one last time
  // through the loop, then stop the client:
  if (!client.connected() && lastConnected) {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();
  }

  // if you're not connected, and ten seconds have passed since
  // your last connection, then connect again and send data:
  if(!client.connected() && (millis() - lastConnectionTime > postingInterval)) {
    httpRequest();
  }
  // store the state of the connection for next time through
  // the loop:
  lastConnected = client.connected();
}
Beispiel #14
0
static void 
extract_status_code(struct HTTPObject *h, EthernetClient client){
    unsigned int k,multiplier,j;
    j=0;
    char c;
    const byte STATUS_CODE_START_INDEX = 9;
    const byte STATUS_CODE_END_INDEX = 11;

    while(j<=STATUS_CODE_END_INDEX && client.connected()){
        if(client.available()){
            // We want to extract the 200 from "HTTP/1.1 200 OK". The 
            // status code starts at index 9 in the string and ends at 11
            c = client.read();
            if(j<STATUS_CODE_START_INDEX){
                j++;
            }
            else if(j>=STATUS_CODE_START_INDEX && j<=STATUS_CODE_END_INDEX){
                // code = 10^2 * str[9] + 10^1 * str[10] + 10^0 * str[11]
                // Do ghetto exponentiation here.
                multiplier = 1;
                for(k = 1; k <= 2 - (j - STATUS_CODE_START_INDEX); k++){
                    multiplier *= 10;
                }
                // c - '0' => char to int
                h->statusCode += (c - '0') * multiplier;
                j++;
            }
        }
    }
}
void MorpheusSlave::receiveEthernet(EthernetClient& incoming) {
	if ( incoming.available() )  {
		char b;
		while ( incoming.available() > 0 ) {
			_lastRX = millis();
			b = incoming.read();
#if DBG
			Serial.print("B: ");
			Serial.println(b);
#endif
			if ( b == '\n' ) {
				endComm();
				break;
			}
			else if ( command == NULL ) {
				command = b;
				data = "";
			}
			else {
				data += b;
			}
		}
    }
	
	if ( _lastRX != -1 && millis() - _lastRX > RX_TIMEOUT ) {
		endComm();
	}
}
boolean readServerResponse() {
	response = "";
	char inBuf[RESPONSE_BUFFER];

	//response.reserve(RESPONSE_BUFFER);
	int bytesRead = 0;
	if (client.connected()) {
		delay(SERVER_WAIT_TIME);
		Serial.println("awaiting response");
		while (client.available()) {
			char c = client.read();
			Serial.print(c);
			if (bytesRead < RESPONSE_BUFFER) inBuf[bytesRead] = c;
			//else client.flush();
			bytesRead++;
		}
		if (bytesRead > 0) {
			response = inBuf;
			Serial.println("Response Received");
			//if (!client.connected()) client.stop();
			return true;
		}
	}
	return false;
}
void checkForResponse(){  
	char c = localClient.read();
	Serial.print(c);
	buff[pointer] = c;
	if (pointer < 64) pointer++;
	if (c == '\n') {
		found = strstr(buff, "200 OK");
		if (found != 0){
			found_status_200 = true; 
			//Serial.println("Status 200");
		}
		buff[pointer]=0;
		found_content = true;
		clean_buffer();    
	}

	if ((found_session_id) && (!found_CSV)){
		found = strstr(buff, "HTTP/1.1");
		if (found != 0){
			char csvLine[strlen(buff)-9];
			strncpy (csvLine,buff,strlen(buff)-9);

			//Serial.println("This is the retrieved CSV:");     
			//Serial.println("---");     
			//Serial.println(csvLine);
			//Serial.println("---");   
			Serial.println("\n--- updated: ");
			Serial.println(pachube_data);
			Serial.println("\n--- retrieved: ");
			char delims[] = ",";
			char *result = NULL;
			char * ptr;
			result = strtok_r( buff, delims, &ptr );
			int counter = 0;
			while( result != NULL ) {
				remoteSensor[counter++] = atof(result); 
				result = strtok_r( NULL, delims, &ptr );
			}  
			for (int i = 0; i < REMOTE_FEED_DATASTREAMS; i++){
				Serial.print( (int)remoteSensor[i]); // because we can't print floats
				Serial.print("\t");
			}

			found_CSV = true;

			Serial.print("\nsuccessful updates=");
			Serial.println(++successes);

		}
	}

	if (found_status_200){
		found = strstr(buff, "_id=");
		if (found != 0){
			clean_buffer();
			found_session_id = true; 
		}
	}
}
Beispiel #18
0
void loopServer() {
	EthernetClient client = server.available();
	if (client) {
		while (client.connected()) {
			if (client.available()) {
				char c = client.read();

				//read char by char HTTP request
				if (readString.length() < 100) {

					//store characters to string
					readString += c;
					//Serial.print(c);
				}

				//if HTTP request has ended
				if (c == '\n') {

					///////////////
					Serial.print(readString); //print to serial monitor for debuging

					//now output HTML data header
					client.println(F("HTTP/1.1 200 OK")); //send new page on browser request
					client.println(F("Content-Type: text/html"));
					client.println();

					client.println(F("Ok"));

					delay(1);
					//stopping client
					client.stop();

					if (readString.indexOf("R1=1") > 0){
						soldoRelays[0]->On();
//						Serial.println(">>>>>>>>>>>>");
//						Serial.println("R1=1");
					}
					if (readString.indexOf("R2=1") > 0){
						soldoRelays[1]->On();
//						Serial.println(">>>>>>>>>>>>");
//						Serial.println("R2=1");
					}
					if (readString.indexOf("R1=0") > 0){
						soldoRelays[0]->Off();
//						Serial.println(">>>>>>>>>>>>");
//						Serial.println("R1=0");
					}
					if (readString.indexOf("R2=0") > 0){
						soldoRelays[1]->Off();
//						Serial.println(">>>>>>>>>>>>");
//						Serial.println("R2=0");
					}
					readString="";

				}
			}
		}
	}
}
Beispiel #19
0
uint16_t readHttpFrame(EthernetClient client) {
	uint16_t size = 0;

    size = client.read((uint8_t *) buf, BUFFER_SIZE);
    buf[size] = 0;

    char *found = strstr_P((char *) buf, PSTR("Content-Length: "));
    if (found == 0) {
        return size; // no length so we stop here
    }
    int contentLength = atoi(&found[16]);
    size_t contentPos = strlen(&strstr_P(found, DOUBLE_ENDL)[4]);
    if (contentPos < contentLength) {
        size += client.read((uint8_t *) &buf[size], contentLength - contentPos);
    }
	return size;
}
void ProcessClientMessage(){   
    // listen for incoming clients
    EthernetClient client = GetAvailableClient();

    if (client) 
    {  
        // an http request ends with a blank line
        boolean currentLineIsBlank = true;

        while (client.connected()) 
        {
            if (client.available()) 
            {
                char c = client.read();

                // if you've gotten to the end of the line (received a newline
                // character) and the line is blank, the http request has ended,
                // so you can send a reply
                if (c == '\n' && currentLineIsBlank) 
                {
                    //Magnetic;Noise;Temperature;Vibration;Voltage

                    String data = "";

                    data += String(GetMagnetic());
                    data += ";";

                    data += String(GetTemperature());
                    data += ";";

                    data += String(GetVibration());
                    data += ";";

                    data += String(GetVoltage());

                    client.println(data);
                    break;
                }

                if (c == '\n') {
                    // you're starting a new line
                    currentLineIsBlank = true;
                }
                else if (c != '\r') 
                {
                    // you've gotten a character on the current line
                    currentLineIsBlank = false;
                }
            }
        }

        // give the web browser time to receive the data
        delay(10);  

        // close the connection:
        client.stop();
    }
}
size_t ArduinoiDigiInterfaceClass::network_recv(idigi_network_handle_t *handle, int timeout_sec, char *buffer, size_t length)
{
  EthernetClient *client = (EthernetClient *) handle;
//  AR_DEBUG_PRINTF("network_recv: timeout_sec = %d\r\n", timeout_sec);
  if (!client->available())
    return 0;
  
  return client->read((uint8_t *) buffer, length);
}
void LeweiTcpClient::listenServer()
{
  EthernetClient clientWeb = server.available();
  if (clientWeb) {
    //Serial.println("new clientWeb");
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    String clientStr = "";
    while (clientWeb.connected()) {
      if (clientWeb.available()) {
        char c = clientWeb.read();
        clientStr += c;
        //Serial.write(c);
        
        // if you've gotten to the end of the line (received a newline
        // character) and the line is blank, the http request has ended,
        // so you can send a reply
        if (c == '\n' && currentLineIsBlank) {
          clientWeb.println("<html><body><form method='get'>");
          clientWeb.print("KEY<input type='text' name='a' value='");
          clientWeb.print(_userKey);
          clientWeb.print("'>GW<input type='text' name='g' value='");
          clientWeb.print(_gatewayNo);
          clientWeb.println("'><input type='submit'>");
          clientWeb.println("</form></body></html>");
          break;
        }
        if (c == '\n') {
          // you're starting a new line
          currentLineIsBlank = true;
          if(clientStr.indexOf(" /?a=")>0)
          {
          	Serial.print(clientStr);
          	String userInfoStr = clientStr.substring(clientStr.indexOf(" /?a=")+5,clientStr.indexOf("&g="));
          	userInfoStr += clientStr.substring(clientStr.indexOf("&g=")+3,clientStr.indexOf(" HTTP/1.1"));
            if(userInfoStr.length()>33)writeRom(userInfoStr);
            Serial.println(userInfoStr);
          }
          //Serial.println(clientStr);
          clientStr = "";
          //checkFreeMem();
        } 
        else if (c != '\r') {
          // you've gotten a character on the current line
          currentLineIsBlank = false;
        }
      }
    }
    // give the web browser time to receive the data
    delay(1);
    // close the connection:
    clientWeb.stop();
    clientWeb= NULL;
    //Serial.println("clientWeb disonnected");
  }
  
}
bool PyrobarHTTPRequestHandler::loadBuffer(String type, int zone, EthernetClient client) {
  if (DEBUG_REQUEST_HANDLER) {
    Serial.print("Loading buffer for zone ");
    Serial.println(zone);
  }
  char tempHex[3] = "00";
  bool success = true;
  while((tempHex[0] = client.read()) != ' ' && (tempHex[1] = client.read()) != ' ') {
    unsigned char value = strtoul(tempHex, NULL, 16);
    if (DEBUG_REQUEST_HANDLER && zone == 0) {
      Serial.print("Received '");
      Serial.print(tempHex);
      Serial.print("' -> ");
      Serial.println(value);
    }
    if (!_lightMap->write(type, zone, value)) success = false;
  }
  return success;
}
  boolean put_handler(AtMegaWebServer& web_server) {
	const char* length_str = web_server.get_header_value("Content-Length");
	long length = atol(length_str);
	const char *path = web_server.get_path();

	SdFile file;
	if(!file.open(path, O_CREAT | O_WRITE | O_TRUNC)){
		 // maybe the folder must be created
		char *c = strrchr(path, '/');
		if(c){
			*c = 0;
			if(sdfat.mkdir(path)){
#if DEBUG
				Serial << "put_handler make DIR: ok " << path <<'\n';
#endif
				*c = '/';
				if(!file.open(path, O_CREAT | O_WRITE | O_TRUNC)){
#if DEBUG
					Serial << "put_handler open FILE: failed " << path <<'\n';
#endif
				}
			}
			*c = '/';
		}
	}
	if(file.isOpen()){

		EthernetClient client = web_server.get_client();
		long size = 0;
		int read = 0;
		while(size < length && web_server.waitClientAvailable()){
			read = client.read((uint8_t*)buffer, sizeof(buffer));
			file.write(buffer, read);
			size += read;
		}
		file.close();
#if DEBUG
		Serial << "file written: " << size << " of: " << length << '\n';
#endif
		if(size < length){
			web_server.sendHttpResult(404);
		}else{
			web_server.sendHttpResult(200);
			web_server << path;
		}

	}else{
		web_server.sendHttpResult(422); // assuming it's a bad filename (non 8.3 name)
#if DEBUG
		Serial << F("put_handler open file failed: send 422 ") << path <<'\n';
#endif
	}
	return true;
  }
Beispiel #25
0
char * CosmClient::getFeed(uint32_t feedId) {
    int maxSize = 50;
    char response[maxSize];

    for(int i=0; i<sizeof(response); i++) {
        if (!_client.available()) {
            return response;
        }
        char c = _client.read();
    }
}
Beispiel #26
0
/*
 * Read through all the headers of the HTTP Response stored in the client
 */
static void 
skip_http_headers(EthernetClient client){
    char c;
    byte allHeadersRead = 0;
    while(!allHeadersRead && client.connected()){
        if(client.available()){
            c = client.read();
            allHeadersRead = finished_reading_headers(&c, client);
        }
    }
}
Beispiel #27
0
//---------------------------------------------------------------------
void terminateConnection()
{
    // flush input buffer
    while ( client_.read() != (-1) )
        delay( STREAM_DELAY_MS );
    
    client_.stop();
#ifdef DEBUG_SERIAL
    Serial.println( "DEBUG: client disconnected" );
#endif
    digitalWrite( PIN_STATUS_LED, LOW );
}
void loop() {
  // Look for new cards
  if ( ! mfrc522.PICC_IsNewCardPresent()) {
    return;
  }

  // Select one of the cards
  if ( ! mfrc522.PICC_ReadCardSerial()) {
    return;
  }

  client.connect(server, 3000);

  char store_id[30];
  
  for (byte i = 0; i < mfrc522.uid.size; i++) {
    Serial.print(mfrc522.uid.uidByte[i]);
  } 
	Serial.println();

  unsigned int hex_num;
  hex_num =  mfrc522.uid.uidByte[0] << 24;
  hex_num += mfrc522.uid.uidByte[1] << 16;
  hex_num += mfrc522.uid.uidByte[2] <<  8;
  hex_num += mfrc522.uid.uidByte[3];

  int  NFC_id=  (int)hex_num;

  sprintf(store_id,"%d" ,NFC_id);

  Serial.print("Store id is: ");
  Serial.println(store_id);

  char req[80];
  strcpy(req, "GET /?uid=");
  strcat(req, store_id);
  strcat(req, "&lat=48.139867&long=11.560935&sensor=MUCHbf HTTP/1.0");
    
  // Make a HTTP request:
  client.println(req);
  client.println();
  Serial.println("Request sent");
  Serial.println(req);

  
  // if there are incoming bytes available 
  // from the server, read them and print them:
  while (client.available()) {
    char c = client.read();
    Serial.print(c);
  }

}
/* the function reads 'size' bytes from the 'client' 
 * and store them into the 'buffer'. 
 * It is useful to read parameters sent from client
 * */
int readParam(char* buffer, int size, EthernetClient client)
{
	/* TODO return error code if received bytes are less than 'size' */
	int i, buffer_ptr = 0;
	for(i = 0; i < size; i++)
	{
		if(client.available()) buffer[buffer_ptr++] = client.read();
		else return -1;
	}
	buffer[buffer_ptr++] = NULL;
	return 0;
}
Beispiel #30
0
void extract_body(struct HTTPObject *h, EthernetClient client){
    char c;
    unsigned int bodyIdx = 0;

    while(bodyIdx < h->bufSize - 1 && client.connected()){
        if(client.available()){
            c = client.read();
            h->body[bodyIdx++] = c;
        }
    }
    h->body[bodyIdx] = '\0';
    h->bodyLength = bodyIdx;
}