WHAT'S NEW?
Loading...
Showing posts with label raspberrypi. Show all posts
Showing posts with label raspberrypi. Show all posts
Some programs requires, at peak, more than 1GB of RAM in order to run stable. To ensure a stabile behavior on a Raspberry Pi it is recommended to set a swapfile with 2048 MB to buffer these peaks.

To create a swapfile on your Raspberry Pi (Raspbian) you can use the following commands:

1) sudo su -c 'echo "CONF_SWAPSIZE=2048" > /etc/dphys-swapfile'

2) sudo dphys-swapfile setup

 After creating the swapfile, you have to activate it once by using this command:

3) sudo dphys-swapfile swapon

Now your Raspberry PI has enough SWAP in place if its needed, and will not go down because of RAM overload. You can set up swap space on an external HDD.

You can edit the /etc/dphys-swapfile config file to make the changes, then reboot.

Something like this (assuming you have created a partition and set your hdd to mount at /media/sda1 - change that to suit):

CONF_SWAPFILE=/media/sda1/swapfile
CONF_SWAPSIZE=2000

That will create and activate a swapfile called /media/sda1 of 2000MB at the next reboot.
Monero mining is more efficient on GPU but its technically totally possible to do it on a Raspberry CPU. The Raspberry is an 32bit processor and the cpu miner is 64bit only, you have to recompile it. If you are able to acquire raspberry pi at no cost and have no power cost its possible and would be proficient. You must avoid solo mining and must use a pool to have some results.



I assume that you have Raspbian or Ubuntu 14/16 as the OS Linux distribution installed under your Raspberry Pi. Due to the lack of a GPU, with a Raspberry Pi we have to use the CPU. Let's start!

Do a SSH connection to your Raspberry Pi, become ROOT and download the needed development libraries with apt:

sudo -i


apt-get update -y



apt install autoconf libcurl4-openssl-dev libjansson-dev openssl libssl-dev gcc gawk automake git -y

git clone https://github.com/lucasjones/cpuminer-multi.git


cd cpuminer-multi

./autogen.sh





Now optimize the build for your Raspberry version
You can read more infos about this here https://gist.github.com/fm4dd/c663217935dc17f0fc73c9c81b0aa845


As for mining, you’ll need to create a Monero wallet https://mymonero.com/ and find a pool to join. Mining in a pool means you get a small part of the reward for the mining you do. In our example we use Nanopool https://xmr.nanopool.org/help

To start the mining we use the minerd command

/usr/local/bin/minerd -a cryptonight -o stratum+tcp://xmr-eu1.nanopool.org:14444 -u stratum+tcp://xmr-eu1.nanopool.org:14444 -u yourmoneroaddress.raspberry -p yourpassword -t 2 

For example

/usr/local/bin/minerd -a cryptonight -o stratum+tcp://xmr-eu1.nanopool.org:14444 -u stratum+tcp://xmr-eu1.nanopool.org:14444 -u 43x4C2pwcvWgGS9Mb9sCcY9SxFjthrk92YM3dT1VHR8QNc4kpj2MJfGQYAYKWBp2s9R9s6sheFx7DWCUezRkZrehDzenTqd.raspberry -p yourpassword -t 2

NOTE: on the command line the {key}.raspberry -p password, the .raspberry (worker name) and the password can be anything you invent yourself.
REMEMBER to replace the wallet address dot worker name with your own.
Set the t parameter equal to the number of cores your cpu has.  So if you have a 4 core cpu then it would be -t 4

In the console you will see, something like this

[2017-10-20 17:08:09] Using JSON-RPC 2.0
[2017-10-20 17:08:09] CPU Supports AES-NI: NO
[2017-10-20 17:08:09] Starting Stratum on stratum+tcp://xmr-eu1.nanopool.org:14444
[2017-10-20 17:08:09] 2 miner threads started, using 'cryptonight' algorithm.
[2017-10-20 17:08:09] Pool set diff to 120001
[2017-10-20 17:08:09] Stratum detected new block
[2017-10-20 17:08:10] thread 0: 26925360 hashes, 0.00 H/s
[2017-10-20 17:08:10] thread 1: 26925368 hashes, 0.00 H/s
.....
[2017-10-20 19:29:00] thread 1: 29985080 hashes, 0.00 H/s
[2017-10-20 19:29:35] thread 1: 29985080 hashes, 0.00 H/s
[2017-10-20 19:29:36] accepted: 1/1 (100.00%), 3.23 H/s at diff 120001 (yay!!!)

