Nancy's Preferred Machete

    ds18b20-gpio-mock

    1.0.0 • Public • Published

    DS18B20 GPIO Mock

    NPM

    Build Status Coverage Status

    A DS18B20 module for GPIO Mock.

    Simulating DS18B20 digital thermometer

    let gpioMock = require('gpio-mock');
    let ds18b20 = require('mc-tempsensor');
    
    // Hardware definition for DS18B20;
    let f = {
      "behavior": "function",
      "temperature": function() {
        return Math.random() * 100000;
      }
    };
    
    gpioMock.start(function(err) {
      gpioMock.addMockHardwareModule('ds18b20', 'ds18b20.js', function(err) {
        if (!err) {
          gpioMock.addMockHardware('ds18b20', '28-800000263717', f, function(err) {
            if (!err) {
              tempsensor.init('28-800000263717');
          
              tempSensor.readAndParse(function(err, data) {
                if (err) {
                  // Handle error
                } else {
                  console.log('Temperature is ' + data[0].temperature.celcius + ' C');
                }
              });
            } else {
              callback(err);
            }
          });
        } else {
          callback(err);
        }
      });
    });
    

    Install

    npm i ds18b20-gpio-mock

    DownloadsWeekly Downloads

    1

    Version

    1.0.0

    License

    ISC

    Last publish

    Collaborators

    • ozsie