Instantly share code, notes, and snippets.

Embed
What would you like to do?
//*****************************
// Create By xzenzza_ping //
// KhonKaen Maker Club //
//*****************************
#include "ESP8266WiFi.h"
#define Sensor A0
int value;
const unsigned long DEEP_SLEEP_MIN = 15;
#define DEBUG 0
// WiFi parameters
const char* ssid = "---YOUR SSID---";
const char* password = "---YOUR Password---";
// Host
const char* host = "dweet.io";
void setup() {
// Start Serial
Serial.begin(115200);
delay(10);
//pinMode(LED, OUTPUT);
pinMode(Sensor, INPUT);
// We start by connecting to a WiFi network
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}
void loop() {
// delay(1000);
// ++value;
Serial.print("Connecting to ");
Serial.println(host);
// Use WiFiClient class to create TCP connections
WiFiClient client;
const int httpPort = 80;
if (!client.connect(host, httpPort)) {
Serial.println("connection failed");
return;
}
// Reading
value = analogRead(Sensor);
Serial.println(value);
// This will send the request to the server
client.print(String("GET /dweet/for/YourThinkName?Door=") + String(value) + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"Connection: close\r\n\r\n");
delay(10);
// Read all the lines of the reply from server and print them to Serial
while(client.available()){
String line = client.readStringUntil('\r');
Serial.print(line);
}
Serial.println();
Serial.println("closing connection");
// Repeat every 10 seconds
delay(1000);
if(DEBUG){
Serial.println("--Deep Sleep--");
}
ESP.deepSleep(DEEP_SLEEP_MIN*60*1000000L,WAKE_RF_DEFAULT);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment