RaspberryPi

Raspberry Pi – nodered/mosquitto

Table of Contents

Intro

Instructions

Install Mosquitto

				
					// good to know
hostname -I // GET Raspi IP
				
			
				
					// install mosquitto broker
sudo apt update // update system
sudo apt install -y mosquitto mosquitto-clients   // install mosquitto broker

sudo systemctl enable mosquitto.service    // autostart on boot

mosquitto -v    // check mosquitto version
				
			

Create Auth

				
					// set up a user
sudo mosquitto_passwd -c /etc/mosquitto/credentials myuser // create a user

sudo nano /etc/mosquitto/mosquitto.conf // setup for using a user in settings

allow_anonymous false
password_file /etc/mosquitto/credential
// if you want to add websocket support for mqtt then add this too
listener 1883
listener 9001
protocol websockets
// if you want us ssl or more info check out http://www.steves-internet-guide.com/mqtt-websockets/

sudo service mosquitto restart  // restart mosquitto service
				
			
				
					# MySettings
pid_file /var/run/mosquitto.pid

persistence true
persistence_location /var/lib/mosquitto/

log_dest file /var/log/mosquitto/mosquitto.log

include_dir /etc/mosquitto/conf.d

allow_anonymous false
password_file /etc/mosquitto/credentials

listener 1883

listener 9001
protocol websockets


				
			

Install NodeRed

				
					// install node.js 
curl -sSL https://deb.nodesource.com/setup_16.x | sudo bash -
sudo apt install -y nodejs
//check version
node --version
npm --version

//install node-red
bash <(curl -sL https://raw.githubusercontent.com/node-red/linux-installers/master/deb/update-nodejs-and-nodered)

sudo systemctl enable nodered.service    // add servic to autostart on boot
				
			

Raspberry Pi – Bluetooth Cheatsheet

Table of Contents

Instructions

Bluetooth Cheatsheet

				
					THE BUILT IN RASPBERRY PI 3 BLUETOOTH DEVICE:

Bluetooth service

# Get the status of the Bluetooth service.
service bluetooth status

# If the Bluetooth service is not running, start it.
service bluetooth start

# Stop the Bluetooth service only if required.
service bluetooth stop


Pairing a Bluetooth device

# Once a device is paired it should automatically pair in future.

# Start the Bluetooth utility.
bluetoothctl

# Make sure the Bluetooth device is powered on.
power on

# Make sure an agent is running for the Bluetooth device.
agent on

# Start a scan for other Bluetooth devices in the area.
scan on

# Wait for the required Bluetooth device to be reported...

# Stop scanning when the required Bluetooth device is found.
scan off

# Attempt to pair the required Bluetooth device.
pair <dev>

e.g. <dev>=00:1D:A5:F7:FF:0D

# Pairing normally prompts for a password. Standard Bluetooth pairing passwords
# are: 0000 or 1234, try these if you are unsure of the password.

# If pairing fails or propt for password does not appear, try the following, and
# then try paring again.
agent off
power off
power on
agent on

# Once paired it should appear in the list of paired devices.
paired-devices

# You can now leave the Bluetooth utility and the device should be paired and
# ready for use.
quit


Creating a serial device for use in the OBDII application

# rfcomm associates the paired device ID with a serial device name.
rfcomm bind 0 <dev>

# The device it should create is:
/dev/rfcomm0

# To remove the serial device do the following if required.
rfcomm release <dev>

### Shouldn't need this command, force rfdevices to stop.
### rfkill list


Unpairing a Bluetooth device

# Start the Bluetooth utility.
bluetoothctl

# Unpair the Bluetooth device if required.
remove <dev>

# Make sure the agent is stopped for the Bluetooth device.
agent off

# Make sure the Bluetooth device is powered down.
power off

# Exit the Bluetooth utility.
quit
				
			

Raspberry Pi – WiFi / SSH

Table of Contents

Intro

Install SteamLink on Windows 10

Instructions

Wifi before boot

Create a file called wpa_supplicant.conf

				
					country=US
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

network={
    ssid="wifi_ssid"
    psk="wifi_password"
}
				
			

add it to your boot partition of your sd card

SSH

Create a file called ssh without a file extension and add it to your boot partition of your sd card

Download

PlaceHOLDER

Raspberry Pi – WLAN Bridge

Table of Contents

Intro

Create a WLan Bridge with a Raspberry Pi for you only EthernetPort devices. I use it to get Internet to my Router from a Wireless Internet

Instructions

Add reconnect file

Edit network-monitor.sh file

				
					sudo nano /usr/local/bin/network-monitor.sh
				
			

Add this to network-monitor.sh file

				
					#!/bin/bash

##################################################################
# Settings
# Which Interface do you want to check/fix
wlan='wlan0'
# Which address do you want to ping to see if the network interface is alive?
pingip='192.168.2.1' #		8.8.8.8		1.1.1.1		192.168.1.1 	192.168.4.1
##################################################################

echo "Performing Network check for $wlan"
/bin/ping -c 1 -I $wlan $pingip > /dev/null 2> /dev/null
if [ $? -ge 1 ] ; then
    echo "Network connection down! Attempting reconnection."
    ip link set wlan0 down
    sleep 5
    ip link set wlan0 up
else
    echo "Network is Okay"
fi
				
			

Give permissen to network-monitor.sh

				
					sudo chmod +x /usr/local/bin/network-monitor.sh
				
			

Make it run by crontab

				
					sudo crontab -e
				
			

Execution time for the file

				
					*/5 * * * * /usr/local/bin/network-monitor.sh # every 5 minutes
				
			

WLan Setup

Edit wpa_supplicant.conf

				
					sudo nano /etc/wpa_supplicant/wpa_supplicant.conf
				
			

Add this to wpa_supplicant.conf

				
					# Edit the WLAN settings to your likings!

network={
    ssid="WLAN1"
    psk="passwordOne"
    priority=1
}

network={
    ssid="WLAN2"
    psk="passwordTwo"
    priority=2
}
				
			

If you want to check SSID

				
					ifconfig wlan0
				
			
				
					iwgetid
				
			

WLan Bridge

Install dnsmasq

				
					sudo apt-get install dnsmasq
				
			

Edit dhcpcd.conf

				
					sudo nano /etc/dhcpcd.conf
				
			

Search and edit

				
					interface eth0
static ip_address=192.168.4.1/24
				
			

BackUp dnsmasq.conf

				
					sudo mv /etc/dnsmasq.conf /etc/dnsmasq.conf.orig
				
			

Edit dnsmasq.conf

				
					sudo nano /etc/dnsmasq.conf
				
			

Search and edit

				
					interface=eth0
dhcp-range=192.168.4.8,192.168.4.250,255.255.255.0,12h
				
			

Edit sysctl.conf

				
					sudo nano /etc/sysctl.conf
				
			

Edit to

				
					net.ipv4.ip_forward=1
				
			

Edit rc.local

				
					sudo nano /etc/rc.local
				
			

add this

				
					iptables -t nat -A  POSTROUTING -o wlan0 -j MASQUERADE
				
			

Restart

				
					sudo reboot
				
			

Check Status

				
					sudo service dnsmasq status