|
| 1 | +# longer range TCPIP via NRF24L01 for a pair of Raspberry PIs |
| 2 | + |
| 3 | +## Intro |
| 4 | + |
| 5 | +This tutorial is trying to use `NRF24L01` to create a TCP/IP link between two Raspberry Pi boards. |
| 6 | +Due to long range of NRFs, some of those have 1800 meter wireless range, it would be good to have a TCPIP link between two RPi via NRFs so it would be possible to have a TCPIP connection between two RPi in longer range. The onboard wifi of RPi cannot do long ranges like 50 meter even in clear sight. |
| 7 | + |
| 8 | + |
| 9 | + |
| 10 | +## Hardware Configuration |
| 11 | + |
| 12 | +1. wiring: Here is how I did connect the module to the RPi as described in the main RF24 documentation [here](https://nrf24.github.io/RF24/#autotoc_md227). |
| 13 | +2. Noise on 3.3v on RPi: Put some capacitor or L-C filter to reduce the noise on 3.3v supply from RPi. |
| 14 | +3. Shielding PA/LNA module: Shield your radio module, if it has none. See more details [in the RF24 Common Issues document](https://github.com/nRF24/RF24/blob/master/COMMON_ISSUES.md#my-palna-module-fails-to-transmit) |
| 15 | + |
| 16 | +## Software Configuration |
| 17 | + |
| 18 | +1. Enable SPI from [`raspi-config`](https://www.raspberrypi.com/documentation/computers/configuration.html#raspi-config). Select "Interface Options" -> "SPI" -> "Yes" -> "Ok", then exit and reboot the RPi (`sudo reboot`). |
| 19 | +2. Install nRF24 library stack on each machine. See more detail in the [RF24 docs](https://nrf24.github.io/RF24/md_docs_2linux__install.html). |
| 20 | + |
| 21 | +```text |
| 22 | +sudo apt-get update |
| 23 | +sudo apt-get upgrade |
| 24 | +wget https://raw.githubusercontent.com/nRF24/.github/main/installer/install.sh |
| 25 | +chmod +x install.sh |
| 26 | +./install.sh |
| 27 | +``` |
| 28 | +Installer will promp which modules you want to install. I did installed all modules: "RF24", "RF24Network" "RF24Mesh" "RF24Gateway". Also please select `SPIDEV` driver during installation. |
| 29 | + |
| 30 | +after installation done, and if there are no errors in the process, there will be these directories inside the RPi: |
| 31 | + |
| 32 | +```text |
| 33 | +~/rf24libs/RF24 |
| 34 | +~/rf24libs/RF24Network |
| 35 | +~/rf24libs/RF24Gateway |
| 36 | +~/rf24libs/RF24Mesh |
| 37 | +``` |
| 38 | + |
| 39 | +Next we need to choose a master/primary node (as discussed [here](https://github.com/nRF24/RF24Gateway/issues/41)). so one RPi will be primary, and another one will be secondary. we'll use the official example named `ncurses` in [RF24 repo](https://github.com/nRF24/RF24Gateway/tree/master/examples/ncurses) to establish the network. |
| 40 | +this code is already cloned to local device in process of installation. so we need to have some edits on the code. On the Master/Primary machine no need to do edits, but on the secondary machine we need to edit `~/rf24libs/RF24Gateway/examples/ncurses/RF24Gateway_ncurses.cpp` file, first lines of method `main()` |
| 41 | + |
| 42 | +Before edit (first lines) |
| 43 | +```cpp |
| 44 | +int main() |
| 45 | +{ |
| 46 | + |
| 47 | + gw.begin(); |
| 48 | + //mesh.setStaticAddress(8, 1); |
| 49 | + |
| 50 | + //uint8_t nodeID = 22; |
| 51 | + //gw.begin(nodeID,3,RF24_2MBPS); |
| 52 | + |
| 53 | + //uint16_t address = 0; |
| 54 | + //gw.begin(address,3,RF24_2MBPS); |
| 55 | +``` |
| 56 | +after edit: |
| 57 | +```cpp |
| 58 | +int main() |
| 59 | +{ |
| 60 | +
|
| 61 | + //gw.begin(); |
| 62 | + //mesh.setStaticAddress(8, 1); |
| 63 | +
|
| 64 | + uint8_t nodeID = 3; |
| 65 | + gw.begin(nodeID); |
| 66 | +
|
| 67 | + //uint16_t address = 0; |
| 68 | + //gw.begin(address,3,RF24_2MBPS); |
| 69 | +``` |
| 70 | + |
| 71 | +Again, the above edit is only done in the secondary machine, the primary machine needs no edits. |
| 72 | + |
| 73 | +Next, we need to recompile the ncurses example and run it in the terminal: |
| 74 | + |
| 75 | +```text |
| 76 | +cd ~/rf24libs/RF24Gateway/examples/build |
| 77 | +make |
| 78 | +``` |
| 79 | + |
| 80 | +### Primary machine config |
| 81 | + |
| 82 | +```text |
| 83 | +sudo ip tuntap add dev tun_nrf24 mode tun user pi multi_queue |
| 84 | +sudo ifconfig tun_nrf24 10.11.2.2/24 |
| 85 | +``` |
| 86 | + |
| 87 | +### Secondary machine config |
| 88 | + |
| 89 | +```text |
| 90 | +sudo ip tuntap add dev tun_nrf24 mode tun user pi multi_queue |
| 91 | +sudo ifconfig tun_nrf24 10.11.2.3/24 |
| 92 | +``` |
| 93 | + |
| 94 | +### Run the ncurses example on both machines |
| 95 | + |
| 96 | +```text |
| 97 | +cd ~/rf24libs/RF24Gateway/examples/build/ncurses |
| 98 | +./RF24Gateway_ncurses |
| 99 | +``` |
| 100 | + |
| 101 | +Done. The primary machine IP is `10.11.2.2`, and the secondary machine IP is `10.11.2.3`. |
| 102 | +One could ping machines from each other. |
| 103 | + |
| 104 | +The resulting latency when pinging primary machine from secondary is about a few milliseconds (or even less than a millisecond), and the speed is about `10kB/s` (equal to 100K bits per second). |
| 105 | + |
0 commit comments