📜 ⬆️ ⬇️

Turning the router into an XBee-to-Ethernet Gateway

I’ll say at once what you won’t find in this article:

Vorning for designers : there is a picture in the post, better not look at it. I saved myself from having to write such a worning for programmers by avoiding the temptation to publish Python scripts and the thml code of the page shown in the picture (the template was generated in Word).

It is assumed that you yourself are able to find the necessary information on the Internet and have the necessary knowledge. The objective of the article is to describe in large enough lines how to integrate XBee and an Ethernet / Wi-Fi router, to give a simple example of a working system, to indicate directions for further development.
Go.

Xbee


I always thought that XBee / Zigbee / Other-bee is such a UART-a wireless extension cable. Therefore, it was always incomprehensible to me - why is it so expensive. But then a friend gave me two XBee modules to “play around”, I dragged them home, immediately ditched one of them when reflashing, turned to Digi support (XBee manufacturer: www.digi.com ), despite the high level of support, I managed to incorrectly execute instructions He closed the case and, in fact, remained with a “burning” piece of iron on his hands, which he had to somehow return. As always, I had to dig, understand, use foul language and beat my head against the table. As a result of many days of dancing with a tambourine, I learned that:

In general, everything is good, we have a network of sensors and performers, all messages between them are routed, they communicate with each other through routers, the coordinator sits on top and watches all this. The problem is that we, humans, do not have an entry point to this network. The simplest solution: USB-UART converter, turn on the computer, launch a terminal or a special program (for example, a program from digi: X-CTU or others, such as XBee-Operator, or even write python scripts ourselves, there are plug-ins on digi.com work with XBee). The bad thing is that if we want to have information about the status of sensors in a digestible form always and everywhere, then a computer, even with a running web server stuck in the Internet, is not the most elegant solution.
')

Router


A more elegant solution is to use a router that is always on and directly looking into the Internet. Any router that has a WART and which has access to the console will do. I use the good old ASUS wl500gP with the firmware from Oleg (wl500g.info), it is more fashionable to use TP-Link, DLink and other tiddly boxes that eat an order of magnitude less energy and you can unsolder the UART and insert the Open-WRT firmware there. How to do it - in Google. Here is an example: wiki.openwrt.org/ru/toh/tp-link/tl-mr3420 . Points of interest are Installation and Serial Port.

We collect


IMPORTANT : The XBee is a 3.3V device. If you submit it to 5B, it will bake.
We take the XBee, connect the adapter to the USB-UART, plug it into the computer, launch the X-CTU, flash it with the necessary firmware. The simplest option is ZB24 Coordinator AT (yes, by this point you already need to know the difference between XBee firmware, what device role is needed, etc. You need to read in the internet, start well from here: The Unofficial XBee FAQ (version 1.3) (eng ) or from the Robert Faludi book - Building Wireless Sensor Networks with ZigBee, XBee, Arduino, and Processing. Disconnect the XBee from the adapter and from the computer, and connect it to the serial port of the router.
XbeeRouter
VDD (pin 1)+ 3.3V
VSS (pin 10)GND
DOUT (pin 2)Rx
DIN (pin 3)Tx

We check the performance. We start minicom, connect to the port on which the XBee hangs at the speed at which the XBee is configured (I have –D / dev / ttyS1 –S115200). Enter AT-command mode: press “+” three times (and nothing more!). After a second, XBee should answer “OK”, which means that it entered the command mode. You can exit the mode by typing the command ATCN <input> or waiting 10 seconds. In principle, this is all, you can already do anything with this port. For example, set ser2net to autoload, and put / dev / ttyS1 on a TCP port, for example 2000. After that, from any machine on the network, you can connect to the router with a Telnet or install software on a machine that zamapit back to a remote serial port.

Example


I have a Python interpreter on my router. Once an hour, cron jerks several scripts. One of the scripts opens the serial port on which the XBee hangs and sends a request to the remote device (which stands in the bathroom on the riser): 'gv'. The device responds with the lines: 'hw25.054cw0.000 \ r \ n' and 'v8.72 \ r \ n', which means that the hot water meter clocked up 25.054 cubic meters of water, cold clocked up 0 cubic meters (of course, it is not connected) and that battery voltage is 8.72 volts. The script takes these values ​​and writes them to a file. Another script, which cron jerks every five minutes, packs these values ​​into an html template and saves it as index.html in the / opt / share / www / folder. The router also raised lighttpd, which, when addressed to the address of the router gives this static page. In this way, my wife and I can at any moment find out the readings of water meters without getting up from the sofa.


What else can you do


Yes whatever.
• Remind you that the flowers are not watered (measure the moisture of the ground in pots and panic when the ground is dry)
• Feed animals while away
• Turn off the light, open the door, heat the bath, close the windows and so on. Everything is limited only by fantasy.

What's next?


Well, probably the most obvious thing is to do a dynamic sensor survey. That is, register the python as a fast-cgi module in lighttpd and directly access scripts from the browser
Further, digi has iDigi Dia software - actually a management console. Using it, you can give commands to the XBee sensors, upload firmware to them remotely, reset them, etc.
Digi also has a cloud (http://www.idigi.com/). That is, it is possible to associate separate sensors or entire networks with a cloud, where control software will spin and have access to it from anywhere.
There are a lot of connectors (http://www.idigi.com/idigiconnector/) - in general, expanse for a person with a head and skills
There is software written by third-party developers. For example, XIG (xig.googlecode.com) is Xbee Internet Gateway. This is a web <-> xbee translator. For example, when receiving data on the state of the sensor, it can screw this data with a tail to a get-request and send this request to a remote server. Or, on request from XBee, download information from a specific site.
In general, a lot of things are possible. Connecting the four wires from the router to the XBee is just the first step to the Internet of Things. But even this first small step is very interesting.

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


All Articles