5 changed files with 54 additions and 5 deletions
@ -0,0 +1,30 @@ |
|||||
|
|
||||
|
void sendData() { |
||||
|
|
||||
|
if((WiFiMulti.run() == WL_CONNECTED)) { |
||||
|
|
||||
|
WiFiClient client; |
||||
|
HTTPClient http; |
||||
|
|
||||
|
char apiString[100] = ""; |
||||
|
sprintf_P(apiString, server, windDirection, windSpeed, temperature, humidity, pressure); |
||||
|
|
||||
|
Serial.print("[HTTP] begin...\n"); |
||||
|
if (http.begin(client, apiString)) { |
||||
|
Serial.print("[HTTP] GET...\n"); |
||||
|
int httpCode = http.GET(); |
||||
|
if (httpCode > 0) { |
||||
|
Serial.printf("[HTTP] GET... code: %d\n", httpCode); |
||||
|
if (httpCode == HTTP_CODE_OK || httpCode == HTTP_CODE_MOVED_PERMANENTLY) { |
||||
|
String payload = http.getString(); |
||||
|
Serial.println(payload); |
||||
|
} |
||||
|
} else { |
||||
|
Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str()); |
||||
|
} |
||||
|
http.end(); |
||||
|
} else { |
||||
|
Serial.printf("[HTTP} Unable to connect\n"); |
||||
|
} |
||||
|
} |
||||
|
} |
Loading…
Reference in new issue