Skip to content

Instantly share code, notes, and snippets.

@sven-bock
sven-bock / gist:78b86896dfdcd9cd323d297fe01f3c51
Created April 30, 2018 12:56
Get temperature of your Raspberry Pi
/opt/vc/bin/vcgencmd measure_temp
@sven-bock
sven-bock / gist:491ca1f9d110e8493b278496c25dd57e
Created April 27, 2018 13:50
Backup and restore SD card image with compression
#Backup SD card
#Verify that sdb is your SD card or change it.
sudo dd bs=4M if=/dev/sdb | gzip > ~/roomba_`date +%d%m%y`.gz
#Wait until the prompt return. It really takes some time to write 32GB and compress it!
#Restore SD card from image
#Verify that sdb is your SD card or change it.
gzip -dc ~/roomba_XXXXX.gz | sudo dd bs=4M of=/dev/sdb
#Wait until the prompt return. It really takes some time to write 32GB and decompress it!
@sven-bock
sven-bock / gist:1eaff06a990e19ec264afb0e2acb75b1
Last active April 27, 2018 12:08
WiFi - command line - ubuntu 16.04
#Show saves connections
nmcli c
#Show available hotspots
nmcli d wifi list
#or
sudo iwlist wlan0 scanning
#Connect to saved connection
nmcli c up CONNECTIONNAME
@sven-bock
sven-bock / split_pdf.bash
Created March 21, 2018 21:09
Split PDF in single page PDFs
#!/bin/bash
# Splits the PDF in single pages PDFs which are saved in a subfolder called extracted and the page name.
# If the pages does already exist, it will increment the page number by one, until the filename is not occupied.
#sudo apt-get install pdftk
#chmod +x split_pdf.bash
#./split_pdf.bash source.pdf
PDFFILE=$1
echo "File: "$PDFFILE
@sven-bock
sven-bock / gist:f7856974c89e24a4969f292d96aa1173
Last active April 30, 2018 12:54
Enable SSH on Raspberry Pi on SD card
+ Plugin SD card that contains the Raspbian OS into your computer
+ Find the partition that is called "boot"
+ Create a file there called ssh
REMARK: Only works for raspbian!
@sven-bock
sven-bock / gpio_control.py
Created March 15, 2018 15:38
Example: MQTT and GPIO control on Raspberry Pi
#!/usr/bin/env python
import paho.mqtt.client as mqtt
import RPi.GPIO as GPIO
import time
import signal
TOPIC_1= "lab_switch"
HOST="localhost"
USER="openhab"
class MQTTGPIO():
def __init__(self):
@sven-bock
sven-bock / gist:56f4e6548a9d9d24312bf573a1056b91
Last active February 28, 2019 16:00
Setting a fixed port (with a simlink) to a USB device (udev/rules)
#Example:
#get some info with:
udevadm info -a -n /dev/ttyUSB0 | grep serial
udevadm info -a -n /dev/ttyUSB0 | grep idProduct
udevadm info -a -n /dev/ttyUSB0 | grep idVendor
#or
udevadm info -a -n /dev/ttyUSB0 | grep -E 'idVendor|idProduct|serial'
@sven-bock
sven-bock / gist:3d0517a8a3f41799ebb5863917317496
Last active January 30, 2018 16:22
Quickly replace all "strings" in files recursively
# Replace OLD with the string you want to replace, and NEW with the string you want to insert
find ./ -type f -exec sed -i -e 's/OLD:/NEW:/g' {} \;
grep -rl 'OLD' . | xargs sed -i 's/OLD/NEW/g'
# Quickly create an android app for IoT :
https://www.blynk.cc/
#ROS stack and library for roomba and create:
https://github.com/AutonomyLab/create_autonomy
https://github.com/AutonomyLab/libcreate/blob/master/include/create/types.h
@sven-bock
sven-bock / gist:2860bdc7f45b8d7195a9d0b88a87bce5
Created January 26, 2018 16:11
Run some executable as a background process
# This can be quite useful to run some process on the server,
# as it will not listen to the hangup signal of the terminal
# and will not terminate the process, if you close the terminal.
# In addition all output is appended in the log file
nohup /usr/bin/python3.4 /abspath/someFile.py 2>&1 | /usr/bin/tee -a /abspath/log.txt &