You are reading a single comment by @Kolban and its replies.
Click here to read the full conversation.
-
Thank you for taking the time to look into this. Here is the code:
var pinButton = NodeMCU.D3; var pinLed = NodeMCU.D7; var pinRelay = NodeMCU.D6; var statusRelay = false; var statusAlarm = null; var statusAlarmRunning = false; // Initalisation of pins var initializePins = function() { console.log("Initialize pins..."); pinMode(pinRelay, "output"); pinMode(pinButton, "input"); pinMode(pinLed, 'output'); }; var initializeButton = function() { setWatch( longButtonPress, pinButton, { repeat:true, debounce: 2000, edge:"falling"} ); setWatch( buttonPressed, pinButton, { repeat:true, debounce: 70, edge:"falling"} ); }; var buttonPressed = function() { console.log("short press"); statusRelay = !statusRelay; digitalWrite(pinRelay, statusRelay); digitalWrite(pinLed,!statusRelay); }; var longButtonPress=function(){ console.log('long press'); // ESP8266.reboot(); }; function init() { initializeButton(); initServer(); setInterval(function(){ console.log(process.memory()); }, 100000); require("ESP8266").setLog(2); } function playAlarm() { statusAlarmRunning = !statusAlarmRunning; console.log("Toggle relay: " + statusAlarmRunning); digitalWrite(pinRelay, statusAlarmRunning); } function initServer() { var http = require("http"); initializePins(); console.log("Initalizing server instance..."); http.createServer(function (req, res){ var request = url.parse(req.url, true); var action = request.query; if (action) { var target = ""; var setting = ""; for (var key in action){ if (action.hasOwnProperty(key)) { target = key.toLowerCase(); setting = action[key].toLowerCase(); if (statusAlarm !== null) { clearInterval(statusAlarm); statusAlarmRunning = false; statusAlarm = null; } switch(target) { case "switch" : if (setting === "on") { // switch relay on console.log("Switch relay ON"); digitalWrite(pinRelay, 1); digitalWrite(pinLed,0); break; } else if (setting === "off"){ // switch relay off console.log("Switch relay OFF"); digitalWrite(pinRelay, 0); digitalWrite(pinLed,1); break; } else if (setting === "toggle") { statusRelay = !statusRelay; console.log("Switch: Toggle to " + statusRelay); digitalWrite(pinRelay, (statusRelay === true) ? 1 : 0); digitalWrite(pinLed, (statusRelay === true) ? 0 : 1); break; } break; case "status" : console.log("Switch status: " + statusRelay); break; case "alarm" : if (!statusAlarm) { statusAlarm = setInterval(playAlarm, 300); } break; } } } target = null; setting = null; } res.writeHead(200); res.end("Hello World"); }).listen(8080); } E.on('init', function() { init();});
Would you be able to attach a file of your JavaScript source as edited in the Web IDE. I for one would be interested to load your program and have a go with dump().