⬆️ ⬇️

Raspberry Pi, alarm and smart home



It all started about 4 years ago when during my work day my apartment was cleaned. After that, it was not possible to get home through the door because of a damaged lock. The unpleasant event made us think about the safety of the home. And this is just one of the reasons for monitoring and automation of the apartment. How often when you came to work (or even when leaving or flying somewhere) did you doubt whether the iron was turned off before leaving, gas or water was turned off ;-) Add oil to the fire of admins - are you at ease that your old power supply unit is not working at home? Chaditas and does not burn!?) And what to do remotely with the device, which “tightly hung”.



In this post, I will look at some of the existing solutions on the market, the retail price of affordable hardware and how to create an apartment alarm and some of the functions of a smart home using a single-board computer Raspberry Pi





Of course, you can connect to private security, pay for equipment, installation and pay a monthly subscriber. This is not an option for geeks) Security will not cheaply reboot a computer that is stuck at home, and besides, not all objects will be able to be handed over to security. Do you all have a telephone line? ;-)

')

A university friend suggested how to connect a motion sensor and smoke to a computer via the LPT port. This port is an option not currently fashionable in motherboards and it is not very convenient to program it in an OS running in protected mode in a high-level language and not in a single-task DOS in real mode. Oldfags will curse me and with nostalgia mourn the sound of Covox on LPT, which they once soldered and programmed themselves)))



In the meantime, the sensors were gathering dust in the closet ... With a friend of the same class, we successfully recalled the USB ports and HID drivers that are present “out of the box” in all modern operating systems. Another friend is well versed in electronics, helped again with the device. This time the device was on the STM32 Cortex M3 controller. In order not to solder from scratch, I bought a ready-made STM32-H103 board www.olimex.com/dev/stm32-h103.html and ST-Link programmer. The prospect of programming for this controller without experience and without the help of a friend did not smile at me. As a result, I now have to gather dust from the microcontroller board with firmware and the optocoupler circuits soldered to the mockup for connecting sensors to the controller's programmed GPIO legs. I never learned how to program the STM32 microcontrollers myself, but from this solution I really liked the implemented idea - access to the sensor states via the MC via USB Virtual COM Port. In Linux, serial drivers via USB are included in the kernel, and access from a java application is simply reading and writing text data to a file. An elegant solution, you can invent and implement your own text protocol on the controller. In general, the solution for inputting discrete signals to a computer is not the most affordable. The price of such a fee was about 1500 rubles, and the programmer cost almost the same money. To add new functions to such a device requires knowledge of development environments for the controller, libraries of controller functions, and more in-depth knowledge of circuit design. An excellent solution for those who are friends with STM32, Keil and a soldering iron ;-) But again, too confusing for application programmers.



It seems obvious - look for ready-made solutions. And it was not there! Prices just for terminal blocks with optocouplers start from 2500r. Blocks with the help of which you can commute external load from a computer start at 900p www.chipdip.ru/product/mp709.aspx . Although every red-eyed person can understand that a cheap Chinese electromagnetic relay with drivers for windows cannot cost so much. Once upon a time, the same master whale sold a more human solution for switching the network load, namely, the solid-state relay www.masterkit.ru/info/magshow.php?num=199 (The people actively use a similar scheme in their home devices arduino- ru.blogspot.com/2009/02/220.html ). Retail prices for solid-state relays in the housing start at 600r. There are no available adapters for inputting discrete signals via USB, there are only expensive ones for electronics. I never managed to connect more than one webcam broadcasting to the network to the USB 2.0 controller of the computer. IP cameras are still quite expensive. DVR cards with a lot of video inputs working under linux should also be looked for for sale (there is information on such cards on the page of the zone minder project) and they require a PCI port. Those that work via USB usually contain only 1 video input.



Of the available universal solutions, I can mention NetPing / PWR-220 v2 with a fairly affordable price of 112 cu. A more expensive and specialized USB I / O device is the Geovision GV-IO USB Box 16 Inputs 16 Relay Outputs for $ 150. The price of finished 3G alarm starts at 3500r for the control unit. Many security systems consoles designed for the equipment of any one company, using a radio channel for communication with sensors, controlled by proprietary software and sending SMS only in the event of an alarm. But what about the "silencers GSM" and radio frequency sensors !?



What stops us from implementing a massively available solution based on open source code for the protection of an apartment and remote control of electrical load?

1. The absence of several GPIO contacts in computers for inputting the signal from the sensors / output control signals

2. High purchase price and power consumption for a constantly working computer.

3. The lack of available mass cards for discrete input / output of signals with optocoupler and the ability to switch the load in the AC network.

4. Lack of available USB webcams with hardware video compression. Or an affordable DVR card with multiple video inputs for security cameras with hardware video compression.



The appearance of selling the Raspberry Pi single-board computer should solve the first two problems.



