Skip to content

Instantly share code, notes, and snippets.

@sarthakpranesh
Last active June 27, 2019 07:46
Show Gist options
  • Save sarthakpranesh/c395497de8853274df553c6a2950ccc7 to your computer and use it in GitHub Desktop.
Save sarthakpranesh/c395497de8853274df553c6a2950ccc7 to your computer and use it in GitHub Desktop.
Code for sending data to thinkspeak
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