It works fine but the only issue is its only shows Hash rate if the share is accepted. Note that with some pools, your Hash Rate will be reported as zero for most of the time, until you suddenly submit a 'share' to the pool from your mining efforts. You will temporarily see your Hash Rate reported, after which it will return to zero. This is normal for some pools, and you do not need to worry that something is not working correctly. As long as after a while you see the "total hashes submitted" figure increase, then your mining setup is working. 
If you want limit CPU usage (75%) you install cpulimit

apt-get install cpulimit

and use

cpulimit -e minerd -l 75 -b 

To keep the miner running at all times, we should set up a daemon to run in the background. In Raspian you must install systemd using:

apt-get install systemd

Systemd, if being used, is the first processes executed in user space in the Linux startup process. If init was used then the first process would have been init. The first process will be the root of the user space’s process tree.

Let’s move to the system and make a service file:
cd /lib/systemd/system/

nano miner.service
and copy in

[Unit]
Description=monero miner daemon
[Service]
ExecStart=<put your minerd command here, example /usr/local/bin/minerd etc etc> 
Restart=always
User=root
Group=root
[Install]
WantedBy=multi-user.target
and Ctrl + X to save it and then reload it with:

systemctl daemon-reload
systemctl enable miner.service
systemctl start miner.service
If the service (minerd) dies, don't worry, Linux will start it again automatically. BTW, the minerd service will start up automatically on every boot.

To View the stdout/stderr of the systemd service

Just use the journalctl command, as in:
journalctl -u miner.service
Or, to see only log messages for the current boot:
journalctl -u miner.service -b



First of all, install NCDU

NCDU stands for NCurse Disk Usage which is Linux program that displays Disk usage statistics in a Ncurse menu, which makes things easier where you don’t know exactly where to start

apt install ncdu


Use dpkg-query to find the largest packages and remove the ones you don't need anymore.
dpkg-query --show --showformat='${Package;-50}\t${Installed-Size}\n' | sort -k 2 -n | grep -v deinstall | awk '{printf "%.3f MB \t %s\n", $2/(1024), $1}
If the application has been installed via the package manager, all you have to do is run
sudo apt-get remove <application_name>

sudo apt-get autoremove

