Beer thermometer with raspberry pi and ds18b20

Hi there! I’m new in the usage of blynk, im coming from Cayenne, but the lack of control about the addition of new devices has forced me to seek for another options, thats how I ended up using Blynk.
Now, I would like to present my project and then ask some questions that I have been unable to solve by searching the forums, please feel free to call me whatever you want if my questions have already been answered in other posts.
What I am aiming to achieve is a set of thermometers and relays that control the temperature of a room. In the process of making home-brew beer the management of temperatures is a key part to obtain something drinkable and not some pee-like beverage, so, mainly I would like to see two ds18b20 sensors and control some relays (this is something that will come in the future, first the temps)
The things I’ve done:

  1. Follow this instructions h ttp://docs.blynk.cc/#hardware-set-ups-raspberry-pi and successfully connect to my raspberry pi using my token.
  2. Installed this library https://github.com/kolarcz/node-w1temp as seen in this post Raspberry + 1-wire temperature sensors DS18B20

Thats where things got messy, I’m not able to instance the sensor and obtain the temperature by using the example provided in the github README and the code posted by @fisero in the above mentioned post.
To finish my endless set of questions, how do I link the graphs in blynk on my smartphone to the data obtained by the .js file? once I am able to instance the sensor and obtain the numeric value of the temp, I think is by using virtual pins, so i guess I write the themp on V0 for instance, and then get in the blynk graph the V0 pin.

Thanks in advance for such great platform and community

Greetings from Spain!

Hello.

Correct. You gave an answer by yourself :wink:

Hi Raul,

Welcome to Blynk. First of all, you should know that Cayenne used a lot of Blynk open-source code to build their platform, so you came to “the roots” :slight_smile:

I can’t recommend anything for the sensor part yet, but I’m sure there are plenty good folks here who know how to resolve it.

You are absolutely right, virtual pins is a concept of the channel between hardware and the app. Basically, you push something from harrdware to Vpin and then set the widget on the app side to the same Vpin, and it creates a channel between these 2 points, where data flows.

Thanks! Always a pleasure to help myself :slight_smile:

I see, I had no idea, their app and web are worst implemented that yours, it is far from smooth, I like your design too, more “materialized”.
Happy to contribute to the origin of everything.
Nice to see that you also take part in the forums.
Cheers!

1 Like

@raul we use w1temp and DS18B20’s attached to our Pi’s. Works fine but we did find the different options a bit confusing when it came to setting up w1temp (modprobe, edit SD card entries, wiringPi etc).

Our code is classified top secret by the KGB so we can’t publish it here but presumably yours isn’t.

Perhaps if you provide details of what bits of the w1temp guide you followed, which bits you skipped and your code as you have it now someone might be able to point you in the right direction.

1 Like

Hmm, I had you pegged as MI6… but then since I work for IDK, I could have been mislead :wink:

@raul I too wouldn’t mind seeing some code, not that I drink beer (darn gluten) but I am always interested in a little code snatching for use on that elusive RPi/Blynk combo.

I only installed w1temp library and followed the modprobe steps showed in github, no wiringPi installed.
I get an error when running this code:

var blynkLib = require('blynk-library');
var W1Temp = require('w1temp');
var AUTH = 'HERE_COMES_YOUR_TOKEN'; 

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

// Automatically update sensors value every 5 minutes
setInterval(function() {
W1Temp.getSensor('28-0000045c34f2').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);

Terminal says, filed to instance
Obviously i change 28-0000045c34f2 to the identifier of one of my sensors, and my AUTH var to my token.

Sorry for the delay, above is the code I run with node and throws me a cant get sensor instance error.
Thats something I notice, I also have an arduino one, but without any wifi shield/esp8266, thats why I went with the raspberry to make this little proyect.
So, this is what raspi shows after running the above mentioned code:

pi@raspberrypi:/usr/local/lib/node_modules/blynk-library $ node TestTemp 
[ '00-c00000000000', '00-200000000000' ]
(node:907) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: Could not set data gpio pin
(node:907) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): Error: Cant get sensor instance
pi@raspberrypi:/usr/local/lib/node_modules/blynk-library $ node TestTemp 
[ '00-200000000000', '00-a00000000000' ]
(node:922) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: Could not set data gpio pin
(node:922) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): Error: Cant get sensor instance

Notice that the array of connected devices changes in each call, something that I dont fully understand.
Hope your code is not classified as top secret
Cheers!

@raul what does lsmod show? Ours is:

pi@raspberrypi:~ $ lsmod
Module                  Size  Used by
w1_therm                4475  0
w1_gpio                 4534  0
wire                   31801  2 w1_gpio,w1_therm
cn                      5860  1 wire
cfg80211              500089  0
rfkill                 21397  1 cfg80211
sg                     20799  0
snd_bcm2835            23131  0
snd_pcm                95473  1 snd_bcm2835
snd_timer              22556  1 snd_pcm
snd                    68400  3 snd_bcm2835,snd_timer,snd_pcm
bcm2835_gpiomem         3823  0
bcm2835_wdt             4133  0
uio_pdrv_genirq         3718  0
uio                    10230  1 uio_pdrv_genirq
ipv6                  367671  24

