Develop RaspberryPI Get started0 - aliconnect/aliconnect.sdk GitHub Wiki
https://www.realvnc.com/en/connect/download/viewer/windows/
- Open a terminal on your Raspberry Pi or use the PiTunnel Remote Terminal.
- Enter the command
sudo raspi-config
. - Use the arrow keys to select Interfacing Options and press Enter.
- Use the arrow keys to select VNC and press Enter.
- You will be prompted to enable VNC Server.
default
- ip:
192.168.0.137
- username:
pi
- password:
raspberry
sudo apt-get update
sudo apt-get install vsftpd
Once installed you can now edit the vsftpd configuration file using :
sudo nano /etc/vsftpd.conf
In this file find the following lines and un-comment them by deleting the # character :
anonymous_enable=NO
local_enable=YES
write_enable=YES
local_umask=022
chroot_local_user=YES
Add the following lines to the end of the file :
user_sub_token=$USER
local_root=/home/$USER/Control
allow_writable_chroot=YES
Save and exit using CTRL-X, Y and ENTER.
To allow you to connect to the FTP server using the default Pi user we need to create a few directories :
mkdir /home/pi/Control
Change the permissions on the ftp directory using :
sudo chmod 777 /home/pi/Control
Finally restart the vsftpd service so that our changes take effect :
sudo service vsftpd restart
Install Node.js on Raspberry Pi With the Raspberry Pi properly set up, login in via SSH, and update your Raspberry Pi system packages to their latest versions.
Update your system package list:
sudo apt update
sudo apt autoremove
sudo apt-get update --fix-missing
sudo apt full-upgrade
sudo apt-get dist-upgrade
To download and install newest version of Node.js, use the following command:
curl -fsSL https://deb.nodesource.com/setup_17.x | bash -
naar Root user
sudo su
curl -fsSL https://deb.nodesource.com/setup_14.x | bash -
Now install it by running:
apt-get install -y nodejs
Terug naar pi user
su pi
Check that the installation was successful, and the version number of Node.js with:
node -v
npm -v
sudo npm i @aliconnect/sdk
sudo chmod 777 /home/pi/Control/node_modules/@aliconnect/sdk
sudo npm cache clean --force
sudo apt remove nodejs npm
uname -m
wget https://nodejs.org/dist/v8.9.0/node-v8.9.0-linux-armv7l.tar.gz
tar -xzf node-v8.9.0-linux-armv7l.tar.gz
cd node-v8.9.0-linux-armv7l
sudo cp -R * /usr/local/
sudo apt full-upgrade
https://aliconnect.nl/sites/rc/truck/pi/control/root/rctruck.html?client_id=5ebabb5e-0a5b-4c87-a970-1919a4680fb1
http://192.168.0.135:8080/rctruck.html
@todo client_id in browser URL samen met inloggen en scope die voldoet aan diverse zaken, controle met secret, dan werkt het.
voldoet acces van gebruiker niet client_secret, dan doorcontroleren naar device. Alleen met juiste secret werkt het. de client_secret hoort bij de device. Maakt onderdeel uit van een verdergaande certificering. Dus iemand die hogere rechten heeft kan een device aansturen. Gebruiker met acces hebben tot device. middel scope of token.
-
ws_client
: URL of AIM Websocket Server -
client_id
: Unique identifier of client application -
ws
:
{
"ws_client":"wss://aliconnect.nl:444",
"client_id":"5ebabb5e-0a5b-4c87-a970-1919a4680fb1",
"ws": {
"port": 8080
},
"wss": {
"protocol": "ws",
"address1": "192.168.1.122",
"address": "192.168.0.201",
"port": 81
}
}
- Client does WebSocket Connect to
ws_client
- Server on
connection
- Set
remoteAddress
- Set
- Client on
open
- send
{ ip_addresses: { "192.168.0.135" : "b8:27:eb:39:8c:bb" } }
- send
{
"ip_addresses": {
"192.168.0.135" : "b8:27:eb:39:8c:bb"
},
"client_id": "#config.client_id"
}
- Unsecure public client_id : These control devices will be configured without identification.
- Secure local client_id : These control devices are connected to a local AIM server and must be accepetd by a administrator
- An acces token is send to the connected device based on the client_id
- The device will request a configuration and related scope at the Websocket Server
- This WS request is send to an ObjectManager with logged in user with admin scope
- The user will select the correct configuration and accept the related scope for the device. This is send to the OAuth Server including configured IP-address.
- The OAuth server will send a code (containing scope) to the device IP-Address
- With the code (that includes scope) the Device will HTTP Request an access_token and refresh_token at the OAuth server. The OAuth server will respond with generate id_token, access_token and refresh_token. Access_token is valid for 1 hour.
- The Device will save refresh_token on the device to refresh the access_token when expired.
-
The device will HTTP request an access token at the OAuth server
-
The device will WS Request the correct configuration at the AIM Server wich will repond with a JSON body with all required control data. This body can include Javascript.
-
The request is broadcast to OM apps on the socket netwerk
-
A OM with loggedin user with admin prefilages will present a message that a new device is Connected
-
The user will generate an refresh_token with the correct configuration properties
-
The configuration properties are send to the connected device.
-
Server on
message
- set
mac
to IP address related mac address
- set
md project\pi\control\node_modules
mklink /D "C:\aim\aim-server\root\sites\rc\truck\pi\control\node_modules\aim-control" "C:\aim\aim-control"
https://medium.com/@tbusser/creating-a-browser-trusted-self-signed-ssl-certificate-2709ce43fd15
mklink /D "E:\Path\Symlink_Books" "F:\Books"
openssl genrsa -des3 -out AliconnectCA.key 4096
openssl req -x509 -new -nodes -key AliconnectCA.key -sha256 -days 1024 -out AliconnectCA.crt
openssl genrsa -out %1.key 2048
openssl req -new -sha256 -key %1.key -subj "/C=US/ST=CA/O=MyOrg, Inc./CN=%1" -out %1.csr
openssl x509 -req -in %1.csr -CA aimCA.crt -CAkey aimCA.key -CAcreateserial -out %1.crt -days 500 -sha256
Attention: this is the key used to sign the certificate requests, anyone holding this can sign certificates on your behalf. So keep it in a safe place!
openssl genrsa -des3 -out aliconnectCA.key 4096
If you want a non password protected key just remove the -des3 option
openssl req -x509 -new -nodes -key aliconnectCA.key -sha256 -days 1024 -out aliconnectCA.crt
Here we used our root key to create the root certificate that needs to be distributed in all the computers that have to trust us.
This procedure needs to be followed for each server/appliance that needs a trusted certificate from our CA
openssl genrsa -out mydomain.com.key 2048
The certificate signing request is where you specify the details for the certificate you want to generate. This request will be processed by the owner of the Root key (you in this case since you create it earlier) to generate the certificate.
Important: Please mind that while creating the signign request is important to specify the Common Name providing the IP address or domain name for the service, otherwise the certificate cannot be verified.
I will describe here two ways to gener
If you generate the csr in this way, openssl will ask you questions about the certificate to generate like the organization details and the Common Name (CN) that is the web address you are creating the certificate for, e.g mydomain.com.
openssl req -new -key mydomain.com.key -out mydomain.com.csr
This method generates the same output as Method A but it's suitable for use in your automation :) .
openssl req -new -sha256 -key mydomain.com.key -subj "/C=US/ST=CA/O=MyOrg, Inc./CN=mydomain.com" -out mydomain.com.csr
If you need to pass additional config you can use the -config parameter, here for example I want to add alternative names to my certificate.
openssl req -new -sha256 \
-key mydomain.com.key \
-subj "/C=US/ST=CA/O=MyOrg, Inc./CN=mydomain.com" \
-reqexts SAN \
-config <(cat /etc/ssl/openssl.cnf \
<(printf "\n[SAN]\nsubjectAltName=DNS:mydomain.com,DNS:www.mydomain.com")) \
-out mydomain.com.csr
```
Verify the csr's content
openssl req -in mydomain.com.csr -noout -text
Generate the certificate using the mydomain csr and key along with the CA Root key
openssl x509 -req -in mydomain.com.csr -CA rootCA.crt -CAkey rootCA.key -CAcreateserial -out mydomain.com.crt -days 500 -sha256
Verify the certificate's content
openssl x509 -in mydomain.com.crt -text -noou
# SSL
## Open SSL
openssl genrsa -des3 -out rootCA.key 4096
## Setup development environment on windows PC
### File synchronisation between PC and PI
#### Get current IP Address
## Configure PI configuratie
To develop and use the PI as a controller we need to setup the PI configuration. This includes settings form
- Using I2C Bus
- Using RealVNC
- Using ssh
Open a command promt and typeof
sudo raspi-config
Now naviagte through the menu and change the specified options
- 5 Interfacing Options
- P5 I2C
- <Ja>
- <Ok>
- <Finish>
- 5 Interfacing Options
- P2 SSH
- <Ja>
- <Ok>
- <Finish>
- 5 Interfacing Options
- P3 VNC
- <Ja>
- <Ok>
- <Finish>
- Close
#### Enable interfacing options SSH
We activeren SSH op de Raspberry PI
sudo raspi-config
5 Interfacing Options P2 SSH
#### WinSCP
https://ninite.com/winscp/
Ga naar de website https://winscp.net/eng/docs/lang:nl en download WinSCP via de link https://winscp.net/download/WinSCP-5.15.3-Setup.exe
Installer WInSCP en start het programma
Maak verbinding met 192.168.1.132
#### FileZilla
- Bestand/Sitebeheer
- New Site
- Algemeen
- Protocol: SFTP - SSH File Transfer protocol
- Host: {PI IP Address}
- Poort: 22
- Inlogtype: Normaal
- Gebruiker: pi
- Wachtwoord: {pi admin password}
- Geavanceerd
- Standaard lokale map: `C:\aim\node\aim-control\`
- Standaard externe map: /home/pi
- Gesynchroniseerd bladeren gebruiken
#### Atom
##### Remote-sync
{ "logger": { "title": "Remote Sync" }, "uploadOnSave": true, "useAtomicWrites": false, "deleteLocal": false, "hostname": "{PI IP Address}", "port": "22", "ignore": [ ".remote-sync.json", ".git/**" ], "target": "/home/pi", "username": "pi", "password": "{pi admin password}", "watch": [], "transport": "scp" }
### Install PI Remote Desktop RealVNC
#### Configure PI
sudo raspi-config
5 Interfacing Options
P3 VNC
<Ja>
<Ok>
<Finish>
#### Install VNC Viewer
Next we need to install RealVNC Viewer on the computer you want to access the Pi from. Download RealVNC Viewer here and open the .exe file. It's a portable application, so you don't need to install it:
Download Real VNC op https://www.realvnc.com/en/connect/download/viewer/ en installer de applicatie.
Aanpassen scherm resolutie VNC
sudo nano /boot/config.txt
Invoeren
hdmi_force_hotplug=1 hdmi_ignore_edid=0xa5000080 hdmi_group=2 hdmi_mode=16
Maak verbinding met je PI via adres 192.168.1.132, Gebruiker pi en wachtwoord {pi_password}
Nu kunnen we het Scherm van de PI en toetsenbord en muis ontkoppelen.
### Atom code Editor
Installeer Atom voor het schrijven van code
### PC IP address
Bekijk je eigen IP adres door te gaan naar de MS-DOS command promt middel CTRL+R en type
cmd
Type in je command scherm
ipconfig /all
en bekijk je IP adres. Voeg indien nodig een eigen IP adres toe in de range 192.168.1.*. bijvoorbeeld 192.168.1.201.
Nodig om dients te oden asl Event Manager
Bekijk tevens je DNS (Domain Name Server) IP adres. Deze is belangrijk om goed in te voeren op de PI omdat deze anders geen internet meer kan vinden.
## Setup a Raspberry-PI
###
### Connect PI
Plaats de stick in de PI, sluit een scherm aan via de HDMI port en een toetsenbord en muis.
Schakel de PI aan en alle software wordt geinstalleerd. Updates worden opgehaald.
Remote Control Module part of the AIM platform based on the Raspberry-PI.
Download PI software
Download Raspbian PI with Desktop
Browser url
https://www.raspberrypi.org/downloads/raspbian/
Maak een bootable PI memmory SD card
https://www.raspberrypi.org/documentation/installation/sdxc_formatting.md
Wij gebruiken SD Card formatter
Setup zie SD_CardFormatter0500SetupEN
??
https://etcher.io/
### Create SD Card
1. [Burn SD Card](https://www.osforensics.com/tools/write-usb-images.html).
1. [sdxc_formatting](https://www.raspberrypi.org/documentation/installation/sdxc_formatting.md)
1. [https://etcher.io/](https://etcher.io/)
### Setup PI Wifi
1. Start PI Desktop
1. Stel WiFi via knop rechts boven. Selecteer WiFi.
### Open PI Commandprompt
Klik in je dahsbord op de prompt icon links boven.
### Installation
### Install node.js
We installern node js en npm. Node is onze webserver en websocket server.
sudo apt-get update --fix-missing sudo apt-get install -y nodejs npm
#### Installeren aim-control
npm install aim-control
## Instellen autoomatisch opstart opties
Setup procedure to autostart the PI with correct service. This includes
- forever
- chromium browser in kiosk mode
### Setup forever
Hiervoor moeten we een service installeren genaamd forever.
sudo npm -i install forever g
Nu kunnen we kijken of de app start met
forever start control.js
We stoppen de service met
forever stop app.js
### Modify autostart
Open a command prompt and type the command
sudo nano /home/pi/.config/lxsession/LXDE-pi/autostart
This will open the editor. Change this file as described.
@lxpanel --profile LXDE-pi @pcmanfm --desktop --profile LXDE-pi #@xscreensaver -no-splash #@point-rpi @xset s off @xset -dpms @xset s noblank @sed -i 's/"exited_cleanly":false/"exited_cleanly":true/' /home/pi/.config/chromium/Default/Preferences #@chromium-browser --start-fullscreen --disable-session-crashed-bubble --noerrdialogs --no-default-browser-check --no-first-run --disable-infobars --kiosk https://aliconnect.nl/aliconnector @chromium-browser --start-fullscreen --disable-session-crashed-bubble --noerrdialogs --no-default-browser-check --no-first-run --disable-infobars --kiosk http://localhost:8080/index.html @forever start control.js
Save file with [CTRL]+[O], [Enter]
Quit editor with [CTRL]+[X]
Test autostart with commandline
reboot
### Control config.json
Downloaded from aim event manager on connection based on IP-address or MAC-address. Includes access-token.
#### Controller WebServer and WebSocketServer configuration
Default port is 8080.
"ws": { "port": 8080 },
#### Controller WebServer and WebSocketServer SSL configuration
SSL required for special functons browsers. See ...
"ssl": { "key": "./cert/aim_control_192_168_1_101.key", "cert": "./cert/aim_control_192_168_1_101.cer", "port": 8443 },
- [ ] SSL certificates aanmaken voor ieder IP address (255) of tool die dit doet op internet na invoeren IP address
#### AIM Event Manager WebSocketServer
"ws": { "wss": { "protocol": "ws", "address": "192.168.0.201", "port": 81 }, },
#### client
"client": { "device_id": "5ebabb5e-0a5b-4c87-a970-1919a4680fb1" },
#### access_token
"access_token": "{header}.{payload}.{signature}",
## Activeer I2C op de PI
sudo raspi-config
5 Interfacing Options P5 I2C
Kijk met WinSCP of bestand /dev/i2c-1 bestaat. Dit bestand maken we lees en schrijfbaar.
sudo chmod o+rw /dev/i2c*
### Bekijk alle I2C aangesloten modules
i2cdetect -y 1
### Aanpassen I2C Adres
Verbind A0,A1 en/of A2 met de GND of de VDD (+3.3V) om een binaire code te maken
111 = Adres 20
### Node modules
npm install node-mcp23017 --save
## help
### Shut down PI with command
sudo shutdown -h now
## Options
### Setup fixed IP address1
Optional, the controller will identify itself with it's IP and MAC address. These are used to configure the device. In special environments a fixed IP address is required. In tha case follow the next instruction.
Open a PI commandprompt and enter command:
sudo nano /etc/dhcpcd.conf
You'll now carry out the configuration of the static IP address. If your Raspberry Pi is connected to the internet via an Ethernet or network cable, then enter the command 'interface eth0'; if it takes place over Wi-Fi, then use the 'interface wlan' command.
To assign an IP address to Raspberry Pi, use the command 'static ip_address=' followed by the desired IPv4 address and the suffix '/24' (an abbreviation of the subnet mak 255.255.255.0). For example, if you want to link a computer with the IPv4 address 192.168.0.4, then you need to use the command 'static ip_address=192.168.0.4/24'. It goes without saying that the address used here is not yet used anywhere else. As such, it also can't be located in the address pool of a DHCP server.
You still then need to specify the address of your gateway and domain name server (usually both are the router). Raspberry Pi turns to the gateway address if an IP address to which it wants to send something is outside of the subnet mask (in the example, this would mean outside of the range 192.168.0). In the following command, the IPv4 address 192.168.0.1 is used as an example as both the gateway and DNS server. The complete command looks like this in our example (where a network cable is used for the internet connection):
interface eth0 static ip_address=192.168.1.131/24 static routers=192.168.1.1 static domain_name_servers=192.168.1.1
interface wlan0 static ip_address=192.168.1.132/24 static routers=192.168.1.1 static domain_name_servers=192.168.1.1
sudo reboot
Open a PC commandpromtp and enter command:
ping 192.168.1.131
#### Check current IP address
Open commandpromt and enter command
ifconfig
IP adres is visble after the text net
#### Modify default net settings of PI
Open commandpromt and enter command
sudo raspi-config
# Node
npm install onoff
# NEXT
npm install express npm install websocket
Now reboot the Pi with `sudo reboot`.
# Node.js Raspberry Pi GPIO
## What is GPIO?
GPIO stands for General Purpose Input Output.
The Raspberry Pi has two rows of GPIO pins, which are connections between the Raspberry Pi, and the real world.
Output pins are like switches that the Raspberry Pi can turn on or off (like turning on/off a LED light). But it can also send a signal to another device.
Input pins are like switches that you can turn on or off from the outside world (like a on/off light switch). But it can also be a data from a sensor, or a signal from another device.
That means that you can interact with the real world, and control devices and electronics using the Raspberry PI and its GPIO pins!
## Taking a Closer Look at the GPIO Pins
This is an illustration of the Raspberry Pi 3.
The GPIO pins are the small red squares in two rows on the right side of the Raspberry Pi, on the actual Raspberry Pi they are small metal pins.
The Raspberry Pi 3 has 26 GPIO pins, the rest of the pins are power, ground or "other".
The pin placements correspond with the table below.
## Install the onoff Module
To interface with the GPIO on the Raspberry Pi using Node.js, we will use a Module called "onoff".
Install the onoff module using npm:
pi@raspberry:~ $ npm install onoff
Now onoff should be installed and we can interact with the GPIO of the Raspberry Pi.
Using the GPIO for Output
In this chapter we will use a Raspberry Pi and its GPIO to make a LED blink.
We use Node.js with the onoff module to control the GPIO.
To get a LED light to turn on, we use a GPIO pin as "Output", and create a script to turn it on and off (blinking).
Building the Circuit
Now it is time to build the circuit on our Breadboard.
If you are new to electronics, we recommend you turn off the power for the Raspberry Pi. And use an anti-static mat or a grounding strap to avoid damaging it.
Shut down the Raspberry Pi properly with the command:
pi@w3demopi:~ $ sudo shutdown -h now
After the LEDs stop blinking on the Raspberry Pi, then pull out the power plug from the Raspberry Pi (or turn of the power strip it is connected to).
Just pulling the plug without shutting down properly may cause corruption of the memory card.
Look at the above illustration of the circuit.
On the Raspberry Pi, connect the female leg of the first jumper wire to Ground. You can use any GND pin. In this example we used Physical Pin 9 (GND, row 5, left column)
On the Breadboard, connect the male leg of the first jumper wire to the Ground Bus column on the right. That entire column of your breadboard is connected, so it doesn't matter which row. In this example we have attached it to row 1
On the Raspberry Pi, connect the female leg of the second jumper cable to a GPIO pin. In this example we used Physical Pin 7 (GPIO 4, row 4, left column)
On the Breadboard, connect the male leg of the second jumper wire to the Tie-Point row of your choice. In this example we connected it to row 5, column A
On the Breadboard, connect one leg of the resistor to the Ground Bus column on the right side. That entire column of your breadboard is connected, so it doesn't matter which row. In this example we have attached it to row 5
On the Breadboard, connect the other leg of the resistor to the right side Tie-Point row of your choice. In this example we have used row 5, column J
On the Breadboard, connect the cathode leg (the shortest leg) of the LED to the same Tie-Point row that you connected the resistor from GND to. In this example we used row 5, column F
On the Breadboard, connect the anode leg (the longest leg) of the LED to the same Tie-Point row that you connected the jumper from the GPIO pin to. In this example we used row 5, column E
Your circuit should now be complete, and your connections should look pretty similar to the illustration above.
Now it is time to boot up the Raspberry Pi, and write the Node.js script to interact with it.
Enable WinSCP
Enable Remote Desktop
I2C ON PI
Hardware
MCP23017
MCP23017-9 VDD <-> PI J8-1 +3.3VDC
MCP23017-10 VSS <-> PI J8-6 GND
MCP23017-12 SCK <-> PI J8-5 GPIO3 SCL1 I2C
MCP23017-13 SDA <-> PI J8-3 GPIO2 SDA1 I2C
MCP23017-15 A0 <-> PI J8-6 GND
MCP23017-16 A0 <-> MCP23017-10 VSS
MCP23017-17 A1 <-> MCP23017-10 VSS
MCP23017-18 A2 <-> MCP23017-10 VSS
MCP23017-19 RESET <-> MCP23017-9 VDD
MCP23017-1 GPB0<-> R330Ohm <-> LED <-> MCP23017-9 VDD
adres select = 000 = adres 20
# Using I2C Bud for Remote Control Modules
## Hardware
## Configure the PI
sudo i2cdetect -y 1
resultaat
20: 20 -- -- -- -- -- -- -- -- --...
## Install node.js module
npm install i2c-bus
# Add sound
When activating servo-blaster there is a noise on the speaker. This is the result of using PWM signal. This can't be resolved. You need to connect a sound system through the USB connector.
## options- Use a HDMI speaker adapter
# testing
[http://192.168.0.135:8080/index.html](http://192.168.0.135:8080/index.html)
[https://aliconnect.nl/cotrol/truck](https://aliconnect.nl/control/truck)