#check partition sizes
df -h
#check directory size
du -s -h /var/log/
#check every directory and file sizes under a dir.
du -s -h /var/log/*


What is Dat?

Share, backup, and publish your filesystem. You can turn any folder on your computer into a dat. Dat scans your folder, allowing you to:
  • Track your files with automatic version history.
  • Share files with others over a secure peer to peer network.
  • Automate live backups to external HDs or remote servers.
  • Publish and share files with built in HTTP server.
First you must install Node.js

Just follow the steps below.
wget https://nodejs.org/dist/v8.6.0/node-v8.6.0-linux-armv7l.tar.gz
tar -xvf node-v8.6.0-linux-armv7l.tar.gz 
cd node-v8.6.0-linux-armv7l
Copy to /usr/local
sudo cp -R * /usr/local/
To check Node.js is properly installed and you have the right version, run the command node -v

Installing via npm

The Dat command line tool can be installed with npm:
npm install -g dat
Make sure you have node and npm installed first. 

Sharing Data

You can start sharing your website files with a single command:
dat share <dir>

<dir> is the path directory with your static website files. Use dat share mywebsitedir to create a dat and sync your files from your computer to other users. Dat scans your files inside <dir>, creating metadata in <dir>/.dat. Dat stores the public link, version history, and file information inside the dat folder.

Point your domain to your website, install dathttpd

A Web server for Dat and HTTPS.
Dat sites are hosted at public keys, which are the equivalent of IP addresses in the P2P network. The pubkeys are ugly, though! Wouldn't it be nice if your dats could have nice DNS shortnames, and also rehost over HTTPS for people still on legacy browsers? Follow these instructions
Create a config file .dathttpd.yml, 

letsencrypt:
  email: 'bob@foo.com'
  agreeTos: true
sites:
  mywebsite.com:
    url: dat://yourdaturl/
    datOnly: false
replace url with your DAT URL , after you must specify the path of the file .dathttpd.yml
In bash you can set the variable like this:
export DATHTTPD_CONFIG=/home/raspberry/
most other shells follow this convention, but not all. You can set it permanently in ~/.profile for bash (and as before, other shells have other locations). In the example /home/raspberry is the path where is the file.

Use the printenv command to print the names and values of all currently defined environment variables:
printenv 


Install dathttpd

# install build dependencies
sudo apt-get install libtool m4 automake

# install dathttpd 
npm install -g dathttpd

# give node perms to use ports 80 and 443
sudo setcap cap_net_bind_service=+ep `readlink -f \`which node\``

# start dathttpd
sudo dathttpd
[sudo] password for raspberry:
Serving from /home/raspberry/.dathttpd
le.challenges[tls-sni-01].loopback should be defined as function (opts, domain, token, cb) { ... } and should prove (by external means) that the ACME server challenge 'tls-sni-01' will succeed
Handling ACME challenges and redirecting to https on plain port 80
Handling ACME challenges and serving https 443
Serving dat.local dat://yourdaturl/

To daemonify the server, stop the dathttpd process and then run:
# install a helper tool
sudo npm install -g add-to-systemd

# create a systemd entry for dathttpd
sudo add-to-systemd dathttpd --user $(whoami) $(which dathttpd)

# start the dathttpd service
sudo systemctl start dathttpd
raspberry@raspberry-desktop:~$ sudo systemctl status dathttpd
â dathttpd.service
   Loaded: loaded (/lib/systemd/system/dathttpd.service; enabled; vendor preset:
   Active: active (running) since mer 2017-09-27 14:35:12 CEST; 1s ago
 Main PID: 3318 (node)
   CGroup: /system.slice/dathttpd.service
           Ã¢Ã¢3318 node /usr/local/bin/dathttpd

set 27 14:35:12 raspberry-desktop systemd[1]: Started dathttpd.service.

Before doing anything, create a backup. You can restore your server in case anything goes wrong. Go to the shell and start by running this command with no options:
  • sudo do-release-upgrade
If the new Ubuntu has not been released yet, you should see the following:
Sample Output
Checking for a new Ubuntu release
No new release found
In order to upgrade to  the last version  before its official release, specify the -d option in order to use the development release:
  • sudo do-release-upgrade -d
If you're connected to your system over SSH, you'll be asked whether you wish to continue.
Follow the on-screen instructions.
You will now see the packages that are going to be upgraded and the changes that are going to be made. Note that the upgrading process can take several hours, and you can't cancel the process once Ubuntu is upgrading.

After the upgrade has finished, you can confirm your server is running on the new version by executing the command

lsb_release -r
To shutdown your Raspberry Pi even when it’s crashed or frozen, you must have 
  1. ssh enabled, and
  2. access to another computer on the same network (you can even use your smartphone.)
Do the following command:

sudo shutdown -h now

You can’t use shutdown unless you have sudo privileges.
-h means halt the system
now means do it straight away. 
Suppose we have a Raspberry Pi connected to the TV with an HDMI cable and that uses the internet connection via Wifi. In this example, the operating system is Ubuntu Mate. What we want to get is to connect the Raspberry Pi directly to the home router using an Ethernet cable and set up a static IP address so that we can connect it later using SSH.

First of all, while we are connected to Wifi, we enable Raspberry to get a dynamic IP from the Ethernet cable. To enable this feature we will have to edit the file

/etc/network/interfaces

and add these 2 lines if they are not present

auto eth0
iface eth0 inet dhcp

the result file should be similar to this

# interfaces(5) file used by ifup(8) and ifdown(8)
# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d

# The loopback network interface
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet dhcp

Connect the Raspberry Pi to your router with the Ethernet cable and do a reboot.

From command line do: ifconfig



You should see a result similar to the one up. To find your Ethernet IP you have to look at the interface Eth0 and then look at the inet (IPv4) section, in the example is : 192.168.1.48

Use the route -n command and mark the values you get

raspberry@raspberry:~$ route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.1.1     0.0.0.0         UG    1024   0        0 wlan0
192.168.1.0     0.0.0.0         255.255.255.0   U     0      0        0 wlan0

My example values are

Gateway 192.168.1.1
Newtwork 192.168.1.0
NetMask 255.255.255.0

Now we have all informations we need to proceed

sudo nano /etc/network/interfaces


Comment the line about dynamic IP address and Eth0 interface by using #
add the line to obtain the static IP and the lines of your configuration as the example. This sets your static IP, and the appropriate settings for your resolv.conf. You'll notice it uses your local DNS, a Google DNS (8.8.8.8 and 8.8.4.4)  the final result must be similar to the follow.

# interfaces(5) file used by ifup(8) and ifdown(8)
# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d

# The loopback network interface
auto lo
iface lo inet loopback
auto eth0
#iface eth0 inet dhcp
allow-hotplug eth0
iface eth0 inet static
address 192.168.1.48
netmask 255.255.255.0
network 192.168.1.0
broadcast 192.168.1.255
gateway 192.168.1.1
dns-nameservers 192.168.1.1 8.8.8.8 8.8.4.4

All done! The Raspberry static IP via Ethernet cable will be 192.168.1.48 in our exmple. Last thing to do is to reboot the system.

sudo reboot
All versions of Windows PCs come with a Remote Desktop Connection (RDP) pre-installed. There are several different implementations of the same protocol for Linux, in this example we will use xrdp



To install xrdp on a Raspberry Pi running Raspbian or Ubuntu use in the command line shell:
sudo apt-get install xrdp

xrdp will be installed as a service and will be started automatically.
On a Windows PC, launch Remote Desktop Connection, you must use MSTSC.exe to open a remote desktop connection to your RaspberryPi. You'll be prompted for a username and password. This will be the same information you've entered when you logged into your RaspberryPi to setup XRDP. 

If you use a Windows 10 PC: In the search box on the taskbar, type Remote Desktop Connection, and then select Remote Desktop Connection. In Remote Desktop Connection, type the full name or IP of the remote RaspberryPi , and select Connect.

To setup a static IP for your Raspberry Pi via an Ethernet cable, read the tutorial 

http://awesomeprojectsxyz.blogspot.it/2017/09/how-to-connect-your-raspberry-pi-to.html

When you work to build a modern website based only on HTML5 and Javascript, you don't need complex configurations to verify how the end user will display the web site. A simple web server serving static files is the fastest and easiest solution, in this guide we will learn how to install Node.js and create a simple web server to use for our work. Node.js is a runtime environment for developing server-side web applications. In simple words, the Node.js platform makes it possible to run JavaScript programs on a server and also on your Raspberry Pi 2.



First of all, please run the following command in a shell or terminal

sudo apt-get update

Please wait! This command can be very slow, it downloads the package lists from the repositories and "updates" them to get information on the newest versions of packages and their dependencies.

Remove a program with similar name to node.js (it creates conflicts, so better remove it)

sudo apt-get --purge remove node

To install Node.js run the commands

sudo apt-get install nodejs
sudo apt-get install npm

Nice job! You have sucessfully installed nodejs and npm in your Raspberry Pi 2. You can see the version currently being used by the shell by typing:

node -v

If nothing happens and you have the error  node: No such file or directory create a symlink with the command

sudo ln -s /usr/bin/nodejs /usr/sbin/node

Create a folder called /var/www/ and navigate to that folder, it will be our work directory.

sudo mkdir /var/www 
cd /var/www

We are ready to start coding! We will create a simple Webserver to host static website. Install the dependencies 

npm install --save compression connect http serve-static

Create a folder called httpdocs, this folder will cointain your HTML file, images and js code you want to host.

sudo mkdir /var/www/httpdocs

For example create a file index.html

Create in /var/www a file named server.js and put this code inside:

or you can download the file

wget https://gist.githubusercontent.com/orfeomorello/704f8639a5afcf50871f/raw/2ca571e41e9bc4c2fd12578293bdcd08eda51a34/server.js

If you followed all the steps, typing the ls command you can see this dicrectory structure

httpdocs node_modules server.js

To start the web server, execute the script with the command

node server.js

This will create a local webserver running on port 8181, if you write this web addess in your browser http://localhost:8181/index.html you will view your website running (remember to put your files in /var/www/httpdocs folder). To stop running the server press ctrl + c

Do you want to make available your website directly on the Internet? Follow this other tutorial