We use cookies to personalise content and ads, to provide social media features and to analyse our traffic. We also share information about your use of our site with our social media, advertising and analytics partners who may combine it with other information that you've provided to them or that they've collected from your use of their services.

Sensors and a large network

1wire sensor3The time has come to test what the DS2482 modules are capable of. I have purchased a large pack of sensors and got to work. I had already had mounting of sensors in the switcher frames behind me so all went quite smoothly. Here are some photos of details…

  1. To solder the legs of DS18B20 to wires of an ethernet cable I used a „third hand”, a metal holder with clamps and a magnifying glass.
  2. I was careful to keep the colors of the wires unchanged and so that later I do not have to check, which is which.
  3. Instead of using a two-component glue (as before) I took a hot-glue pistol, which my wife uses for her paper art. It was a great improvement as the glue cools down quickly and in case of errors a correction is possible.
  4. I tried to place the sensor-heads slightly outside the switcher frames, but they were too visible on a light-colored wall. At the end I placed all of them even with the frame walls.

1wire sensor1 1wire sensor2

As all the Ethernet cables leading to the wall-mounted switches end up at one point – the central cabinet – my 1-wire network has the shape of the unrecompensed star.  With every additional sensor the ability of such a network to properly read the data falls.  I was able to connect up to 11 sensors to one ‘hole’ of the DS2482-800. That is by no means a scientific measure of anything – I cannot measure the length of which wire or analyse the interference with the 230V wires.  That shows, however, that with the DS2482-800, which offers a total of 8 1-wire hubs, one can control a huge amount of sensors even in a falsely laid network.

Currently my RPi reads data from 16 DS18B20 and 1 light-sensor.  I connected the sensors on the outside of my house to a separate ‘hole’/hub, so 3 hubs are used.  Still… the reserve for future extension is big.

A few words about scripts.  I have placed 2 files in the directory /var/www:

1. sensors.csv, which stores the numbers/names and descriptions of the sensors.  I fill it gradually after connecting each additional sensor:

28.F471B0040000;Salon - przy oknie;
28.B2B3A1040000;Sypialnia - drzwi;
28.87E9A0040000;Salon - kominek;
28.914CA1040000;Pokój Dzieci - drzwi;
...

 

2. sensors.php, which is opened in an internet browser

<?php
echo "<p>Update of: ".date('Y-m-d H:i:s')."</p>";
if ($MainDir = opendir('/mnt/1wire')) {
	$SensorFile = file("sensors.csv");
	if (!$SensorFile) {
		echo "Opening file with sensor names failed";
	}
	else {
		foreach ($SensorFile as $line){
			$SensorData = explode (";", $line);
			$SensorNumbers[]=$SensorData[0];
			$SensorNames[]=$SensorData[1];
		}
	}
	echo "<ol>";
	while (false !==($MainDirItem = readdir($MainDir))){
		if (preg_match('/[0-9]{2}./', $MainDirItem)) {
			$key = array_search($MainDirItem, $SensorNumbers);
			echo "<li>";
			if (false !==$key){
				echo $SensorNames[$key]." : ";
			}
			else{
				echo $MainDirItem." - no name assigned  : ";
			}	
			$TempFile = fopen("/mnt/1wire/$MainDirItem/temperature", "r");
			if (!$TempFile) {
				echo "...some problems with temp. file opening...";
			}
			else {
				$Temperature = fgets($TempFile);
				echo $Temperature."&deg;C<br>";
			}
			echo "</li>";
		}
	}
	echo "</ol>";
}