-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLog_Data_into_Google_Sheets_using_IFTTT_and_NodeMCU.ino
76 lines (62 loc) · 2.04 KB
/
Log_Data_into_Google_Sheets_using_IFTTT_and_NodeMCU.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include <ESP8266WiFi.h>
long i;
String Mystring;
WiFiClient client;
String MakerIFTTT_Key ;
;String MakerIFTTT_Event;
char *append_str(char *here, String s) { int i=0; while (*here++ = s[i]){i++;};return here-1;}
char *append_ul(char *here, unsigned long u) { char buf[20]; return append_str(here, ultoa(u, buf, 10));}
char post_rqst[256];char *p;char *content_length_here;char *json_start;int compi;
void setup()
{
i = 0;
Mystring = "";
Serial.begin(9600);
WiFi.disconnect();
delay(3000);
Serial.println("START");
WiFi.begin("xxxxxxxxxx","xxxxxxxxxx");
while ((!(WiFi.status() == WL_CONNECTED))){
delay(300);
Serial.print(".");
}
Serial.println("Connected");
Serial.println("Your IP is");
Serial.println((WiFi.localIP().toString()));
}
void loop()
{
i = (random(0,100));
Mystring = i;
if (client.connect("maker.ifttt.com",80)) {
MakerIFTTT_Key ="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
MakerIFTTT_Event ="sheets";
p = post_rqst;
p = append_str(p, "POST /trigger/");
p = append_str(p, MakerIFTTT_Event);
p = append_str(p, "/with/key/");
p = append_str(p, MakerIFTTT_Key);
p = append_str(p, " HTTP/1.1\r\n");
p = append_str(p, "Host: maker.ifttt.com\r\n");
p = append_str(p, "Content-Type: application/json\r\n");
p = append_str(p, "Content-Length: ");
content_length_here = p;
p = append_str(p, "NN\r\n");
p = append_str(p, "\r\n");
json_start = p;
p = append_str(p, "{\"value1\":\"");
p = append_str(p, Mystring);
p = append_str(p, "\",\"value2\":\"");
p = append_str(p, "");
p = append_str(p, "\",\"value3\":\"");
p = append_str(p, "");
p = append_str(p, "\"}");
compi= strlen(json_start);
content_length_here[0] = '0' + (compi/10);
content_length_here[1] = '0' + (compi%10);
client.print(post_rqst);
Serial.println("Value sent to Google Sheets");
Serial.println(i);
}
delay(20000);
}