I have some beginner's doubts and I wanted to help you. I created a Residential Automation, based on Microcontroller + Node.js + Angular.js.
Communication of the Angular.js with the Microcontroller is OK. But I will also do the reverse. In which the MIC will send a POST command to the Node.js, more or less with this parameter:
router.post('/Saidas', function(req,res) {
saida = req.body.atuador;
estado = req.body.estado;
final = saida + estado;
res.send('Enviado = Saida: ' + saida + '; Estado: ' + estado);
});
And later I will send to the HTML site, via Angular.js with this command:
router.get('/SaidasSite', function(req,res){
res.send(final);
});
** Above is in the path.js code for Node.js.
However, in my Angular.js, I made the following code:
<script>
var app = angular.module('Saidas',[]);
app.controller('Status', function($scope, $http, $interval) {
$interval(function(){
var request = $http.get('/SaidasSite');
request.success(function(data) {
if (data='QTD1LEDON') {
$('#QTD1LAMP').bootstrapToggle('on');
} else (data='QTDLEDOFF'){
$('#QTD1LAMP').bootstrapToggle('off');
} else (data='QTD2LEDON'){
$('#QTD2LAMP').bootstrapToggle('on')
} else { $('#QTD1LAMP').bootstrapToggle('on'); }
})
.error(function(data){
console.log('Error: ' + data);
});
}, 5000);
/* O segundo parâmetro "5000", diz que a função deve ser repetida a cada
5000 milisegundos (5 segundos) */
});
</script>
My idea is this: When I send the "QTD1LEDON" command to the POST / Outputs command, it sends the command to the Node.js and afterwards the site will receive the GET command with that value (GET / SaidasSite ) and hit a button according to the string it received.
Ex: QTD1LED button ON ON - > QTDLEDON - > Activate "Bootstrap Toogle" button.
I'm not finding the best way to do this. This process is not working. In this code, it always fires the "QTD1LEDON".
Would you have a better way to fix this code or implement another process? Thanks!