HttpClient

Bir Yún cihazı için bu örnek, internete bağlanan ve içerik indiren temel bir HTTP istemcisinin nasıl oluşturulduğunu gösterir. Bu durumda, Arduino web sitesinde ASCII metni olarak indirirsiniz.

Kartı programından sonra IDE'de Seri Monitörü açın.

Gerekli Donanım

  • Yún kartı veya kalkan
  • internete kablosuz ağ bağlantısı

devre

Bu örnek için devre yok.

Kod

Hem Bridge hem de HttpClient kitaplıklarını dahil edin

#include <Bridge.h>
#include <HttpClient.h>
[Kodu Al]

setup() Bridge'i gerektirir ve loop() bir girmeden önce seri bağlantıyı bekliyoruz.

void setup ( ) {
pinMode ( 13 , ÇIKIŞ ) ;
digitalWrite ( 13 , DÜŞÜK ) ;
Köprü. begin ( ) ;
Seri . başlar ( 9600 ) ;
süre ( ! Seri ) ;
}

loop() , adlandırılmış Bir HttpClient Örneği oluşturun ettik client.get(url) ile Bir URL client.get(url) .

void loop ( ) {
HttpClient istemcisi ;
istemcisi. get ( "http://www.arduino.cc/asciilogo.txt" ) ;

İstemci arabelleğindeki sunucudan bayt olduğuna göre baytları okuyun ve seri monitöre yazdırın. Her 5 saniyede bir tekrarlayın.

while ( müşteri. kullanılabilir ( ) ) {
char c = istemci. read ( ) ;
Seri . baskı ( c ) ;
}
Seri . flush ( ) ;

gecikme ( 5000 ) ;
}

Çizimin listesinde aşağıdakidır:


 /* Yún HTTP Client This example for the YunShield/Yún shows how create a basic HTTP client that connects to the internet and downloads content. In this case, you'll connect to the Arduino website and download a version of the logo as ASCII text. created by Tom igoe May 2013 This example code is in the public domain. http://www.arduino.cc/en/Tutorial/HttpClient */ #include #include void setup() { // Bridge takes about two seconds to start up // it can be helpful to use the on-board LED // as an indicator for when it has initialized pinMode(13, OUTPUT); digitalWrite(13, LOW); Bridge.begin(); digitalWrite(13, HIGH); SerialUSB.begin(9600); while (!SerialUSB); // wait for a serial connection } void loop() { // Initialize the client library HttpClient client; // Make a HTTP request: client.get("http://www.arduino.cc/asciilogo.txt"); // if there are incoming bytes available // from the server, read them and print them: while (client.available()) { char c = client.read(); SerialUSB.print(c); } SerialUSB.flush(); delay(5000); }  /* Yún HTTP Client This example for the YunShield/Yún shows how create a basic HTTP client that connects to the internet and downloads content. In this case, you'll connect to the Arduino website and download a version of the logo as ASCII text. created by Tom igoe May 2013 This example code is in the public domain. http://www.arduino.cc/en/Tutorial/HttpClient */ #include #include void setup() { // Bridge takes about two seconds to start up // it can be helpful to use the on-board LED // as an indicator for when it has initialized pinMode(13, OUTPUT); digitalWrite(13, LOW); Bridge.begin(); digitalWrite(13, HIGH); SerialUSB.begin(9600); while (!SerialUSB); // wait for a serial connection } void loop() { // Initialize the client library HttpClient client; // Make a HTTP request: client.get("http://www.arduino.cc/asciilogo.txt"); // if there are incoming bytes available // from the server, read them and print them: while (client.available()) { char c = client.read(); SerialUSB.print(c); } SerialUSB.flush(); delay(5000); }  /* Yún HTTP Client This example for the YunShield/Yún shows how create a basic HTTP client that connects to the internet and downloads content. In this case, you'll connect to the Arduino website and download a version of the logo as ASCII text. created by Tom igoe May 2013 This example code is in the public domain. http://www.arduino.cc/en/Tutorial/HttpClient */ #include #include void setup() { // Bridge takes about two seconds to start up // it can be helpful to use the on-board LED // as an indicator for when it has initialized pinMode(13, OUTPUT); digitalWrite(13, LOW); Bridge.begin(); digitalWrite(13, HIGH); SerialUSB.begin(9600); while (!SerialUSB); // wait for a serial connection } void loop() { // Initialize the client library HttpClient client; // Make a HTTP request: client.get("http://www.arduino.cc/asciilogo.txt"); // if there are incoming bytes available // from the server, read them and print them: while (client.available()) { char c = client.read(); SerialUSB.print(c); } SerialUSB.flush(); delay(5000); } 

See Also

  • Bridge Library- Köprü Kütüphanesine referansınız
  • Bridge- Analog ve dijital pinlere erişmek için basit REST tarzı çağrılar
  • Console Ascii Table- Konsola yazdırılan eksiksiz bir ASCII tablosu
  • Console Pixel- Konsoldan bir LED'i açma ve kapatma
  • Console Read- Console.read () işlevini kullanarak köprüden gelen verileri okuma
  • Data Logger- Üç analog sensörden bir SD karta veri kaydedin.
  • File Write- Dosya Yún dosya sistemine nasıl yazılır.
  • Http Client Console- Bağlanan, içeriği indiren ve WiFi ve Konsol kullanarak içeriği gösteren HTTP istemcisi.
  • Mailbox Read Message- Köprü kitaplığını kullanarak Posta Kutusu adlı ileti sırasını okuma.
  • Process- Bir Yún kullanarak linux süreçleri nasıl çalıştırılır.
  • Remote Due Blink- DUE panolarına uzaktan taslak yükleme.
  • Shell Commands- Bir Yún kullanarak linux kabuk komutları nasıl çalıştırılır.
  • Temperature Web Panel- Yún'ın yerleşik web sunucusu üzerinden bir analog girişten veri sunma.
  • Time check- Bridge üzerinden Linux'tan zamanı alır, sonra saatleri, dakikaları ve saniyeleri ayrıştırır.
  • WiFi Status- Wifi bağlantınızın durumu hakkında bilgi yazdırır.
  • Yún First Configuration- Seri Monitör ve USB bağlantı noktasını kullanarak Yún cihazınızı kolayca yapılandırın.
  • Serial Terminal- Yún'ın 32U4 işlemcisini, Yún'daki Linux tarafı için seri terminal olarak kullanın.