本文整理汇总了C++中EthernetClient::print方法的典型用法代码示例。如果您正苦于以下问题:C++ EthernetClient::print方法的具体用法?C++ EthernetClient::print怎么用?C++ EthernetClient::print使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EthernetClient
的用法示例。
在下文中一共展示了EthernetClient::print方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: loop
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");
}
}
示例2: serverRequest
//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;
}
}
示例3: createPoint
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();
}
}
示例4: sendData
// 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();
}
示例5: loop
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);
}
示例6: listenServer
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");
}
}
示例7: writeAuthParamsToClient
void Nimbits::writeAuthParamsToClient(EthernetClient client)
{
client.print(F("email="));
client.print(_ownerEmail);
if (_accessKey.length() > 0)
{
client.print(F("&key="));
client.print(_accessKey);
}
}
示例8: writeHostToClient
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();
}
示例9: read
// 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
示例10: sendValues
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...");
}
}
示例11: sendData
/*
* 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");
}
}
示例12: loop
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();
}
}
示例13: recordValue
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;
}
示例14: getValue
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;
}
}
示例15: updateDB_Door
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();
}