17 February 2021

how to setup raspberry pi as a geo(web)server part 1-- setup postgresql on the raspberry pi

 How to setup Raspberry pi 4 as a geoserver


prepare:

1. raspberry pi 4. I am using the 2GB version.

2. install ubuntu server on the pi4.

3. Internet/Wifi connection

4. basic knowledge of computer and linux terminal.


Step1. Using SSH login on the pi 4. 

1.1 start terminal

1.2 ssh login on your server

ssh ubuntu@YOURSERVERIP


step2: keep your server up to date

sudo apt install

sudo apt upgrade


step3 install postgresql


read https://tecadmin.net/install-postgresql-server-on-ubuntu/


sudo apt-get install wget ca-certificates


ok


sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ `lsb_release -cs`-pgdg main" >> /etc/apt/sources.list.d/pgdg.list'


sudo apt-get update

sudo apt-get install postgresql postgresql-contrib


result:


Success. You can now start the database server using:


    pg_ctlcluster 13 main start


install postgis extension for postgresql


sudo apt install postgis postgresql-13-postgis-2.5


check database:

1.Switch to postgres user.


sudo -i -u postgres


2. create database, 

createdb postgis25


psql -d postgis25


3. create extension postgis;

4. select postgis_version();


ctrl + d, two times return to normal terminal


install import tool gdal

sudo apt install gdal-bin


import a ESRI shapefile (WORLD boundary) to database. 

mkdir geodata

cd geodata

wget https://opendata.arcgis.com/datasets/a21fdb46d23e4ef896f31475217cbb08_1.zip


sudo apt install zip 

unzip a21fdb46d23e4ef896f31475217cbb08_1.zip


sudo -i -u postgres


ogr2ogr -f PostgreSQL PG:dbname=postgis25 -progress -lco SCHEMA=public -nlt PROMOTE_TO_MULTI 99bfd9e7-bb42-4728-87b5-07f8c8ac631c2020328-1-1vef4ev.lu5nk.shp


login into database 


psql -d postgis25


to get all tables

\dt


get the first feature


SELECT objectid,cntr_name from lu5nk limit 1;


to quit

\q


using cmd htop check raspberry resources after install postgres



[2021-05-08] Unfortunately, the project is onhold. I am using the machine for another project. Right now, I installed MotionEyeOS on it. The project is about wiring doorbell with esp32(micro python) Microcontroler. With the doorbell triggered, a call will be made to webhook or webserver, then send rich notification(timestamp with snapshot of Raspberry Pi camera) to my email or mobile.