Skip to content

Instantly share code, notes, and snippets.

@Tech500
Created February 22, 2022 17:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Tech500/f73369f9e1ce4b2a781fbaf5edc17cea to your computer and use it in GitHub Desktop.
Save Tech500/f73369f9e1ce4b2a781fbaf5edc17cea to your computer and use it in GitHub Desktop.
//////////////////////////////////////////////////////////////////////////////////
//Hosted Domain, web page -code sends data for Dynamic web page every 15 Minutes
/////////////////////////////////////////////////////////////////////////////////
void webInterface()
{
gpslat = gps.location.lat();
gpslng = gps.location.lng();
char glat[10]; // Buffer big enough for 9-character float
dtostrf(gpslat, 9, 4, glat); // Leave room for too large numbers!
char glng[10]; // Buffer big enough for 9-character float
dtostrf(gpslng, 9, 4, glng); // Leave room for too large numbers!
char fahr[7];// Buffer big enough for 9-character float
dtostrf(temperature, 6, 1, fahr); // Leave room for too large numbers!
char heatindex[7];// Buffer big enough for 9-character float
dtostrf(heat, 6, 1, heatindex); // Leave room for too large numbers!
char humidity[7]; // Buffer big enough for 9-character float
dtostrf(hum, 6, 1, humidity); // Leave room for too large numbers!
char dewpoint[7]; // Buffer big enough for 9-character float
dtostrf(dew, 6, 1, dewpoint); // Leave room for too large numbers!
char barometric[9]; // Buffer big enough for 7-character float
dtostrf(currentPressure, 8, 3, barometric); // Leave room for too large numbers!
char diff[9]; // Buffer big enough for 7-character float
dtostrf(difference, 8, 3, diff); // Leave room for too large numbers!
char rain5[10]; // Buffer big enough for 9-character float
dtostrf(rain5min, 6, 3, rain5); // Leave room for too large numbers!
char rain60[10]; // Buffer big enough for 9-character float
dtostrf(rainHour, 6, 3, rain60); // Leave room for too large numbers!
char rain24[10]; // Buffer big enough for 9-character float
dtostrf(rainDay, 6, 3, rain24); // Leave room for too large numbers!
char alt[9]; // Buffer big enough for 9-character float
dtostrf(altFeet, 8, 1, alt); // Leave room for too large numbers!
String data = "&last=" + (String)lastUpdate
+ "&glat=" + glat
+ "&glng=" + glng
+ "&fahr=" + fahr
+ "&heatindex=" + heatindex
+ "&humidity=" + humidity
+ "&dewpoint=" + dewpoint
+ "&barometric=" + barometric
+ "&diff=" + diff
+ "&rain5=" + rain5
+ "&rain60=" + rain60
+ "&rain24=" + rain24
+ "&alt=" + alt;
if (WiFi.status() == WL_CONNECTED)
{
//Check WiFi connection status
HTTPClient http; //Declare object of class HTTPClient
http.begin(sendData); //Specify request destination
http.addHeader("Content-Type", "application/x-www-form-urlencoded"); //Specify content-type header
int httpCode = http.POST(data); //Send the request
String payload = http.getString(); //Get the response payload
if (httpCode == 200)
{
Serial.print("");
Serial.print("HttpCode: ");
Serial.print(httpCode); //Print HTTP return code
Serial.print(" Data echoed back from Hosted website " );
Serial.println("");
Serial.println(payload); //Print payload response
http.end(); //Close HTTPClient http
}
else
{
Serial.print("");
Serial.print("HttpCode: ");
Serial.print(httpCode); //Print HTTP return code
Serial.print(" Domain website data update failed. ");
Serial.println("");
http.end(); //Close HTTPClient http
}
}
else
{
Serial.println("Error in WiFi connection");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment