[SOLVED] Raspberry Pi (with) ds18b20 (temp sensor, stops after 6 readings)

So to avoid posting in the old topic “Beer thermometer with raspberry pi and ds18b20” i’m gonna ask my question here. I follow the instructions and my ds18b20 now works with my rpi2 but i only get 6 readings and then it stops.
Anyone experienced this issue ? I can’t seem to find anything about it on the web. This is what i get :OnOff mode

Connecting to: blynk-cloud.com 8441
SSL authorization…
Connected
Authorized
Actual temp: 23.937 °C
Actual temp: 23.875 °C
Actual temp: 23.875 °C
Actual temp: 24.125 °C
Actual temp: 24.937 °C
Actual temp: 26.687 °C

And this is the code :

var blynkLib = require(‘/usr/lib/node_modules/blynk-library’);
var W1Temp = require(‘/usr/lib/node_modules/w1temp’);
var AUTH = ‘MYTOKEN’;

// Setup Blynk (SSL)
var blynk = new blynkLib.Blynk(AUTH);

W1Temp.setGpioData(4);

// Automatically update sensors value every 5 minutes
setInterval(function() {
W1Temp.getSensor(‘28-8000000365a2’).then(function (sensor) {
// print actual temperature
var temp = sensor.getTemperature();
console.log(‘Actual temp:’, temp, ‘°C’);
//Report it to server
blynk.virtualWrite(0, temp);
});
}, 50000);

Anyone have any idea ?
Thanks

Did you wire it with a proper pull up resistor on the digital out line?

Yes 4.7K and its always exactly 6 readings i get, nothing more, nothing less.

Coding for a pi is far from my expertise, but a question this sensor object where is it declared?

I removed it to see what it does, and when i did i got exactly 6 errors saying sensor not defined so it seems like that is the definition.

Seems like your set interval is limited to 6 loops?

Yes it seems so but i have no clue how to change this as i don’t see where this is set.

What language is this? I’m not to familiar with it :stuck_out_tongue:

python

It’s not Python.

1 Like

What is it then and how do i fix it ?
(I was hoping to see you here ^^)

It’s JavaScript and I too had a similar issue with DSB1820 sensors on my Pi’s.

The problem is that the 50s loop simply doesn’t continue to run.

I think I modified the script to provide readings “on tempearature change” rather than at timed intervals.

1 Like

Yes i saw something like that.
Thanks for you time Costas, much appreciated.

var Blynk = require(‘/usr/lib/node_modules/blynk-library’);
var W1Temp = require(‘/usr/lib/node_modules/w1temp’);
var AUTH = ‘YOUR_TOKEN_HERE’;

// Setup Blynk (SSL)
var blynk = new Blynk.Blynk(AUTH, options={
connector : new Blynk.TcpClient()
});

W1Temp.setGpioData(4);

setInterval(function(sensor) {
W1Temp.getSensor(‘28-8000000365a2’).then(function (sensor) {
sensor.on(‘change’, function (temp) {
temp = sensor.getTemperature();
blynk.virtualWrite(0, temp );
})
})
})

It works, here it is if anyone needs it

1 Like