Dieses Blog durchsuchen

Seiten

Labels

Raspberry (8) RPI (8)

Dienstag, 5. März 2019

Win10 SSH to RPI with key


1.) Create a Key on the RPI and import it


ssh-keygen -b 4096

ssh-copy-id -i .ssh/id_rsa.pub pi@rpi3 


(rpi3 is in this case my Raspberry )

2.) Copy the private key from rpi


([Username] is the windows username)

~/.ssh/id_rsa      to   c:\Users\[Username]\.ssh\id_rsa
~/.ssh/id_rsa.pub  to   c:\Users\[Username]\.ssh\id_rsa.pub


3.) Remove the Keys from the rpi and check if the authorized_keys updated

pi@rpi3:~/.ssh $ rm id_rsa
pi@rpi3:~/.ssh $ rm id_rsa.pub
pi@rpi3:~/.ssh $ ll
total 8
-rw------- 1 pi pi 733 Mar  5 22:15 authorized_keys
-rw-r--r-- 1 pi pi 222 Mar  5 22:15 known_hosts
pi@rpi3:~/.ssh $

4.) Activate ssh_agent in the Windows Services and set it to automatic


5.) Start the Agent in Gui or with command net start ssh-agent 

net start ssh-agent 

6.) Import the Key to the agent

 ([Username] is the windows username)

ssh-add c:\Users\[Username]\.ssh\id_rsa_rpi3


7.) To connect without password to the RPI over windows SSH use this command

ssh  pi@rpi3 


 

Samba auf dem Rasperry

Hier mal eine kurze Anleitung wie man Samba auf dem Raspberry installiert.

 Die Installation

sudo apt-get install samba samba-common-bin
sudo smbpasswd -a pi

  Sichern der originalen Konfiguration


sudo cp /etc/samba/smb.conf /etc/samba/smb.org

Konfiguration bearbeiten


sudo pico /etc/samba/smb.conf

Meine Änderung um jedem Zugriff auf das Home Verzeichnis zu geben

.
.
.
# ---mz schnippel
follow symlinks = yes
wide links = yes
unix extensions = no
# ---mz schnappel

#======================= Share Definitions =======================
.
.
.
.
# ---mz schnippel
[home]
follow symlinks = yes
wide links = yes
Comment =PI Home
Path = /home/pi
Browseable = yes
Writeable = Yes
only guest = no
create mask = 0775
directory mask = 0775
Public = yes
Guest ok = yes
force user = pi
# ---mz schnappel

Jetzt nur noch neu starten und ausprobieren

sudo /etc/init.d/samba restart

 

Freitag, 15. Juni 2018

How to connect a OLed (I2c) to Raspberry and programing with mono (c#)

 

This little blog shows you how to connect a 0.96" OLed to the Raspberry and programming with C#.

First of all we need the right OLed with the I2C interface, in my case i used a 0,96 Inch Oled for ~3€ in Ebay like this. It is controlled by a SSD1306 controller the hardware documentation can be found here: https://cdn-shop.adafruit.com/datasheets/SSD1306.pdf



Now we connect the OLed to the Raspberry as follow:


The hardware is ready but now we need the code and libraries now. In my case i use the WiringPi library in combination with Mono. I love mono and it work's pretty well with my Rasperry zero W.

Install Mono and WiringPi

see this links to install WiringPi and Mono
http://wiringpi.com/download-and-install/
https://www.mono-project.com/download/stable/#download-lin-raspbian 

 After installed, check the follow:

Mono


WiringPi



Setup I2C on the Raspberry


Enable I2C run:  sudo raspi-config









Now close and reboot
After this the I2C module is available, please chek it with lsmod:




The code


My C# code is a small example and paints a rectangle and elipse on the 0.96 Inch Display with 128x64 Pixel. I use WiringPi function as an DllImport to communicate
You can download or clone the Visual Studio 2017 Project from here:
https://github.com/maza70/Oled_SSD1306








Freitag, 9. Februar 2018

Alexa custom Skill and the Raspberry

Raspberry and Alexa a good Team

Today i will show what you can do when you have time  :-)

"Yoda" is my custom skill that communicate with my RPI Zero.
RPI Zero gets the Alexa request from the Amazon Server and my PHP code controls the actions and in this case he play my private MP'3 over Bluetooth to Echo.
Server code is prototyped with PHP 7


Donnerstag, 1. Februar 2018

Power consumption of the Raspberry Zero W

Here's my test results from the current consumption of the Raspberry Zero W

  • WiFi connected and cpu IDLE: 0,7 W
  • Wi-Fi network and CPU load: 1,2 W
  • WiFi connected, HDMI out, cpu IDLE: 0,6 W
    /usr/bin/tvservice -o
  • WiFi connected, HDMI out, cpu load: 1,1 W
Since I do not need HDMI, I switch it permanently off in the /etc/local.rc


#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

