Created
September 8, 2016 00:48
-
-
Save yoshimov/817fd49446b7b812cc2069f0e244a0a3 to your computer and use it in GitHub Desktop.
Light sensor script for Espruino on ESP8266
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
var http = require("http"); | |
var pre = 0; | |
var count = 0; | |
var MAX = 50; | |
var TIMEOUT = 100; | |
var POSTURL="http://dweet.io/dweet/for/xxx"; | |
var NOTIFYURL="http://auto-remote-url"; | |
function loop() { | |
// 0 < val < 1 | |
var val = analogRead(); | |
// if the light is on | |
if (val > pre+0.2 || count++ > MAX) { | |
var url = POSTURL + "?light=" + val; | |
http.get(url); | |
if (val > pre+0.2) { | |
http.get(NOTIFYURL); | |
console.log("sent notification"); | |
} | |
count = 0; | |
} | |
pre = val; | |
} | |
var wifi=require("Wifi"); | |
function onInit() { | |
wifi.connect("ssid", {password:"password"}); | |
wifi.stopAP(); | |
setInterval(loop, TIMEOUT); | |
} | |
onInit(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment