Hi-
The three item maximum supported by IFTTT is not an option for me, so I have been looking into using Zapier. The zap seems to be good, but I can’t seem to figure exactly what the format is for the post to start the trigger. Any chance of adding this to the course?
The transition from Pro-mini to ESP32 has been relatively painless thanks to your courses. Congrats and Thanks!
john.crockett@videotron.ca
Hi.
I’ve just tried post data to google sheets with Zapier with success.
However, keep in mind that their free plan is limited to 1000 tasks per month (1000 data entries to google sheets).
Do you still want to use it? If yes, I can explain you how to use it.
Regards,
Sara
Sure. 1000 tasks will give me a reading every 40 minutes which will do. Better than trying to parse .csv data in GSheets. BTW, I can make the Zap work using Postman, but translating what postman does behind the scenes to Arduino IDE is beyond me!
Hi.
Can you show me the request?
This example code shows how to make a request using the ESP32:
https://raw.githubusercontent.com/RuiSantosdotme/Random-Nerd-Tutorials/master/Projects/ESP32/HTTP/ESP32_HTTP_POST.ino
Here’s the corresponding tutorial: https://randomnerdtutorials.com/esp32-http-get-post-arduino/
Insert the webhooks URL of your zapp on the serverName variable.
Tell me if you are able to do it, or if you need further help.
Regards,
Sara
Hi Sara-
Couldn’t get the HTTP_POST example to work.
Because of the Webhook, I’ve been using the framework from the “Publish Sensor Readings to Google Sheets” tutorial. I’m getting a response, but my spreadsheet is not being updated.
Start your code here
#include <WiFi.h>
#include <Wire.h>
const char* ssid = “homenet 2.4”;
const char* password = “jdc4mfbexXXXXX”;
const char* resource = “/hooks/catch/8851494/oqxvbqm/”;
const char* server = “hooks.zapier.com”;
//The Webhook URL I was given is: https://hooks.zapier.com/hooks/catch/8851494/oqxvbqm
void setup() {
Serial.begin(115200);
delay(2000);
initWifi();
makeZapierRequest();
}
void loop() {
}
void initWifi() {
Serial.print(“Connecting to: “);
Serial.print(ssid);
WiFi.begin(ssid, password);
int timeout = 10 * 4; // 10 seconds
while(WiFi.status() != WL_CONNECTED && (timeout– > 0)) {
delay(250);
Serial.print(“.”);
}
Serial.println(“”);
if(WiFi.status() != WL_CONNECTED) {
Serial.println(“Failed to connect, going back to sleep”);
}
Serial.print(“WiFi connected in: “);
Serial.print(millis());
Serial.print(“, IP address: “);
Serial.println(WiFi.localIP());
}
void makeZapierRequest() {
Serial.print(“Connecting to “);
Serial.print(server);
WiFiClient client;
int retries = 5;
while(!!!client.connect(server, 80) && (retries– > 0)) {
Serial.print(“.”);
}
Serial.println();
if(!!!client.connected()) {
Serial.println(“Failed to connect…”);
}
Serial.print(“Request resource: “);
Serial.println(resource);
String jsonObject = String (“{\”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\”}”);
client.println(String(“POST “) + resource + ” HTTP/1.1″);
client.println(String(“Host: “) + server);
client.println(“Connection: close\r\nContent-Type: application/json”);
client.print(“Content-Length: “);
client.println(jsonObject.length());
client.println();
client.println(jsonObject);
int timeout = 5 * 10; // 5 seconds
while(!!!client.available() && (timeout– > 0)){
delay(100);
}
if(!!!client.available()) {
Serial.println(“No response…”);
}
while(client.available()){
Serial.write(client.read());
}
Serial.println(“\nclosing connection”);
client.stop();
}
This is the output from the serial monitor.
12:11:36.838 -> Connecting to: homenet 2.4..
12:11:37.413 -> WiFi connected in: 2617, IP address: 192.168.0.179
12:11:37.448 -> Connecting to hooks.zapier.com/hooks/catch/8851494/oqxvbqm/HTTP Response code: -1
12:20:26.216 -> Connecting to: homenet 2.4.
12:20:26.527 -> WiFi connected in: 2366, IP address: 192.168.0.179
12:20:26.566 -> Connecting to hooks.zapier.com/hooks/catch/8851494/oqxvbqm/HTTP Response code: -1
12:20:51.178 -> Connecting to: homenet 2.4..
12:20:51.757 -> WiFi connected in: 2616, IP address: 192.168.0.179
12:20:51.757 -> Connecting to hooks.zapier.com
12:20:51.859 -> Request resource: /hooks/catch/8851494/oqxvbqm/
12:20:52.067 -> HTTP/1.1 308 Permanent Redirect
12:20:52.067 -> Content-Type: text/html
12:20:52.067 -> Date: Sat, 07 Nov 2020 17:20:51 GMT
12:20:52.067 -> Location: https://hooks.zapier.com/hooks/catch/8851494/oqxvbqm/
12:20:52.067 -> Strict-Transport-Security: max-age=31536000; includeSubDomains; preload
12:20:52.067 -> Content-Length: 168
12:20:52.067 -> Connection: Close
12:20:52.067 ->
12:20:52.067 -> <html>
12:20:52.067 -> <head><title>308 Permanent Redirect</title></head>
12:20:52.105 -> <body>
12:20:52.105 -> <center><h1>308 Permanent Redirect</h1></center>
12:20:52.105 -> <hr><center>openresty</center>
12:20:52.105 -> </body>
12:20:52.105 -> </html>
12:20:52.105 ->
12:20:52.105 -> closing connection
Hi.
Try the following code.
https://gist.github.com/sarasantos/446edb4a6dc64a372f669a766108a04e
Just insert your username and password.
Tell me if it works.
Regards,
Sara
‘Mornin’!
I get this:
11:49:34.056 -> Connecting
11:49:34.545 -> .
11:49:34.545 -> Connected to WiFi network with IP Address: 192.168.0.179
11:49:34.545 -> Timer set to 5 seconds (timerDelay variable), it will take 5 seconds before publishing the first reading.
11:49:38.941 -> HTTP Response code: -1
11:49:43.937 -> HTTP Response code: -1
11:49:48.932 -> HTTP Response code: -1
11:49:53.934 -> HTTP Response code: -1
11:49:58.921 -> HTTP Response code: -1
Funny that Postman generates a snippet of code in HTTP that looks just like what I have, but Postman connects and triggers the hook.(???)
Start your code here
POST /hooks/catch/8851494/oqxvbqm/ HTTP/1.1
Host: hooks.zapier.com
Content-Type: application/json
Content-Length: 185
{
“Time”: “11:31”,
“OutsideTemp”: “12”,
“T9.0”: “31”,
“Th9.0”: “30”,
“H9.0”: “90%”,
“T9.1”: “13”,
“TH9.1”: “12”,
“H9.1”: “80”,
“9.1Weight”: “67.03”
}
Hi.
There was an extra space in the serverName in the code I’ve sent you.
The code is fixed now and it should work.
https://gist.github.com/sarasantos/446edb4a6dc64a372f669a766108a04e
Regards,
Sara
Yahoo! It works! I’ll use this method, thanks. Just so I can understand, any idea what is wrong with the other method? ( the one similar to the IFTTT example)