Example #1
0
// this method makes a HTTP connection to the server:
void sendData(String thisData) {
    // if there's a successful connection:
    if (client.connect("www.pachube.com", 80)) {
        Serial.println("connecting...");
        // send the HTTP PUT request.
        // fill in your feed address here:
        client.print("PUT /api/YOUR_FEED_HERE.csv HTTP/1.1\n");
        client.print("Host: www.pachube.com\n");
        // fill in your Pachube API key here:
        client.print("X-PachubeApiKey: YOUR_KEY_HERE\n");
        client.print("Content-Length: ");
        client.println(thisData.length(), DEC);

        // last pieces of the HTTP PUT request:
        client.print("Content-Type: text/csv\n");
        client.println("Connection: close\n");

        // here's the actual content of the PUT request:
        client.println(thisData);

        // note the time that the connection was made:
        lastConnectionTime = millis();
    }
    else {
        // if you couldn't make a connection:
        Serial.println("connection failed");
    }
}
Example #2
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");
  }
}
//builds the url for the api request, connects to the server, and sends the request
boolean serverRequest() {
	//Serial.print(server);
	//Serial.println(page);
	client.stop();

	Serial.println("connecting...");
	if (client.connect(server, 80)) {
		Serial.println("connected");
		client.print("GET /makermanager/index.php?r=api/toolValidate&badge=");
		client.print(rfid_long);
		client.print("&tool=1");
		client.println(" HTTP/1.1");
		client.print("Host: ");
		client.println(server);
		client.println("User-Agent: arduino-ethernet");
		client.println("Connection: close");
		client.println("");
		
		//Serial.println(cmd);
		//client.println(cmd);
		return true;
	}
	else {
		Serial.println("connection failed");
		return false;
	}
}
Example #4
0
void Nimbits::createPoint(String pointName)
{
  EthernetClient client;
  if (client.connect(GOOGLE, PORT))
  {
    client.println(F("POST /service/point HTTP/1.1"));
    String content;
    //  writeAuthParams(content);
    content += "email=";
    content += _ownerEmail;
    if (_accessKey.length() > 0)
    {
      content += ("&key=");
      content += (_accessKey);
    }
    content += "&action=create&point=";
    content += (pointName);
    client.println(F("Host:nimbits1.appspot.com"));
    client.println(F("Connection:close"));
    client.println(F("Cache-Control:max-age=0"));
    client.print(F("Content-Type: application/x-www-form-urlencoded\n"));
    client.print(F("Content-Length: "));
    client.print(content.length());
    client.print(F("\n\n"));
    client.print(content);
    while (client.connected() && !client.available())
    {
      delay(1); //waits for data
    }
    client.stop();
    client.flush();
  }

}
// this method makes a HTTP connection to the server:
void sendData(String thisData) {
  // if there's a successful connection:
  if (client.connect(server, 80)) {
    Serial.println("connecting...");
    // send the HTTP PUT request:
    client.print("PUT /v2/feeds/");
    client.print(FEEDID);
    client.println(".csv HTTP/1.1");
    client.println("Host: api.xively.com");
    client.print("X-ApiKey: ");
    client.println(APIKEY);
    client.print("User-Agent: ");
    client.println(USERAGENT);
    client.print("Content-Length: ");
    client.println(thisData.length());

    // last pieces of the HTTP PUT request:
    client.println("Content-Type: text/csv");
    client.println("Connection: close");
    client.println();

    // here's the actual content of the PUT request:
    client.println(thisData);
  } 
  else {
    // if you couldn't make a connection:
    Serial.println("connection failed");
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();
  }
  // note the time that the connection was made or attempted:
  lastConnectionTime = millis();
}
void loop()
{
	static double v = 0.0;
	static int count = 0;

	EthernetClient client = server.available();
	if (client)
	{
		while(true){

			Serial.print("Printing data... count=");
			Serial.println(count);

			client.print(count++); client.print("; ");
			client.print(0.00 + v, 2); client.print("; ");
			client.print(1.23 + v, 2); client.print("; ");
			client.print(2.098 + v, 3); client.print("; ");
			client.print(3.83974 + v, 5); client.print("; ");
			client.print(1.23 + v, 10); client.print("; ");
			client.println(6.1276512765 + v, 10);
			client.println("\r\n");

			Serial.println("Done!");
			delay(1000);

			v += 0.2;
		}
	}else{
		Serial.print("NO client!!! count=");
		Serial.println(count++);
	}

	delay(1000);

}
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");
  }
  
}
Example #8
0
void Nimbits::writeAuthParamsToClient(EthernetClient client)
{
  client.print(F("email="));
  client.print(_ownerEmail);
  if (_accessKey.length() > 0)
  {
    client.print(F("&key="));
    client.print(_accessKey);
  }
}
Example #9
0
void Nimbits::writeHostToClient(EthernetClient client)
{
  client.print(F("&client=arduino"));
  client.print(F(" "));
  client.println(F("HTTP/1.1"));
  client.print(F("Host:"));
  client.print(_instance);
  client.println(F(".appspot.com"));
  client.println();
}
// Fonction affichant sur le port série le contenu d'un fichier sur carte mémoire SD
// par X. HINAULT - www.mon-club-elec.fr - GPLv3 - 03/2013
void UtilsSDEthernet::read(EthernetClient clientIn, char* nomFichierIn, boolean debug) {
  // La fonction reçoit : 
  // > le client Ethernet à utiliser 
  // > le nom du fichier au format 8.3
  // > un drapeau d'affichage de messages de debug
  
  // la fonction ne renvoie rien 
 
                // lecture du contenu du fichier  
                File dataFile=SD.open(nomFichierIn, FILE_READ); // ouvre le fichier en lecture - NOM FICHIER en 8.3 ++++
                // un seul fichier ne peut etre ouvert à la fois - fermer au préalable tout fichier déjà ouvert
               
                clientIn.println(F("------")); 
                    
                if (dataFile){ // le fichier est True si créé
                  if (debug) clientIn.println(F("Ouverture fichier OK")); 
                
                  while (dataFile.available()) { // tant que des données sont disposnibles dans le fichier
                  // le fichier peut etre considéré comme un "buffer" de données comme le buffer du port série
                
                    char c = dataFile.read(); // lit le caractère suivant
                    clientIn.print(c); // affiche le caractère courant
                    
                    //if (c==10) delay(10); // pause enttre 2 lignes
                  } // fin while available
                
                  dataFile.close(); // fermeture du fichier obligatoire après accès 
                  
                } // si fichier True 
                else { // sinon = si probleme creation
                  clientIn.println(F("Probleme lecture fichier")); 
                } // fin else              
  
} // fin fonction readSerial 
Example #11
0
void sendValues() { //Send values to www.onms.net server
    if (client.connect(server, 80)) {
        Serial.println("Connected to www.onms.net server...");
        client.print("GET ");
        client.print("/?update_id=");
        client.print(update_id);
        client.print("&key=humidity&value=");
        client.print(humidity);
        client.println(" HTTP/1.1");
        client.println("Host: www.onms.net");
        client.println();
        Serial.println("Disconnecting from www.onms.net server...");
        client.stop();
    } else {
        Serial.println("Connection to www.onms.net failed...");
    }
}
/*
 * Sends an HTTP POST request containing the name and the code to the server.
 */