The board according to the documentation has 8 GPIO . The $ 35 modification has an Ethernet port. In retail there are usb wifi adapters working under Debian linux from 400r. 3G modem without binding to a telecom operator costs in Svyaznoy from 990r. Power can be obtained from the USB hub Defender Septima Light c external power supply and use it for its intended purpose, with the cost of it in the retail network from 440r. If we need a microphone input, then we can splurge on a Chinese USB audio card for 220r, which people successfully use under linux everybuying.ru/product_info.php?products_id=1469 . 8Gb SD card can be purchased at retail for 300r. The case is just like a box with leads for wires for REA will cost from 160r. Prices for external HDDs for 500GB start at around 2600r (this is optional for work and is needed only in the case of a file player, media player). Yes, if suddenly one ethernet adapter is not enough for us, then you can buy a USB ethernet adapter. For example TrendNet TU-ET100C for 460r. In any case, this solution will be cheaper than a nettop at least 3-4 times, energy efficient and more compact.



Programming GPIO in linux is easy enough - either using the C API or more conveniently, access via the file system



If we use only for security purposes, home web, file server and torrent rocking, then you can not buy a separate monitor and connect remotely from your phone or laptop via wifi or from desktop via ethernet. If we need a home media player, then we can connect it to the TV via HDMI. And if we decide to use it in a car or as a video intercom, we can purchase a portable 7 "monitor with a composite video input, for example Velas VTV-720 (from 1900r). You can use the cigarette lighter charger for USB 300-500r as a power supply.

To ensure uninterrupted power supply of sensor power supply units and Raspberry Pi, you can use a computer uninterruptible power supply, for example, APC Back-UPS ES 525VA. At a cost of about 3000r, this UPS has support for signaling that there is no external power supply and the level of the remaining battery charge through the USB output to linux (everything works fine in ubuntu for me).



There will be a problem with the discrete I / O board, but even with my knowledge of circuitry and soldering, I can easily assemble a prototype board for 4 discrete inputs with optocoupler, 4 discrete outputs. A couple of pins can be used to switch the network load using the optorele and remotely turn on / off electrical appliances at home. The remaining pins with opto-isolator can be used, for example, to remotely press the server reset button, turn on the solenoid valve to shut off the water / gas in case of leakage, etc. I am sure that China does not sleep and soon such ready-made devices will be massively distributed on the market. There is a need for such devices.



In the first approximation, the cost of parts in the retail network does not exceed 1000r for the development of a prototype of a discrete I / O board, with opto-isolation of external signals, contact panels for sensors, with 2 220V switched sockets, ready-made housing.



It is a little about sensors for alarm systems and their cost at retail. Motion sensor costs about 400r, smoke sensor 400-500r, water leakage sensor 400-800r, natural gas leakage sensor 1300r, sensor reacting to breaking window glass 400r, reed switch (sealed contact) that triggers opening / closing of the door and window frame costs about 30R))))



Also, this solution is suitable not only for a standard apartment, but also in the case of the protection of a large area. Because these computers are cheap enough and equipped with all the necessary network interfaces, it is easy to collect data and transmit control signals. Interference may be the temperature range in which the Raspberry Pi works (a possible solution is a case with a thermal sensor and heating), moisture and dust protection (this problem can be overcome by a hermetic case).



Interfere with the wires from the sensors and optorele / actuators !? We can make a less secure and noise-proof connection. For example, using a microcontroller with an integrated Zegbee transceiver. Many devices can be powered by small-capacity batteries for a long time and can be accessed via radio. Controlled mains sockets and electrical switches are available AC mains voltage, which can be used to power a low-power controller via a compact transformerless power supply. The Chinese market already has a sufficient number of devices controlled by the Zigbee protocol. There is room to strive for our market of electronic devices ;-)



For software compression of a video signal from several webcams, the device’s performance is hardly enough. If something changes in the market of IP cameras and they become more accessible for the mass market, then the device's performance should be quite enough for recording and broadcasting compressed video.



From the point of view of a programmer, such hardware allows transmitting a sensor triggering signal via SMS, 3G, WiFi, and wired Internet. It is easy enough to create a web service that allows you to access home security, webcams, manage sockets. The inability to connect to the system is also a signal that not everything is in order. It is possible to receive sms, email, jabber, skype, etc. alerts. For paranoid, untrusted web services, you can organize your own space fleet ...



How do you like the idea of ​​using an affordable mainframe computer with linux for the apartment security system, managing the smart home systems and sharing other useful functions in it? How is the second option for using old computers to develop a USB-> GPIO card on a microcontroller?



I repeat that I am a programmer and I do not know the details of designing devices for mass production. You can wait for the appearance of the development of Chinese industry, but it is better to create a massive solution earlier and focus on creating software for it. How difficult is it to launch a small series of input-output boards into production (up to 1000 pcs.). Where it is better to produce printed circuit boards, where it is better to install the elements? What cost price can be provided for such a batch of devices?

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



All Articles