meta données pour cette page
  •  

Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Les deux révisions précédentesRévision précédente
Prochaine révision
Révision précédente
esp8266_http [2016/10/11 08:27] Alexandre Castonguayesp8266_http [2016/10/11 08:39] (Version actuelle) Alexandre Castonguay
Ligne 15: Ligne 15:
  
 {{::adafruit_products_screen_shot_2015-07-23_at_12.20.12_pm.png?200|}} {{::adafruit_products_screen_shot_2015-07-23_at_12.20.12_pm.png?200|}}
 +
 +Dans Arduino, sélectionnez 'D1 mini' dans la liste des cartes; 115200 Bauds pour la vitesse de transfert 
 +
 +Pour aller lire une page web.
 +
 +<sxh>
 +
 +/*
 +  Simple client HTTP 'get'
 + */
 +
 +#include <ESP8266WiFi.h>
 +
 +const char* ssid     = "mon point d'accès";
 +const char* password = "son mot de passe";
 +
 +const char* host = "artengine.ca";
 +
 +void setup() {
 +  Serial.begin(115200);
 +  delay(100);
 +
 +  // We start by connecting to a WiFi network
 +
 +  Serial.println();
 +  Serial.println();
 +  Serial.print("Connecting to ");
 +  Serial.println(ssid);
 +  
 +  WiFi.begin(ssid, password);
 +  
 +  while (WiFi.status() != WL_CONNECTED) {
 +    delay(500);
 +    Serial.print(".");
 +  }
 +
 +  Serial.println("");
 +  Serial.println("WiFi connected");  
 +  Serial.println("IP address: ");
 +  Serial.println(WiFi.localIP());
 +}
 +
 +int value = 0;
 +
 +void loop() {
 +  delay(5000);
 +  ++value;
 +
 +  Serial.print("connecting to ");
 +  Serial.println(host);
 +  
 +  // Use WiFiClient class to create TCP connections
 +  WiFiClient client;
 +  const int httpPort = 80;
 +  if (!client.connect(host, httpPort)) {
 +    Serial.println("connection failed");
 +    return;
 +  }
 +  
 +  // We now create a URI for the request
 +  String url = "/acastonguay/AVM3301/wemos/index.html";
 +  Serial.print("Requesting URL: ");
 +  Serial.println(url);
 +  
 +  // This will send the request to the server
 +  client.print(String("GET ") + url + " HTTP/1.1\r\n" +
 +               "Host: " + host + "\r\n"
 +               "Connection: close\r\n\r\n");
 +  delay(500);
 +  
 +  // Read all the lines of the reply from server and print them to Serial
 +  while(client.available()){
 +    String line = client.readStringUntil('\r');
 +    Serial.print(line);
 +  }
 +  
 +  Serial.println();
 +  Serial.println("closing connection");
 +}
 +</sxh>
 +
 +