-
-
Save sarasantos/446edb4a6dc64a372f669a766108a04e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Arduino.h> | |
#include <WiFi.h> | |
#include <HTTPClient.h> | |
const char* ssid = "YOUR-SSID"; | |
const char* password = "PASSWORD"; | |
//Your Domain name with URL path or IP address with path | |
const char* serverName = "https://hooks.zapier.com/hooks/catch/8851494/oqxvbqm/"; | |
// the following variables are unsigned longs because the time, measured in | |
// milliseconds, will quickly become a bigger number than can be stored in an int. | |
unsigned long lastTime = 0; | |
// Timer set to 10 minutes (600000) | |
//unsigned long timerDelay = 600000; | |
// Set timer to 5 seconds (5000) | |
unsigned long timerDelay = 5000; | |
void setup() { | |
Serial.begin(115200); | |
WiFi.begin(ssid, password); | |
Serial.println("Connecting"); | |
while(WiFi.status() != WL_CONNECTED) { | |
delay(500); | |
Serial.print("."); | |
} | |
Serial.println(""); | |
Serial.print("Connected to WiFi network with IP Address: "); | |
Serial.println(WiFi.localIP()); | |
Serial.println("Timer set to 5 seconds (timerDelay variable), it will take 5 seconds before publishing the first reading."); | |
} | |
void loop() { | |
//Send an HTTP POST request | |
if ((millis() - lastTime) > timerDelay) { | |
//Check WiFi connection status | |
if(WiFi.status()== WL_CONNECTED){ | |
HTTPClient http; | |
// Your Domain name with URL path or IP address with path | |
http.begin(serverName); | |
int number = random(10); | |
// Specify content-type header | |
//http.addHeader("Content-Type", "application/x-www-form-urlencoded"); | |
// Data to send with HTTP POST | |
//String httpRequestData = "Test1="+String(number)+"&Test2=49.54"; | |
// Send HTTP POST request | |
//int httpResponseCode = http.POST(httpRequestData); | |
// If you need an HTTP request with a content type: application/json, use the following: | |
http.addHeader("Content-Type", "application/json"); | |
int httpResponseCode = http.POST("{\"Time\":\"12:24\",\"OutsideTemp\":\"12\",\"T9.0\": \"12.1\",\"Th9.0\":\"30\",\"H9.0\": \"90%\",\"T9.1\":\"13\",\"H9.1\":\"80\",\"9.1Weight\":\"67.03\"}"); | |
// If you need an HTTP request with a content type: text/plain | |
//http.addHeader("Content-Type", "text/plain"); | |
//int httpResponseCode = http.POST("Hello, World!"); | |
Serial.print("HTTP Response code: "); | |
Serial.println(httpResponseCode); | |
// Free resources | |
http.end(); | |
} | |
else { | |
Serial.println("WiFi Disconnected"); | |
} | |
lastTime = millis(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment