meta données pour cette page
Différences
Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
esp8266_http [2016/10/11 08:27] – Alexandre Castonguay | esp8266_http [2016/10/11 08:39] (Version actuelle) – Alexandre Castonguay | ||
---|---|---|---|
Ligne 15: | Ligne 15: | ||
{{:: | {{:: | ||
+ | |||
+ | 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> | ||
+ | |||
+ | /* | ||
+ | | ||
+ | */ | ||
+ | |||
+ | #include < | ||
+ | |||
+ | const char* ssid = "mon point d' | ||
+ | const char* password = "son mot de passe"; | ||
+ | |||
+ | const char* host = " | ||
+ | |||
+ | void setup() { | ||
+ | Serial.begin(115200); | ||
+ | delay(100); | ||
+ | |||
+ | // We start by connecting to a WiFi network | ||
+ | |||
+ | Serial.println(); | ||
+ | Serial.println(); | ||
+ | Serial.print(" | ||
+ | Serial.println(ssid); | ||
+ | | ||
+ | WiFi.begin(ssid, | ||
+ | | ||
+ | while (WiFi.status() != WL_CONNECTED) { | ||
+ | delay(500); | ||
+ | Serial.print(" | ||
+ | } | ||
+ | |||
+ | Serial.println("" | ||
+ | Serial.println(" | ||
+ | Serial.println(" | ||
+ | Serial.println(WiFi.localIP()); | ||
+ | } | ||
+ | |||
+ | int value = 0; | ||
+ | |||
+ | void loop() { | ||
+ | delay(5000); | ||
+ | ++value; | ||
+ | |||
+ | Serial.print(" | ||
+ | Serial.println(host); | ||
+ | | ||
+ | // Use WiFiClient class to create TCP connections | ||
+ | WiFiClient client; | ||
+ | const int httpPort = 80; | ||
+ | if (!client.connect(host, | ||
+ | Serial.println(" | ||
+ | return; | ||
+ | } | ||
+ | | ||
+ | // We now create a URI for the request | ||
+ | String url = "/ | ||
+ | Serial.print(" | ||
+ | Serial.println(url); | ||
+ | | ||
+ | // This will send the request to the server | ||
+ | client.print(String(" | ||
+ | " | ||
+ | " | ||
+ | delay(500); | ||
+ | | ||
+ | // Read all the lines of the reply from server and print them to Serial | ||
+ | while(client.available()){ | ||
+ | String line = client.readStringUntil(' | ||
+ | Serial.print(line); | ||
+ | } | ||
+ | | ||
+ | Serial.println(); | ||
+ | Serial.println(" | ||
+ | } | ||
+ | </ | ||
+ | |||
+ |