Advertisement
rsbelza

Untitled

Feb 9th, 2023 (edited)
1,111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <ESP8266WiFi.h>
  2. #include <ESP8266HTTPClient.h>
  3. #include <WiFiClient.h>
  4.  
  5. const char* ssid = "converge-2.4g";
  6. const char* password = "Sierra911";
  7. //Your Domain name with URL path or IP address with path
  8. const char* serverName = "https://us-central1-floodmonitor-474e0.cloudfunctions.net/devices";
  9.  
  10. void setup() {
  11.   Serial.begin(115200);
  12.  
  13.   WiFi.begin(ssid, password);
  14.   Serial.println("Connecting");
  15.   while(WiFi.status() != WL_CONNECTED) {
  16.     delay(500);
  17.     Serial.print(".");
  18.   }
  19.   Serial.println("");
  20.   Serial.print("Connected to WiFi network with IP Address: ");
  21.   Serial.println(WiFi.localIP());
  22.  
  23.  
  24. }
  25.  
  26. void loop() {
  27.   WiFiClient client;
  28.   HTTPClient http;
  29.      
  30.   // Your Domain name with URL path or IP address with path
  31.   http.begin(client,servername);
  32.  
  33.      
  34.   // If you need an HTTP request with a content type: application/json, use the following:
  35.   http.addHeader("Content-Type", "application/json");
  36.   int httpResponseCode = http.POST("{\"deviceId\":\"3\",\"lat\":\"14.627656\",\"long\":\"121.070773\",\"waterLevel\":\"16\",\"flooded\":\"true\"}");
  37.      
  38.      
  39.   Serial.print("HTTP Response code: ");
  40.   Serial.println(httpResponseCode);
  41.        
  42.   // Free resources
  43.   http.end();
  44.   delay(5000);
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement