Difference between revisions of "Pi projects"

From Organic Design
m (Wifi signal extender)
(Running a Bitcoin node on a Pi: very unrepsonsive)
Line 63: Line 63:
 
</source>
 
</source>
  
The '''dbcache''', '''maxmempool''' and '''maxorphantx''' options cut down on RAM usage, and [https://bitcointechweekly.com/briefs/bitcoin-core-blocksonly-how-to-reduce-bandwidth-usage/ blocksonly] saves bandwidth. Use '''bitcoind --help''' for details about the parameters and other options.<noinclude>[[Category:Bitcoin]]</noinclude>
+
The '''dbcache''', '''maxmempool''' and '''maxorphantx''' options cut down on RAM usage, and [https://bitcointechweekly.com/briefs/bitcoin-core-blocksonly-how-to-reduce-bandwidth-usage/ blocksonly] saves bandwidth. Use '''bitcoind --help''' for details about the parameters and other options.
 +
 
 +
Note that if you need these low-memory settings, the node will have a lot of trouble synchronising and could take a month or two to synchronise. During synchronisation it will be very sluggish and take minutes to respond to REST requests. But after it finally gets fully synchronised, it will behave more responsively.
  
 
== Other Pi projects ==
 
== Other Pi projects ==

Revision as of 20:20, 20 February 2020

Info.svg This is a page about various projects you can set up on small single board computers (SBCs) like the Raspberry Pi or Banana Pi.


Wifi signal extender

PiFi signal extender.jpg

In a few AirBnB's we've stayed at recently we've found that the wifi signal is very weak in some parts of the house where we like to use the computers a lot. I decided to make a general purpose solution using a Pi with an extra wifi adapter added via USB. This extra wifi adpater could also be further extended using a 5m USB extension cable in the case of very extreme cases involving concrete walls etc.

It's easiest to get an official wifi module so that you know it's supported by the Pi out of the box, but in my case I already had a USB adapter that was based on the RTL8192EU chip which took a few hours to get working. In the end I found these instructions that use this script which worked flawlessly:

sudo wget http://fars-robotics.net/install-wifi -O /usr/bin/install-wifi
sudo chmod +x /usr/bin/install-wifi
sudo install-wifi


After running this, I could then see my two wifi adapters listed in ifconfig. To see which is which, you can check the driver that each one is using:

readlink /sys/class/net/wlan0/device/driver
readlink /sys/class/net/wlan1/device/driver

In my case I found that the original on-board one showing up as wlan1, and the new one as wlan0. I figure that it would be best to use the new one as the one that connects to the internet router, because it has an external antenna and so probably can reach the router from further away than the on-board one can. The connection details (the router SSID and password) are usually added to the /etc/wpa_supplicant/wpa_supplicant.conf file to have the wifi adapter automatically connect to the router on boot up. But if we do that, both of the wifi adapters will connect to the router. To have the details in the file only apply to one specific network interface, the interface name can be included in the file name - in this case we call the file wpa_supplicant-wlan0.conf. See Arch wiki for more details about this file. A typical file will look something like this:

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
network={
	ssid="WiFi_SSID"
	psk="WiFi_Password"
}


Now for the internal wlan1 wifi - we want to configure that one as a hotspot. The easiest way I've found to do this in Raspbian is using the create-ap utility which is covered in the hotspot page. Once you've gone through the installation of that, you can then add your configuration in the /etc/create_ap.conf file, the minimal configuration involves setting the network interface names and specifying an SSID and password.

WIFI_IFACE=wlan1
INTERNET_IFACE=wlan0
SSID=PiFi_Extension
PASSPHRASE=MyPwd

Then I set the hotspot service to start on bootup and rebooted the Pi to test everything was working :-)

systemctl enable create_ap

Running a Bitcoin node on a Pi

Running a bitcoin node is usually pretty straight forward, just download the latest version for your architecture from bitcoin.org/bin, unpack it and install it into the environment as follows. Note that here I'm running under user and group "bitcoin", it's good practice to create a dedicated unprivileged user for it.

wget https://bitcoin.org/bin/bitcoin-core-0.19.0.1/bitcoin-0.19.0.1-arm-linux-gnueabihf.tar.gz
tar -zxf bitcoin-0.19.0.1-arm-linux-gnueabihf.tar.gz
install -m 0755 -o bitcoin -g bitcoin -t /usr/local/bin bitcoin-0.19.0.1/bin/*


Most likely you're running off a small primary drive or even an SD card, in which case you'll need to ensure that the .bitcoin data directory for your bitcoin user is actually located on a large external drive since the blockchain (even if running a pruning node) will be very large. A symlink won't work for this, so you need to use a binding mount (both source and target must already exist), e.g

mount --bind /mnt/usb-drive/bitcoin/ /home/bitcoin/.bitcoin

Alternatively you can provide the -prune parameter when you start the service set to a certain number of megabytes to keep the stored block storage below your target value.


And then finally start bitcoin in daemon mode. If you have low memory, then you'll need a few extra parameters to keep the memory foot print down, the defaults will require about a GB of RAM for the bitcoin process. The following example keeps it down to around 400M of RAM usage. Don't forget to use sudo to run it under your dedicated user. If you're behind a firewall you'll need to edit your bitcoin.conf and set listen to 0 and addnode to the IP of another trusted node on port 8333.

sudo -u bitcoin bitcoind -daemon -blocksonly=1 -dbcache=50 -maxmempool=100 -maxorphantx=10

The dbcache, maxmempool and maxorphantx options cut down on RAM usage, and blocksonly saves bandwidth. Use bitcoind --help for details about the parameters and other options.

Note that if you need these low-memory settings, the node will have a lot of trouble synchronising and could take a month or two to synchronise. During synchronisation it will be very sluggish and take minutes to respond to REST requests. But after it finally gets fully synchronised, it will behave more responsively.

Other Pi projects

See also