void sendData() {
	Serial.print("attempting to send data (name = ");
	Serial.print(nameBuf);
	Serial.print(", code = ");
	Serial.print(buffer);
	Serial.println(")");


	// if you get a connection, report back via serial:
	if (client.connect(server, port)) {
		Serial.println("connected");
		// Make a HTTP request:
		client.print("POST /barcode");
		client.print("?name=");
		client.print(nameBuf);
		client.print("&code=");
		client.print(buffer);
		client.print("&uptime=");
		client.print(millis());
		client.println(" HTTP/1.0");
		client.println();
		client.flush();
		client.stop();
		Serial.println("request sent");
	}
	else {
		// if you didn't get a connection to the server:
		Serial.println("connection failed");
	}
}
Example #13
0
void loop()
{
  // listen for incoming clients
  EthernetClient client = server.available();
  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) {
          // send a standard http response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println();

          // output the value of each analog input pin
          for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
            client.print("analog input ");
            client.print(analogChannel);
            client.print(" is ");
            client.print(analogRead(analogChannel));
            client.println("<br />");
          }
          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();
  }
}
Example #14
0
String Nimbits::recordValue(String point, float value)
{
  EthernetClient client;
  String content;

  if (client.connect(GOOGLE, PORT))
  {
    client.println(F("POST /service/value HTTP/1.1"));
    //  writeAuthParams(content);
    content += ("email=");
    content += _ownerEmail;
    if (_accessKey.length() > 0)
    {
      content += ("&key=");
      content += (_accessKey);
    }

    char buffer[10];

    dtostrf(value, 5, 5, buffer);
    String str = buffer;

    content += ("&value=");
    content += (str);
    content += ("&point=");
    content += (point);
    client.println(F("Host:nimbits1.appspot.com"));
    client.println(F("Connection:close"));
    client.println(F("Cache-Control:max-age=0"));
    client.print(F("Content-Type: application/x-www-form-urlencoded\n"));
    client.print(F("Content-Length: "));
    client.print(content.length());
    client.print(F("\n\n"));
    client.print(content);
    while (client.connected() && !client.available())
    {
      delay(1); //waits for data
    }
    client.stop();
    client.flush();
  }

  return content;
}
Example #15
0
float Nimbits::getValue(String pointName)
{
  EthernetClient client;

  if (client.connect(GOOGLE, PORT))
  {
    client.print(F("GET /service/value?"));
    writeAuthParamsToClient(client);
    client.print(F("&point="));
    client.print(pointName);
    writeHostToClient(client);

    return atof(&getResponse(client)[0]);
  }
  else
  {
    return -1;
  }

}
void updateDB_Door(){	
	Serial.println("connecting for DB update");
	if (client.connect(server, 80)) {
		client.print("GET http://153.42.193.63/ardi_db_update.php?door=");
		if(clientDoor)
			client.print(clientDoor,BIN);
		else
			client.print("'0'");
			
		client.print(" HTTP/1.0");
		client.println("Host: http://153.42.193.63");
		client.println();
		doorChanged = 1;
	} 
	else {  //connection failed
		Serial.println("connection failed");
		doorChanged = 0;
	}
	client.stop();
	client.flush();
}
void updateDB_Shades(){	
	Serial.println("connecting for DB update");
	if (client.connect(server, 80)) {
		client.print("GET http://153.42.193.63/ardi_db_update.php?shades=");
		if(clientShades)
			client.print(clientShades,BIN);
		else
			client.print("'0'");
			
		client.print(" HTTP/1.0");
		client.println("Host: http://153.42.193.63");
		client.println();
		shadesChanged = 1;
	} 
	else {
		Serial.println("connection failed");
		shadesChanged = 0;
	}

	client.stop();
	client.flush();
}
Example #18
0
void printFooter() {

  client.print("\"");
  client.print("THE");
  client.print("\"");
  client.print(":");
  client.print("\"");
  client.print("END");
  client.println("\"");

  client.print("}");
}
Example #19
0
void loop(){
  if (dataLesen()==1) {
  //QFF-Berechnung
  x = ((temp + konst1)/(qfe/100)*exp(((temp+konst1+konst2)*11.5526-26821)/(temp+konst1+konst2-1060)));
  qff = (qfe/100)*exp(konst2*10.5152/(x+temp+konst1+konst2));
  //Messwerten abschicken
  if (client.connect(serverName, 80)) {
    //Serial.println("Verbunden ... sende ... fertig!");
    // URL anrufen:
    client.print("GET /upload.php?TEMP=");
    client.print(temp);
    client.print("&TAU=");
    client.print(taupunkt);
    client.print("&QFE=");
    client.print(qfe/100, 1);
    client.print("&QFF=");
    client.print(qff,1);
    client.print("&FEUCHTE=");
    client.print(feuchte);
    client.println("&key=root HTTP/1.0\n");
    client.println("Host: localhost");
    client.println("User-Agent: Arduino");
    client.println();
    client.stop();
  } 
  if (!client.connected()) {
    /*Serial.println();
    Serial.println("disconnecting.");*/
    client.stop();
}    
  delay(899500);
  softReset();
/*  else {
    // 2. Worst-Case-Szenario
    Serial.println("connection failed");
  }*/
}
}
 // Fonction renvoyant la taille en octet d'un fichier sur carte mémoire SD