# Print the IP address
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
  printf "My IP address is %s\n" "$_IP"
fi
## MZ
/usr/bin/tvservice -o
exit 0


Alexa communicates with Raspberry


All based on Raspberry Zero W with an "Debian Stretch" installed!

It takes a little bit of knowledge to connect Alexa to the Raspberry.
The most important thing to know is that the echo is quite stupid and almost does not do it on its own.
The echo only responds to the keyword Alexa and then sends the spoken word to the server.
As in our case the communication looks, I show here in a small diagram.

 

As we can see, Raspberry has to be reachable over the internet, with the Fritzbox you can do it easily.
After that we have to forward the port 443 for SSL to our Raspberry,
for this we have to use the standard port because Amazon is very bitchy and only allows SSL over 443. (Grrrr)
When we reach our PI over the Internet via ssl, we can get started on Skill development.

First we register at https://developer.amazon.com and then go to Alexa and to "Get Started".


Next, we'll start a new skill..


In my case, the skill is called Yoda and is German.


After saving we come to the "interaction model"

To test I enter in the "Intent schema" the following:
{
  "intents": [
    {
      "intent": "AMAZON.CancelIntent"
    },
    {
      "intent": "AMAZON.HelpIntent"
    },
    {
      "intent": "AMAZON.PauseIntent"
    },
    {
      "intent": "AMAZON.ResumeIntent"
    },
    {
      "intent": "AMAZON.StopIntent"
    },
    {
      "intent": "MeinIntent"
    }
   ]
}

In the "Sample Utterances" I enter the following (it this case, its scrap but for testing it is enough ):

MeinIntent hallo wie gehts
MeinIntent hallo wie geht es dir
MeinIntent wie gehts
MeinIntent wie geht es


After saving, we come to the "Configuration" and enter the following, please note that you the Https address adapts to your!



Now we have to teach Amazon that our SSL certificate is accepted, since it is a self-singed certificate.

For this we take the content of certificate.pem that we already have as in the blog post
Lighttp and SSL have generated and copy the content into the input box.




So, now it's time to test!
We specified the endpoint under "Configuration" and now we have to fill it with life. 
Create the file yoda.php as follows:

pico /var/www/html/yoda/yoda.php

Now copy the following PHP code in.
 
<?php
header ("Content-Type: application/json;charset=UTF-8" );
http_response_code(200);
echo '{"version": "1.0","response": {"outputSpeech": {"type": "PlainText","text": "Am Ende sind Feiglinge die, die der Dunklen Seite folgen."},
        "card": {
            "type": "Simple",
            "title": "Am Ende sind Feiglinge die, die der Dunklen Seite folgen."
        }
       },"shouldEndSession": true}';

To test you call your HTTPS adress it in your browser (in my case i use Chrome).
Chrome shows a warning message because the certificate is "Self Signed". 
Confirm that he should load the page and the result should look like this.



Now we almost made it, only the final test is missing.



So, if now have a "Service Response" after clicking on "Ask Yoda", Alexa is connected to the Raspberry and all paths are open to us. Now go to your echo and say "Alexa start Yoda" and Alexa will answer you. :-)

Raspberry Lighttp and SSL

All based on Raspberry Zero W with an "Debian Stretch" installed!
 
Since the Amazon Echo server only wants to communicate via https, I have to use for the Lighttp server a  "self-singed ceriticate".

First, let's start with a configuration for the certificate (please replace everything between <..> with your values):

cd ~
mkdir ssl
cd ssl
pico ssl.cfg
[req]
distinguished_name = req_distinguished_name
x509_extensions = v3_req
prompt = no

[req_distinguished_name]
C = [[dein land=""]]
ST = [[dein bundesland=""]]
L = [[deine stadt=""]]
O = keine
CN = [[dein skillname=""]]

[v3_req]
keyUsage = keyEncipherment, dataEncipherment
extendedKeyUsage = serverAuth
subjectAltName = @subject_alternate_names

[subject_alternate_names]
DNS.1 = [[domain die von außen aufgerufen wird z.b.23213qwesd.myfritz.net]]
DNS.2 = [[interne domain z.b. rpi-zero]]

Now we execute the following commands:
 
openssl genrsa -out private-key.pem 2048
openssl req -new -x509 -days 365 -key private-key.pem -config ssl.cfg -out certificate.pem
cat private-key.pem  certificate.pem > lighttp.pem
sudo mkdir /etc/lighttpd/ssl
sudo cp lighttp.pem /etc/lighttpd/ssl/


Almost done now we have to configure Lighttpd:

sudo pico /etc/lighttpd/lighttpd.conf

Enter the following at the end of the file

$SERVER["socket"] == "0.0.0.0:443" {
 ssl.engine = "enable"
 ssl.pemfile = "/etc/lighttpd/ssl/lighttp.pem"
}

Now restart the server

sudo service lighttpd restart


So the certificate is installed!