<commit_before>var tessel = require('tessel');
var climatelib = require('climate-si7005');
var climate = climatelib.use(tessel.port['A']);
var http = require('http');

var readClimate = function () {
    
    var o = {};
  
    // get celsius temperature
    climate.readTemperature(function (err, tempC) {
        if (err) {
            console.log('TESSEL TEMP C ERROR');
            console.log(err);
            return;
        }

        var handicapF = 9.5; // subtract from reading b/c of heated climate module
    
        o.temp = {
            c: tempC.toFixed(2)
        };

        // get fahrenheit temperature (lazy, yes)
        climate.readTemperature('f', function (err, tempF) {
            if (err) {
                console.log('TESSEL TEMP F ERROR');
                console.log(err);
                return;
            }

            o.temp.f = tempF.toFixed(2);

            // get humidity
            climate.readHumidity(function (err, humid) {
                if (err) {
                    console.log('TESSEL HUMID ERROR');
                    console.log(err);
                    return;
                }

                o.humid = humid.toFixed(2);

                o.date = new Date();
                report(o);
            });
        })
    });
};

var report = function (o) {
    //console.log(o, "\n");
    saveToDb(o);
    setTimeout(readClimate, 15*1000);
};

var saveToDb = function (o) {
    // stringify data
    var postDataString = JSON.stringify(o);

    var headers = {
        'Content-Type': 'application/json',
        'Content-Length': postDataString.length
    };

    var options = {
        method : 'POST',
        host : '192.168.1.149',
        port : '3000',
        path : '/api/weather',
        headers: headers
    };

    // define POST request
    var request = http.request(options, function(res) {
        res.setEncoding('utf-8');
        var responseString = ''; 
        
        res.on('data', function(data) {
            responseString += data;
        });

        res.on('end', function() {
            console.log('data written to:', options.path, JSON.parse(responseString));
        });
    });

    // send POST request 
    request.write(postDataString);
    request.end();
};


climate.on('ready', readClimate);


<commit_msg>converted temp and humidity POST data from strings to numbers.<commit_after>var prefs = {
    decimalPlaces: 2,
    timeout: 5 * 1000,
    host: '192.168.1.149',
    port: 3000,
    path: '/api/weather'
}


var tessel = require('tessel');
var climatelib = require('climate-si7005');
var climate = climatelib.use(tessel.port['A']);
var http = require('http');

var readClimate = function () {
    
    var o = {};
  
    // get celsius temperature
    climate.readTemperature(function (err, tempC) {
        if (err) {
            console.log('TESSEL TEMP C ERROR');
            console.log(err);
            return;
        }
    
        o.temp = {};
        o.temp.c = tempC;
        
        // get fahrenheit temperature (lazy, yes)
        climate.readTemperature('f', function (err, tempF) {
            if (err) {
                console.log('TESSEL TEMP F ERROR');
                console.log(err);
                return;
            }

            o.temp.f = tempF;

            // get humidity
            climate.readHumidity(function (err, humid) {
                if (err) {
                    console.log('TESSEL HUMID ERROR');
                    console.log(err);
                    return;
                }

                o.humid = humid;

                o.date = new Date();
                report(o);
            });
        })
    });
};

var report = function (o) {
    saveToDb(o);
    setTimeout(readClimate, prefs.timeout);
};

var saveToDb = function (o) {
    // stringify data
    var postDataString = JSON.stringify(o);

    var headers = {
        'Content-Type': 'application/json',
        'Content-Length': postDataString.length
    };

    var options = {
        method : 'POST',
        host : prefs.host,
        port : prefs.port,
        path : prefs.path,
        headers: headers
    };

    // define POST request
    var request = http.request(options, function(res) {
        res.setEncoding('utf-8');
        var responseString = ''; 
        
        res.on('data', function(data) {
            responseString += data;
        });

        res.on('end', function() {
            console.log('data saved at:', o.date);
        });
    });

    // send POST request 
    request.write(postDataString);
    request.end();
};


climate.on('ready', readClimate);



{'fraction_non_alphanumeric': 0.1357142857142857, 'fraction_numerical': 0.011904761904761904, 'mean_word_length': 1.5858981533296026, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '3127186', 'n_tokens_mistral': 1442, 'n_tokens_neox': 1343, 'n_words': 300}