Created
November 26, 2018 10:49
-
-
Save li2hub/23fb637b4b8ca234e9c78b061dedfdcd 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 <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); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment