<commit_before>var gpio = require('pi-gpio');

gpio.open(11, "output", function(err) {
  gpio.write(11, 1, function(err) {
    gpio.close(11);
  });
});<commit_msg>Apparently working version of long-polling client<commit_after>var http = require('http');
var gpio = require('pi-gpio');
var currentState = false;

var actuator = function(outputValue) {
  console.log('Switching relay: '+outputValue);
  currentState = outputValue;
  gpio.open(11, "output", function(err) {
    gpio.write(11, outputValue, function(err) {
      gpio.close(11);
    });
  });
};

var doPollingReq = function() {
  console.log('Starting request...');
  var pollingReqOpts = {
    host: 'localhost',
    port: 3000,
    path: '/alarm',
    method: 'GET'
  };
  var pollingReq = http.request(pollingReqOpts, function(res) {
    res.on('data', function(data) {
      console.log('Got data: '+data);
      var objData = JSON.parse(data);
      if (objData) {
        if (objData.value == true) {
          actuator(true);
        } else if (objData.value == false) {
          actuator(false);
        }
      }
    });
    res.on('close', doPollingReq);
    res.on('finish', doPollingReq);
  });
};

setImmediate(doPollingReq);
{'fraction_non_alphanumeric': 0.17040731504571904, 'fraction_numerical': 0.014131338320864505, 'mean_word_length': 3.23943661971831, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2912024', 'n_tokens_mistral': 432, 'n_tokens_neox': 404, 'n_words': 82}