📜 ⬆️ ⬇️

1-wire smart home network and FreeBSD

There are a great many articles about “smart home” and 1-wire technology. I want to write how it is done “from scratch” and not on Linux (as in most instructions and articles on the web), but on FreeBSD.

Why this OS? Because there are people who have their own routers deployed at home on FreeBSD, which has some differences from Linux in configuring certain services and services. I am writing the article as a novice, i.e. it is, in its own way, an attempt to share my own experience.

Not much is written about building a 1-wire network on FreeBSD, and, as a rule, there is no comprehensive information anywhere on the “basics” of a novice homeowner. Usually on the forums they are greeted with the phrase “read man”, “teach a materiel”, “everything is elementary”, etc., essentially no one gives a hint or help.

We will do everything ourselves. To begin with, let's try to deploy something simple, such as a network with a temperature sensor. What we need.
')
1. Tools
- Soldering iron. It will be necessary to solder the two wiring, so you do not need special skills for owning a soldering iron. Not yet needed.
- A knife or something that can remove the insulation.

2. Hardware
- Our router / gateway / server with FreeBSD (I have 9 RELEASE)
- DS9490R controller for 1-wire network
image
- DS1820 + PAR temperature sensor. “PAR” tells us that the sensor has enough “parasitic” current for operation. It will be very useful to us if we build a small autonomous network. The scale of the apartment is enough. The specification for the sensor can be read here (PDF) .
image
- Cable, for example, a twisted pair of category 5. For the test, I used a piece of ordinary telephone cable, but at home everything is better to be done properly.

3. Software
- owfs. A set of utilities for working with a 1-wire network controller.

Let's get started
First install the auxiliary software.
Install fuse-kmod. I put all the software through the portmaster utility, which is installed from:
/usr/ports/ports-mgmt/portmaster
whom the religion does not allow, can be set from the ports manually.
Execute the command:
portmaster sysutils/fusefs-kmod
If the question "Do the automatic configuration", then put a tick. Otherwise, we will have to manually add the following line to the /etc/rc.conf file:
fusefs_enable="YES"
and team
/usr/local/etc/rc.d/fusefs start
run fuse.

Next, put:
portmaster devel/swig13
and execute the commands:
echo 'vfs.usermount=1' >> /etc/sysctl.conf
/etc/rc.d/sysctl restart


Now the owfs package. There were some difficulties. From the official website of owfs.org, the current version (at the time of this writing) 2.8p14 refused to be placed. More precisely refused to compile. Having rummaged in the buggy, I found an official patch that fixed the compilation error that occurred, but spawned another. On the forum site www.lissyara.su, someone wrote that he had the same problem back in version 8.2 and one friend posted his build on the network, which was successfully installed on FreeBSD. Having glanced on its ftp, I found the assembly and for the current version.

You can get it from here: ftp://hi.dp.ua/unix/owfs/owfs-2.8p14.tar.gz
Just in case, if for some reason the server goes down, I put the archive in an alternative repository:
http://ifolder.ru/29766619

Download the archive and unpack:
fetch ftp:// hi.dp.ua/unix/owfs/owfs-2.8p14.tar.gz
tar -zxvf owfs-2.8p14.tar.gz
cd owfs-2.8p14

Team:
chmod +x insta.sh
make the script executable and run:
./insta.sh
By the way, insta.sh is not my typo, it is a typo of the author of the assembly. I did not begin to rename the file and repack the archive, so that the checksum from the original server coincided with what I posted on iFolder.

When the script runs to the / usr / local address, the “owfs” directory appears - this is what we will work with.

Now with glands.

We take our telephone cable and plug it into the controller with one end, and cut off the connector from the other end and remove the insulation from the two wires.
The telephone (RJ-11) connector has 6 pins, and the wiring is in 3 and 4 pins. My 3rd contact was green, and the 4th was red.
We take our "tripod", but not this:
image
and the one that has a temperature sensor.
Legs №1 and №3 are joined together (we solder) and we solder the red wiring to them, we solder green to the remaining №2 leg. At work, in the absence of a soldering iron, I did everything on my knee with twists:
image
at home, of course, everything has to be soldered properly, so that nothing superfluous sticks out anywhere and looks beautiful.
We stick the controller into the USB connector of our server. Create the directory " / mnt / 1wire ":
mkdir /mnt/1wire
and execute the command:
/usr/local/owfs/bin/owfs -C -u /mnt/1wire
A message should be displayed containing something like:
Opened USB DS9490 bus master at
Great, the controller is working. Now check if the temperature sensor is working.

Check the contents of the / mnt / 1wire directory :
image
There are files and directories. I have a directory starting with "81." - this is the controller itself, but starting with "10." is already a temperature sensor. Let's see what it contains:
image
Aha There is a file called "temperature". Most likely this is what we need. Print the contents of this file:
image
Well, we saw the current temperature. Then you can use this data anywhere, at least in PERL, at least in PHP, at least in BASH - who likes what.

Well, these are the very basics. They have mastered it - the rest will follow itself, if we do it by analogy.
Now these “snot” can be disassembled, lay a common tire from a normal cable around the house and hang in series as many sensors as needed. All sensors can be interrogated by some samopisny script - it all depends on the tasks.

I hope this material will help those who are just starting to master 1-wire with the server running FreeBSD.

Source: https://habr.com/ru/post/141713/


All Articles