I’m not entirely sure wiringPi is required but it’s probably worth installing just for the graphical display of the pin settings.

For reference the 5 minutes is actually 50s in the code extract.
We have some problems with the path on our Pi so all require statements show the full path for example:
var W1Temp = require('/opt/nodejs/bin/node_modules/w1temp');
Your path is likely to be different unless you used the latest guide for setting up the Pi as a client for Blynk.

You are missing the pin setting and you should display the sensor address with this code between the require and the setInterval(function(){});

W1Temp.setGpioData(7);
console.log('using BCM GPIO 7, physical pin 26 on a Model B Pi');

W1Temp.getSensorsUids().then(function (sensorsUids) {
  console.log('DS18B20 address is: ' + sensorsUids);
})

See how you go with these changes.

lsmode shows:

Module                  Size  Used by
sha256_generic          9839  1 
hmac                    3211  1 
drbg                   12876  1 
ctr                     4101  2 
ccm                     9008  2 
arc4                    2076  2 
rt2800usb              18877  0 
rt2800lib              82155  1 rt2800usb
rt2x00usb              12680  1 rt2800usb
rt2x00lib              48998  3 rt2x00usb,rt2800lib,rt2800usb
mac80211              608581  3 rt2x00lib,rt2x00usb,rt2800lib
cfg80211              500089  2 mac80211,rt2x00lib
crc_ccitt               1732  1 rt2800lib
rfkill                 21397  2 cfg80211
snd_bcm2835            23131  0 
snd_pcm                95473  1 snd_bcm2835
snd_timer              22556  1 snd_pcm
snd                    68400  3 snd_bcm2835,snd_timer,snd_pcm
i2c_bcm2708             5740  0 
spi_bcm2835             7424  0 
bcm2835_gpiomem         3823  0 
bcm2835_wdt             4133  0 
w1_gpio                 4534  0 
wire                   31801  1 w1_gpio
cn                      5860  1 wire
uio_pdrv_genirq         3718  0 
uio                    10230  1 uio_pdrv_genirq
ipv6                  367671  26 

About the 50 seconds, totally correct, I made a typo.
Will check the rest of your steps as soon as I can, I will update this post once I tested your changes.
Thanks!!

Edit: after placing the full path of the modules, the can´t get sensor instance error and the ids of the sensors keep changing, Anyone knows why they change on each call?
Cheers!

Also, my relays came, already set up and functioning flawlessly, one more problem I faced is the disconnection from the server on raspberry pi, forcing me to run again the command blynk-client.
Will investigate more once I finished the setup of the temperatures.
Cheers!

Really considering removing the sd and making a wipe, to start again everything. Quite reluctant tho, I would’t like to see my problem unsolved after all the process :grin:

Normally means the sensors are not wired up correctly, wrong pins or missing the 4K7.

Darn, i swear i got them correctly wired, I will make a scheme right know.
I really appreciate your help here, thanks!

This is my circuit, notice that one of the ds18b20 is not connected to a 4.7K resistor, since it came in a small board ready to plug.
Regards

I would try to get one sensor running first, maybe the one that has the builtin resistor.

What do you have for setGpioData?

I will disconnect the other then.
for setGpioData I have 23

The one I suggested you left connected is connected to GPIO 24 ?

What results are you getting now and have you installed wiringPi?

I just disconnected everything and changed the setGpioData to 24.
I haven’t installed wiringPi.
I will test know and post my results
Cheers

Edit: addresses keep changing in each call, making me impossible to set one in my .js.
This is the output of the command

pi@raspberrypi:/usr/local/lib/node_modules/blynk-library $ sudo node TestTemp 
using BCM GPIO 7, physical pin 26 on a Model B Pi
DS18B20 address is: 00-800000000000,00-400000000000
(node:925) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: Cant get sensor instance
pi@raspberrypi:/usr/local/lib/node_modules/blynk-library $ sudo node TestTemp 
using BCM GPIO 7, physical pin 26 on a Model B Pi
DS18B20 address is: 00-c00000000000,00-200000000000
(node:974) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: Cant get sensor instance
pi@raspberrypi:/usr/local/lib/node_modules/blynk-library $ 

This is my runned code once more

var W1Temp = require('/usr/local/lib/node_modules/blynk-library/node_modules/w1temp');

// turn on gpio pin 13 as W1 power if you want to

// set gpio pin 6 to use as W1 data channel
// if is not set by instructions above (required root permissions)
W1Temp.setGpioData(24);
console.log('using BCM GPIO 7, physical pin 26 on a Model B Pi');

W1Temp.getSensorsUids().then(function (sensorsUids) {
  console.log('DS18B20 address is: ' + sensorsUids);
})

// get instance of temperature sensor
W1Temp.getSensor('00-f84000000000').then(function (sensor) {

  // print actual temperature
  var temp = sensor.getTemperature();
  console.log('Actual temp:', temp, '°C');
});