Last active
June 27, 2019 07:46
-
-
Save sarthakpranesh/c395497de8853274df553c6a2950ccc7 to your computer and use it in GitHub Desktop.
Code for sending data to thinkspeak
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 wifi = require("Wifi"); | |
var http = require("http"); | |
wifi.setHostname("nodeMCU-espruino"); | |
wifi.connect(YourSSID, {password: YourPassWord}, function(err){ | |
setTimeout(function(){ | |
if(err !== null){ | |
console.log("Unable to connect"); | |
return; | |
} | |
console.log("Info: ", wifi.getIP()); | |
digitalWrite(NodeMCU.D4, 0); | |
}, 2000); | |
}); | |
wifi.stopAP(); | |
wifi.save(); | |
var temp = 0; | |
setInterval(function(){ | |
http.get(YourUpdateFeed + temp, function(res){ | |
res.on('data', function(data){ | |
console.log("Data: ", data); | |
}); | |
res.on('close', function(){ | |
console.log("Temperature Sent"); | |
}); | |
}).on('error', function(e){ | |
console.log("Error: ", e); | |
}); | |
if(temp>=99){ | |
temp = 0; | |
} | |
temp = temp + 1; | |
}, 20000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment