Difference between revisions of "Node-HIU Installation"

From Heatweb Wiki
Jump to: navigation, search
(Pi Zero Updates)
(Node-HIU Basic Install)
 
Line 4: Line 4:
 
sudo apt-get update
 
sudo apt-get update
 
sudo apt-get upgrade
 
sudo apt-get upgrade
wget https://raw.githubusercontent.com/node-red/raspbian-deb-package/master/resources/update-nodejs-and-nodered
+
bash <(curl -sL https://raw.githubusercontent.com/node-red/linux-installers/master/deb/update-nodejs-and-nodered)
bash update-nodejs-and-nodered
+
 
wget http://www.heatweb.info/updatefiles/node-hiu-install-min.sh
 
wget http://www.heatweb.info/updatefiles/node-hiu-install-min.sh
 
bash node-hiu-install-min.sh
 
bash node-hiu-install-min.sh

Latest revision as of 01:02, 1 November 2019

Node-HIU Basic Install

sudo apt-get update
sudo apt-get upgrade
bash <(curl -sL https://raw.githubusercontent.com/node-red/linux-installers/master/deb/update-nodejs-and-nodered)
wget http://www.heatweb.info/updatefiles/node-hiu-install-min.sh
bash node-hiu-install-min.sh
passwd (to set new password)
sudo reboot

Go to http://url_of_device:1880/ui for setup screen.

The following will reset the installation flow.

curl -L http://www.heatweb.info/updatefiles/node-hiu-setup.sh | bash

Installation Script

To simplify the process of upgrading your Raspberry Pi, and installing the basic Thermal Integration Node-HIU system, we have developed a script to run through the steps automatically.

Start with a fresh Raspbian installation from https://www.raspberrypi.org/downloads/raspbian/

The following commands are done over SSH. From a fresh installation you will need to connect your Pi to a display, keyboard, and mouse and boot up the desktop. From there you can configure the options, turning on SSH so we can continue without the monitor. On should do the following:

  • Setup any WiFi connections needed, and take not of the IP address
  • Turn on SSH
  • Change hostname
  • Change password
  • Change to boot to command line
  • Reboot

Then SSH into the system and run the commands below.

Press y followed by ENTER when prompted.

After the last command runs the system should reboot. Ignore any error codes, and it may seem like it has hung at times - be patient (5 minutes at one point).


sudo apt-get update

sudo apt-get upgrade

wget https://raw.githubusercontent.com/node-red/raspbian-deb-package/master/resources/update-nodejs-and-nodered

bash update-nodejs-and-nodered

node-red-start 
CTRL-C (to exit node-red screen after 1 minute)

node-red-stop

wget http://www.heatweb.info/updatefiles/node-hiu-install.sh

bash node-hiu-install.sh

curl -L http://www.heatweb.info/updatefiles/node-hiu-update.sh | bash

Finally, it sometimes worth mounting the SD card as read only file system, with nothing been written to the SD card, such as Linux log files. This is to maintain SD card reliability.

Note, this measure stops the Apache web server and PHP from working, so should only be used where all tasks are done through Node-RED or Python.

It requires Raspbian Lite. See https://learn.adafruit.com/read-only-raspberry-pi?view=all. for more information.

wget https://raw.githubusercontent.com/adafruit/Raspberry-Pi-Installer-Scripts/master/read-only-fs.sh
sudo bash read-only-fs.sh

You can find the system on your network at http://ip_address:1880/ui

ALWAYS CHANGE THE DEFAULT PASSWORD FOR THE USER pi

Automation Phat

curl https://get.pimoroni.com/automationhat | bash


Reverse Proxy for Public Web Portals

https://www.raspberrypi.org/forums/viewtopic.php?t=34291

1. Make a backup folder for all of the files you are about to modify
sudo mkdir /home/pi/backupfiles

2. Configure a Static IP for the Raspberry Pi
a. Make a backup of your interfaces file
sudo cp /etc/network/interfaces /home/pi/backupfiles/interfaces.backup
b. Edit the interfaces file
sudo nano /etc/network/interfaces
c. Delete the line 
iface eth0 inet dhcp
d. Add the following 4 lines to the interfaces file where you deleted the line above.
iface eth0 inet static
address 192.168.0.120
netmask 255.255.255.0 
gateway 192.168.0.1
e. Save the file and afterwards reboot the system
sudo shutdown -r now
f. When the system reboots ensure that no errors regarding the interfaces file shows on your monitor.

3. Install ddClient you will need this software to send the IP address of your router to dnsdynamic.org a. sudo apt-get install ddclient b. Answer the following questions After this operation, 1,774 kB of additional disk space will be used. Do you want to continue [Y/n]?: Y Dynamic DNS service provider: other Dynamic DNS server: http://www.dnsdynamic.org Dynamic DNS update protocol: dyndns2 Username of dynamic DNS service: enter your login for dnsdynamic.org Password for dynamic DNS service: enter your password for dnsdynamic.org Network interface used for dynamic DNS service: eth0 DynDNS fully qualified domain names: exampleurl.dnsdynamic.com c. Edit the ddclient conf file sudo nano /etc/ddclient.conf d. change the 6th line FROM use=if, if=eth0 TO use=web, if=eth0 e. Save the file and reboot the system sudo shutdown -r now f. If no errors show up during your reboot make a copy of the ddclient.conf file. sudo cp /etc/ddclient.conf /home/pi/backupfiles/ddclient.conf.backup g. Login at http://www.dnsdynamic.org and see if your router IP address shows up.

4. Create your self signed SSL certificates a. Make a directory for the certificates sudo mkdir /home/pi/certificates b. Navigate to that directory cd /home/pi/certificates b. Generate the private key sudo openssl genrsa -des3 -out exampleurl.dnsdynamic.com.key 2048 -- you will be prompted (twice) for a password for the key do not forget it c. Generate the Certificate Signing Request sudo openssl req -new -key exampleurl.dnsdynamic.com.key -out exampleurl.dnsdynamic.com.csr -- at the prompts feel free to either enter values or simply press the enter key to accept the shown default value. d. Generate the self signed certificate (good for 12 years) sudo openssl x509 -req -days 4380 -in exampleurl.dnsdynamic.com.csr -signkey exampleurl.dnsdynamic.com.key -out exampleurl.dnsdynamic.com.crt -- you will be prompted for the private key password e. Generate a key that does not have a password sudo openssl rsa -in exampleurl.dnsdynamic.com.key -out exampleurl.dnsdynamic.com.unsecure.key 5. Install nginx sudo apt-get install nginx a. Answer the question After this operation, 6,134 kB of additional disk space will be used. Do you want to continue [Y/n]?: Y b. Make a backup of the nginx config file sudo cp /etc/nginx/sites-enabled/default /home/pi/backupfiles/nginx.default.backup c. Edit the nginx config sudo nano /etc/nginx/sites-enabled/default d. Add the following lines near the top of the server section

listen 443; ssl on; ssl_certificate /home/pi/certificates/exampleurl.dnsdynamic.com.crt; ssl_certificate_key /home/pi/certificates/exampleurl.dnsdynamic.com.unsecure.key;

location /cameraup/ { proxy_pass http://192.168.0.33:6474/; proxy_redirect off; proxy_set_header Host $host:$server_port; proxy_set_header X-Real-IP $remote_addr; } location /cameradown/ { proxy_pass http://192.168.0.34:6475/; proxy_redirect off; proxy_set_header Host $host:$server_port; proxy_set_header X-Real-IP $remote_addr; } e. change the server_name from localhost to your domain name server_name exampleurl.dnsdynamic.com; f. Save the file and see if you made any mistakes by reloading nginx sudo service nginx reload g. If no errors reboot


sudo nano /etc/nginx/sites-enabled/default

server {
        listen 80 default_server;
        listen [::]:80 default_server;

        listen 443;
        ssl on;
        ssl_certificate /home/pi/certificates/heatweb.ddns.net.crt;
        ssl_certificate_key /home/pi/certificates/heatweb.ddns.net.unsecure.key;

        location /home/ {
                if ($scheme = http) {
                        return 301 https://$server_name$request_uri;
                }
                proxy_pass http://localhost:1880/ui/;
                proxy_set_header Host $host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection "upgrade";
        }

        location /modbus/ {
                if ($scheme = http) {
                        return 301 https://$server_name$request_uri;
                }
                proxy_pass http://localhost:1880/ui/;
                proxy_set_header Host $host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection "upgrade";
        }

       location /hiu/ {
                if ($scheme = http) {
                        return 301 https://$server_name$request_uri;
                }
                proxy_pass http://192.168.0.55:1881/ui/;
                proxy_set_header Host $host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection "upgrade";
        }


        root /var/www/html;

        # Add index.php to the list if you are using PHP
        index index.html index.htm index.nginx-debian.html;

        server_name heatweb.ddns.net;


        # pass PHP scripts to FastCGI server
        #
        #location ~ \.php$ {
        #       include snippets/fastcgi-php.conf;
        #
        #       # With php-fpm (or other unix sockets):
        #       fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
        #       # With php-cgi (or other tcp sockets):
        #       fastcgi_pass 127.0.0.1:9000;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #       deny all;
        #}
}
sudo service nginx reload


Pi Zero Updates

Where problems occur on the Pi Zero, it may be related to Node been the wrong version for the CPU. Fixed by running.

sudo apt-get remove nodejs
sudo apt-get remove npm

Then go to /etc/apt/sources.list.d and remove any node list if you have. Then do a

sudo apt-get update

Then run basic installation.