Example #1
1
//---------------------------------------------------------------------
void processCommand( uint8_t command )
{
    switch ( command )
    {
        //-------------------------------------------------------------
        case COMMAND_TAG_EMULATE:
        {
#ifdef DEBUG_SERIAL
            Serial.println( "DEBUG: nfc tag emulate" );
#endif
            emulateNfcTag();
            break;
        }
        //-------------------------------------------------------------
        case COMMAND_VIB_MEASUREMENT:
        {
#ifdef DEBUG_SERIAL
            Serial.println( "DEBUG: vibration measurement" );
#endif
            if ( measureVibration() )
                client_.println( VIB_MEASUREMENT_RESP_ON );
            else
                client_.println( VIB_MEASUREMENT_RESP_OFF );
            
            break;
        }
        //-------------------------------------------------------------
        case COMMAND_LIGHT_MEASUREMENT:
        {
#ifdef DEBUG_SERIAL
            Serial.println( "DEBUG: light measurement" );
#endif
            if ( measureLight() )
                client_.println( LIGHT_MEASUREMENT_RESP_ON );
            else
                client_.println( LIGHT_MEASUREMENT_RESP_OFF );
            
            break;
        }
        //-------------------------------------------------------------
        case COMMAND_VIB_CALIBRATE:
        {
#ifdef DEBUG_SERIAL
            Serial.println( "DEBUG: calibrate vibration sensor" );
#endif
            vibrationCalibration();
            break;
        }
        default:
            //handle error
            ;
#ifdef DEBUG_SERIAL
            Serial.println( "WARNING: unknown command" );
#endif
    }
}
Example #2
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();
  }

}
// Fonction créant un fichier sur carte mémoire SD
// par X. HINAULT - www.mon-club-elec.fr - GPLv3 - 03/2013
void UtilsSDEthernet::createFile(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 
 
              // création nouveau fichier  
              File dataFile=SD.open(nomFichierIn, FILE_WRITE); // crée / ouvre un objet fichier et l'ouvre en mode écriture - NOM FICHIER en 8.3 ++++
              // > soit en mode : FILE_WRITE: ouvre le fichier pour lecture et écriture, en démarrant au début du fichier. 
              // Important : Si le fichier est ouvert pour écriture, il sera créé si il n'existe pas déjà (cependant le chemin le contenant doit déjà exister)
             
              clientIn.println("------"); 
                
              if (dataFile){ // le fichier est True si créé
                clientIn.println(F("Creation nouveau fichier OK")); 
                dataFile.print(""); // chaine vide
                dataFile.close(); // fermeture du fichier obligatoire après accès 
              } // si fichier existe 
              else { // sinon = si probleme creation
                clientIn.println(F("Probleme creation fichier")); 
              } // fin else datafile
  
} // fin fonction createFile 
Example #4
0
void setup() {
 // Open serial communications and wait for port to open:
  Serial.begin(9600);
   while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }

  // start the Ethernet connection:
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    // no point in carrying on, so do nothing forevermore:
    // try to congifure using IP address instead of DHCP:
    Ethernet.begin(mac, ip);
  }
  // give the Ethernet shield a second to initialize:
  delay(1000);
  Serial.println("connecting...");

  // if you get a connection, report back via serial:
  if (client.connect(server, 80)) {
    Serial.println("connected");
    // Make a HTTP request:
    client.println("GET /search?q=arduino HTTP/1.1");
    client.println("Host: www.google.com");
    client.println("Connection: close");
    client.println();
  }
  else {
    // kf you didn't get a connection to the server:
    Serial.println("connection failed");
  }

}
//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 #6
0
void sendData()
{
  Serial.println("connecting...");

  // if you get a connection, report back via serial:
  if (client.connect("kaylee.markild.no", 80))
  
  {
    Serial.println("connected");
    // Make a HTTP request:
    Serial.println("GET /crap/test.txt HTTP/1.1");
    client.println("GET /crap/test.txt HTTP/1.1");
    Serial.println("Host: kaylee.markild.no");
    client.println("Host: kaylee.markild.no");
    Serial.println("User-Agent: ArduinoUno/r3 Ethernet Shield");
    client.println("User-Agent: ArduinoUno/r3 Ethernet Shield");
    Serial.println("Accept: */*");
    client.println("Accept: */*");    
    client.println();
  }
  else
  {
    // kf you didn't get a connection to the server:
    Serial.println("connection failed");
  }
}
// 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 
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);

}
Example #9
0
void CosmClient::sendData(uint32_t feedId, char datastreamId[], double dataToSend)
{
    if (_client.connect("api.cosm.com", 80)) {
        Serial.println("Connecting to Cosm...");

        _client.print("PUT /v2/feeds/");
        _client.print(feedId);
        _client.print("/datastreams/");
        _client.print(datastreamId);
        _client.print(".csv HTTP/1.1\n");
        _client.print("Host: api.cosm.com\n");

        _client.print("X-ApiKey: ");
        _client.print(_api);
        _client.print("\n");
        _client.print("Content-Length: ");

        int lengthOfData = getLength(dataToSend);
        _client.println(lengthOfData, DEC);

        _client.print("Content-Type: text/csv\n");
        _client.println("Connection: close\n");

        _client.print(dataToSend, DEC);
    }
}
/*
 * 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 #11
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
Example #12
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 #13
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()) {
  }
}
Example #14
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="";

				}
			}
		}
	}
}
Example #15
0
void printHeader() {

  client.println("HTTP/1.1 200 OK");
  client.println("Content-Type: application/json");
  client.println("Connnection: close");
  client.println();
  client.println("{");

}
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 #17
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();
}
Example #18
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");
  }
}
// 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() {
  // 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);
  }

}
// This method makes an HTTP connection to the server
void httpRequest(String link) {
	//if there is a successful connection
	if (client.connect(server, 80)) {
		client.println("Get " + link + " HTTP/1.0 ");
		client.println();

	} else {
		// You couldn't make the connection
		Serial.println("Connection Failed");
		Serial.println("Disconnecting.");
	}
		client.stop(); }
Example #22
0
void connectToServer() {
  // attempt to connect, and wait a millisecond:
  Serial.println("connecting to server...");
  if (client.connect(serverName, 80)) {
    Serial.println("making HTTP request...");
    // make HTTP GET request to twitter:
    client.println("GET /1/statuses/user_timeline.xml?screen_name=arduino&count=1 HTTP/1.1");
    client.println("HOST: api.twitter.com");
    client.println();
  }
  // note the time of this connect attempt:
  lastAttemptTime = millis();
}   
Example #23
0
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();
}
Example #24
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"));
}
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 #26
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...");
    }
}
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();
    }
}
Example #28
0
void Nimbits::doGet(EthernetClient client, String service, String content) {

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

    client.println();
    client.println();
}
Example #29
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 #30
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;
}