// par X. HINAULT - www.mon-club-elec.fr - GPLv3 - 03/2013
int UtilsSDEthernet::getFileSize(EthernetClient clientIn, char* nomFichierIn, boolean debug) {
  // La fonction reçoit : 
  // > le client Ethernet à utiliser 
  // > le nom du fichier au format 8.3
  // > un drapeau d'affichage de messages de debug
  
  // la fonction renvoie le nombre d'octet du fichier
 
   File dataFileIn=SD.open(nomFichierIn, FILE_READ); // ouvre le fichier en lecture - NOM FICHIER en 8.3 ++++
     
     if (debug) clientIn.println("------"); 

    clientIn.println("------"); 

   if (dataFileIn){ // le fichier est True si créé

      if (debug)clientIn.println(F("Ouverture fichier OK")); 
    
  
      if (debug) clientIn.print(F("Taille du fichier : "));
      if (debug) clientIn.print(dataFileIn.size());
      if (debug) clientIn.println(F(" octets."));
  
      return(dataFileIn.size()); // renvoie la taille du fichier

       if (debug) clientIn.println(F("------")); 
  
      dataFileIn.close(); // fermeture du fichier obligatoire après accès 

    } // si fichier existe 
    else { // sinon = si probleme creation

      clientIn.println(F("Probleme ouverture fichier")); 
      return(0); 
      
    } // fin else
  
} // fin fonction getFileSize
void updateDB_Lights(){
	Serial.println("connecting for DB update");
	if (client.connect(server, 80)) {
		client.print("GET http://153.42.193.63/ardi_db_update.php?lights=");
		if(clientLights)
			client.print(clientLights,BIN);
		else
			client.print("'0'");
			
		client.print(" HTTP/1.0");
		client.println("Host: http://153.42.193.63");
		client.println();
		Serial.println("connection successful");
		
		lightsChanged = 1;
		
	} 
	else {
		lightsChanged = 0;
		Serial.println("connection failed");
	}
	client.stop();
	client.flush();
}	
Example #22
0
void sendData() {
	request[0] = '?';
	int sensorsRead = buildRequestString(soldoSensors, SOLDO_SENSORS_COUNT,
			request + 1);
	if (sensorsRead > 0) {

		if (client.connect(serverIp, 80)) {
			Serial.println("connecting...");
			// send the HTTP PUT request:
			client.print("GET /index.py");
			client.print(request);
			client.println(" HTTP/1.0");
			client.println();

		} else {
			// if you couldn't make a connection:
			Serial.println("connection failed");
			Serial.println("disconnecting.");
			client.stop();
		}
		int cc = 20000;
		while (client.connected() && !client.available()) {
			delay(1); //waits for data
			if(cc--) break;
		}
		while (client.connected() || client.available()) { //connected or data available
			char c = client.read();
			//Serial.print(c);
		}
		Serial.println();
		Serial.println("disconnecting.");
		Serial.println("==================");
		Serial.println();
		client.stop();
	}
}
Example #23
0
void refreshSection(EthernetClient& client)
{
  if (addRefeshSection)
  {
    client.print("<meta http-equiv=\"Refresh\" content=\"0; url=http://");
    client.print(ip[0]);
    client.print(".");
    client.print(ip[1]);
    client.print(".");
    client.print(ip[2]);
    client.print(".");
    client.print(ip[3]);
    client.println("\" />");

    addRefeshSection = false;
  }
}
int connectAndRead(){
	//connect to the server
	Serial.println(Ethernet.localIP());
	Serial.println("connecting for DB poll...");
  
	//port 80 is typical of a www page
	if (client.connect(server, 80)) {
		client.print("GET ");
		client.println(location);
		client.println();
		return 1;  // connection successful
	}
	else{
		return 0;  //connection failed
	}
}
Example #25
0
void Nimbits::doPost(EthernetClient client, String service, String content) {

    client.println("POST " + service + " HTTP/1.1");
    client.println("Accept: */*");
    client.println("Host: " + _hostname + ":" + _port);
    client.println("Connection: close");
    client.println("User-Agent: Arduino/1.0");
    client.println("Cache-Control: max-age=0");
    client.println("Content-Type: application/x-www-form-urlencoded");
    client.println("token: " + _authToken);
    client.print("Content-Length: ");
    client.println(content.length());
    client.println();
    client.println(content);

}
Example #26
0
void printChaveValorJson(String chave, String valor) {

  client.print("\"");
  client.print(chave);
  client.print("\"");
  client.print(":");
  client.print("\"");
  client.print(valor);
  client.println("\",");

}
Example #27
0
long Nimbits::getTime()
{
  EthernetClient client;

  if (client.connect(GOOGLE, PORT))
  {
    client.print(F("GET /service/time?"));
    writeAuthParamsToClient(client);
    writeHostToClient(client);

    String response = getResponse(client);
    return atol(&response[0]);

  }
  else
  {
    return -1;
  }
}
// Fonction renvoyant le nombre de lignes d'un fichier sur carte mémoire SD
// par X. HINAULT - www.mon-club-elec.fr - GPLv3 - 03/2013
int UtilsSDEthernet::getNumberOfLines(EthernetClient clientIn, char* nomFichierIn, boolean debug) {
  // La fonction reçoit : 
  // > le client Ethernet à utiliser 
  // > le nom du fichier au format 8.3
  // > un drapeau d'affichage de messages de debug
  
  // la fonction renvoie le nombre de ligne
 
   File dataFileIn=SD.open(nomFichierIn, FILE_READ); // ouvre le fichier en lecture - NOM FICHIER en 8.3 ++++
 
   if (debug) clientIn.println(F("------")); 
   
   int comptLine=0; // variable de comptage des lignes 
  
   if (dataFileIn){ // le fichier est True si créé

      if (debug)clientIn.println(F("Ouverture fichier OK")); 
  
      while (dataFileIn.available()) { // tant que des données sont disposnibles dans le fichier
      // le fichier peut etre considéré comme un "buffer" de données comme le buffer du port série
    
        char c = dataFileIn.read(); // lit le caractère suivant
        if (debug)clientIn.print(c); // affiche le caractère courant

        if (c==10) { // si le caractère est \n : c'est une fin de ligne
        comptLine=comptLine+1; 
        } // fin if saut de ligne
      
      } // fin while available   

     if (debug) clientIn.println("------"); 
  
      dataFileIn.close(); // fermeture du fichier obligatoire après accès 
    
      
    } // si fichier existe 
    else { // sinon = si probleme creation
      clientIn.println(F("Probleme ouverture fichier")); 
    } // fin else

    return(comptLine); // renvoie le nombre de ligne
  
} // fin fonction getNumberOfLines
Example #29
0
void sendHttpRequest(byte ip[], int port, EthernetClient cl) {
  if (cl.connect(ip, port)) {
    timeStamp();
    Serial.print("Host ");
    printIp(ip);
    Serial.print(" ");
    Serial.println(buf);
    cl.println(buf);
    cl.print("Host: ");
    sendIpClient(SELF_IP, cl);
    cl.println();
    cl.println();
    delay(100);
    cl.stop();
  } else {
      timeStamp();
      Serial.print("Host ");
      printIp(ip);
      Serial.print(" not connected (");
      Serial.print(buf);
      Serial.println(")");
    }
}
void PyrobarHTTPRequestHandler::handleRequest(EthernetClient client) {
  if (DEBUG_LIGHT_MAP) {
    Serial.print("Light map in PyrobarHTTPRequestHandler at address ");
    Serial.println((long)_lightMap);
  }
  if (DEBUG_REQUEST_HANDLER) {
    Serial.println("Handling request");
  }
  bool currentLineIsBlank = true;
  bool success = parseRequest(client);
  while (client.connected()) {
    char c = client.read();
    if (c == '\n' && currentLineIsBlank) {
      client.print("HTTP/1.1 ");
      client.println(success ? "200 OK" : "401 BAD REQUEST");
      client.println("Content-Type: text/plain");
      client.println("Connection: close");  // the connection will be closed after completion of the response
      break;
    }
    if (c == '\n') currentLineIsBlank = true;
    else if (c != '\r') currentLineIsBlank = false;
  }
  client.stop();
}