Last active
September 25, 2018 23:25
-
-
Save wolfiex/3074ee5333ccfdc08c9c313c9719904f to your computer and use it in GitHub Desktop.
NodeMCU boiler
This file contains hidden or 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
/** | |
* are we currently running ? publish as everyone even anonymous | |
*/ | |
function doGet() { | |
var currentTime = new Date(); | |
var calendarId = '[email protected]'; | |
var optionalArgs = { | |
timeMin: (new Date(currentTime.getTime()-(2*3600*1000))).toISOString(), | |
timeMax: (new Date(currentTime.getTime()+(2*3600*1000))).toISOString(),//pm 2 h | |
showDeleted: false, | |
singleEvents: true, | |
maxResults: 10, | |
orderBy: 'startTime' | |
}; | |
var on = '0'; | |
var response = Calendar.Events.list(calendarId, optionalArgs); | |
var events = response.items; | |
if (events.length > 0) { | |
for (i = 0; i < events.length; i++) { | |
var event = events[i]; | |
var when = event.start.dateTime; | |
//Logger.log('%s (%s)', currentTime,event.summary); | |
if (new Date(event.start.dateTime) < currentTime){ | |
if (new Date(event.end.dateTime) > currentTime){ | |
on='1'; | |
//Logger.log('aaaaaa %s %s %s (%s)', currentTime,event.end.dateTime, event.start.dateTime,event.summary); | |
}; | |
} | |
} | |
} else { | |
Logger.log('No upcoming events found.'); | |
} | |
return ContentService.createTextOutput(on) | |
} |
This file contains hidden or 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
/********* | |
Dan Ellis | |
*********/ | |
#include <WiFiClientSecureRedirect.h> | |
#include <ESP8266WiFi.h> //ESP8266 Core WiFi Library (you most likely already have this in your sketch) | |
#include <DNSServer.h> //Local DNS Server used for redirecting all requests to the configuration portal | |
#include <ESP8266WebServer.h> //Local WebServer used to serve the configuration portal | |
#include <WiFiManager.h> //https://github.com/tzapu/WiFiManager WiFi Configuration Magic | |
//Network! | |
WiFiManager wifiManager; | |
//first parameter is name of access point, second is the password | |
int i = 0 ; | |
const char* url ="http://script.googleusercontent.com/macros/s/AKfycbzDQSX8cDeFs812jak1L6dbOccK1cIS0iIRI9oKj20dNNDF1Uk/exec"; | |
// fetch events from Google Calendar | |
char const * const dstHost = "script.google.com"; | |
char const * const dstPath = "/macros/s/AKfycbzDQSX8cDeFs812jak1L6dbOccK1cIS0iIRI9oKj20dNNDF1Uk/exec"; // ** UPDATE ME ** | |
int const dstPort = 443; | |
int32_t const timeout = 5000; | |
// On a Linux system with OpenSSL installed, get the SHA1 fingerprint for the destination and redirect hosts: | |
// echo -n | openssl s_client -connect script.google.com:443 2>/dev/null | openssl x509 -noout -fingerprint | cut -f2 -d'=' | |
// echo -n | openssl s_client -connect script.googleusercontent.com:443 2>/dev/null | openssl x509 -noout -fingerprint | cut -f2 -d'=' | |
char const * const dstFingerprint = "2A:AB:40:E7:AC:95:BE:8C:A4:54:91:FD:7E:C0:70:05:C6:EC:58:80"; | |
char const * const redirFingerprint = "AF:A2:C1:9F:67:58:7F:75:A9:03:71:C4:DE:7E:66:8E:A9:75:22:A5"; | |
#define DEBUG | |
#ifdef DEBUG | |
#define DPRINT(...) Serial.print(__VA_ARGS__) | |
#define DPRINTLN(...) Serial.println(__VA_ARGS__) | |
#else | |
#define DPRINT(...) //now defines a blank line | |
#define DPRINTLN(...) //now defines a blank line | |
#endif | |
// Assign output variables to GPIO pins | |
const int temp_up = D2; | |
const int temp_down = D1; | |
const int clickdelay = 400; | |
// Set web server port number to 80 | |
WiFiServer server(80); | |
void setup() { | |
Serial.begin(115200); | |
// Initialize the output variables as outputs | |
pinMode(temp_up, INPUT); | |
pinMode(temp_down, INPUT); | |
pinMode(LED_BUILTIN, OUTPUT); | |
// Set outputs to LOW | |
//digitalWrite(temp_up, HIGH); | |
//digitalWrite(temp_down, HIGH); | |
wifiManager.autoConnect("FoxyHouse","31francisstreet"); | |
// Connect to Wi-Fi network with SSID and password | |
Serial.print("Connecting to "); | |
//Serial.println(ssid); | |
//WiFi.begin(ssid, password); | |
while (WiFi.status() != WL_CONNECTED) { | |
delay(500); | |
Serial.print("."); | |
} | |
// Print local IP address and start web server | |
Serial.println(""); | |
Serial.println("WiFi connected."); | |
Serial.println("IP address: "); | |
Serial.println(WiFi.localIP()); | |
server.begin(); | |
} | |
void loop(){ | |
DPRINT("Free heap .. "); DPRINTLN(ESP.getFreeHeap()); | |
bool error = true; | |
WiFiClientSecureRedirect client; | |
DPRINT("Check if on "); | |
do { | |
DPRINT("."); | |
if (client.connect(dstHost, dstPort) != 1) { // send connect request | |
off(); | |
break; | |
} | |
DPRINT("."); | |
while (!client.connected()) { // wait until connected | |
client.tick(); | |
} | |
DPRINT("."); | |
if (client.request(dstPath, dstHost, 2000, dstFingerprint, redirFingerprint) != 0) { // send alarm request | |
break; | |
} | |
DPRINT("."); | |
while (!client.response()) { // wait until host responded | |
client.tick(); | |
} | |
DPRINT(".\n<RESPONSE>\n"); | |
while (client.available()) { // read and print until end of data | |
String line = client.readStringUntil('\n'); | |
Serial.println(line); | |
if (line =="1") | |
{DPRINT("turn on");on();digitalWrite(LED_BUILTIN, LOW);} | |
else | |
{DPRINT("turn off");off();digitalWrite(LED_BUILTIN, HIGH);}; | |
} | |
DPRINT("</RESPONSE>"); | |
client.stop(); | |
error = false; | |
} while (0); | |
DPRINTLN(error ? " error" : " done"); | |
delay(300000); //Send a request every 30 seconds | |
} | |
int off(){ | |
Serial.println(" off"); | |
for (i = 0; i < 20; i++) { | |
pinMode(temp_down, OUTPUT); | |
digitalWrite(temp_down, LOW); | |
delay(clickdelay); | |
pinMode(temp_down, INPUT); | |
//digitalWrite(temp_down, HIGH); | |
}; | |
delay(1000); | |
for (i = 0; i <4; i++) { | |
pinMode(temp_up, OUTPUT); | |
digitalWrite(temp_up, LOW); | |
delay(clickdelay); | |
pinMode(temp_up, INPUT); | |
} | |
return 1; | |
}; | |
int on(){ | |
Serial.println(" on"); | |
for (i = 0; i < 20; i++) { | |
pinMode(temp_up, OUTPUT); | |
digitalWrite(temp_up, LOW); | |
delay(clickdelay); | |
pinMode(temp_up, INPUT); | |
//digitalWrite(temp_down, HIGH); | |
}; | |
delay(1000); | |
for (i = 0; i <4; i++) { | |
pinMode(temp_down, OUTPUT); | |
digitalWrite(temp_down, LOW); | |
delay(clickdelay); | |
pinMode(temp_down, INPUT); | |
} | |
return 1; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment