-
Notifications
You must be signed in to change notification settings - Fork 5
How To Setup The Marketplace on a Raspberry Pi
Having the case prepared we need to get started with the basic setup of our Raspberry Pi (in this case Rasbery Pi 4 - with 4GB Ram).
First, we want to install Raspbian - we recommend installing Raspbian with desktop (Download latest version here). To do that plug the Pi's SD card in your computer and flash the Raspian Stretch Lite on it. Tip: To do that you can use Etcher.
After the flashing process finished, the SD card has been ejected from your computer. All you need to do is to plug it out and in to let the OS recognize it again. As soon as your boot drive has appeared to open your terminal and execute:
$ cd /Volumes/boot
Now we want to enable SSH, which is disabled by default on the Raspberry Pi. We simply create a file called ssh within the boot drive. To do that execute:
$ touch ssh
Even if the file is empty it will enable ssh as soon as the Pi boots.
Lastly, we also want the Pi to connect with wifi as soon as it boots. To do that we store the connection details at the boot drive of the Pi. Execute the following command:
$ nano wpa_supplicant.conf
Now go ahead and paste the following code in the file. Also, enter your wifi connection details and press ctrl + x to save the changes.
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
network={
ssid="YOUR_SSID"
psk="YOUR_WIFI_PASSWORD"
key_mgmt=WPA-PSK
}
Tip: If you intend to use the tool in different places you can easily setup multiple wifi configurations right now. By doing so you won't need to plug out the Pi's SD card when you change your location. If you want to do that just add the following code:
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
network={
ssid="SCHOOL_NETWORK_NAME"
psk="SCHOOL_PASSWORD"
id_str="school"
}
network={
ssid="HOME_NETWORK_NAME"
psk="HOME_PASSWORD"
id_str="home"
}
You can add as many networks as you want here by adding more network object.
Now we are ready to connect via SSH to the Pi.
We want to open a WIFI with the Raspberry, so we connect vie normal LAN to the Raspberry for configuration.
Checks the Raspberry Pi IP in your Router, or try to connect with the hostname "raspberrypi".
$ ssh pi@raspberrypi
Now you have to enter the default password "raspberry" and you're in!
For security reasons, let's change the default password of the user "pi. Input this command:
$ passwd
To connect to the Pi via SSH you can execute the following command:
$ sshpass -p <PASSWORD> ssh -o StrictHostKeyChecking=no pi@<IP_ADDRESS>
Tip: To make this process easier if you intend to repeat this multiple times in the future, you can create an alias to access the pi with something like marketplace
instead of the command above. To do so execute:
$ nano ~/.zshrc
Then simply create an alias be pasting this inside the file:
alias marketplace="sshpass -p <PASSWORD> ssh -o StrictHostKeyChecking=no pi@<IP_ADDRESS>"
Now, open a new tab and you are ready to connect to the pi by executing:
$ marketplace
Now you need to type in the current password again (raspberry) and then your new password and the confirmation.
Now you're safe and ready for the next step!
For this example, we need to install NodeJS and npm, and some Python libraries to control the e-ink display.
Install NodeJS
$ sudo apt-get update
$ sudo apt-get dist-upgrade
$ curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
$ sudo apt-get install -y nodejs
$ node -v
After the last command, you should see your node version.
sudo apt install git
Clone and run the marketplace backend
git clone https://github.com/open-marketplace-applications/marketplace-backend
cd marketplace-backend
npm install
Create a new file called .env
, take care of the leading dot! Add a new seed like in this example:
Please don't use an online seed generator to create a seed!
seed='REPLACE-THIS-WITH-YOUR-SEED'
socketOrigins=http://localhost:* http://127.0.0.1:*
Create a system service to run it on server start
$ sudo nano /etc/systemd/system/marketplace-backend.service
Add the following content
[Unit]
Description=Marketplace Backend Service
After=network.target
[Service]
WorkingDirectory=/home/pi/marketplace-backend
ExecStart=/usr/bin/npm start
Restart=on-failure
User=pi
Environment=PORT=3000
[Install]
WantedBy=multi-user.target
Add and start the service.
$ sudo systemctl enable marketplace-backend.service
$ sudo systemctl start marketplace-backend.service
That’s how you can see the logs:
$ journalctl -u marketplace-backend
Exit with CTRL+C and leave the backend directory.
$ cd ..
Clone and run the marketplace frontend application
git clone https://github.com/open-marketplace-applications/marketplace
cd marketplace
npm install
npm build
Create a new file called .env
, take care of the leading dot! Add a the following entrie seed like in this example. Replace the Example values with your local community
Please don't use an online seed generator to create a seed!
BASE_URL=http://localhost:3000
CITY_URL=http://localhost:5000
CITY_TITLE="Open Marketplace"
CITY_DESCRIPTION="Online Shopping, News, Donations and more."
CITY_LATITUDE=46.711456
CITY_LONGITUDE=10.951586
CITY_HERO_IMGAE_URL="https://upload.wikimedia.org/wikipedia/commons/thumb/0/0d/Bozen_seen_from_east.jpg/1920px-Bozen_seen_from_east.jpg"
MVM=9
Create a system service to run it on server start
$ sudo nano /etc/systemd/system/marketplace.service
Add the following content
[Unit]
Description=Marketplace Frontend Service
After=network.target
[Service]
WorkingDirectory=/home/pi/marketplace
ExecStart=/usr/bin/npm start
Restart=on-failure
User=pi
Environment=PORT=3000
[Install]
WantedBy=multi-user.target
Add and start the service.
$ sudo systemctl enable marketplace.service
$ sudo systemctl start marketplace.service
That’s how you can see the logs:
$ journalctl -u marketplace
Exit with CTRL+C and leave the backend directory.