Skip to content

Instantly share code, notes, and snippets.

View pilotak's full-sized avatar

Pavel S pilotak

View GitHub Profile
@pilotak
pilotak / main.cpp
Created September 29, 2021 13:23
Mbed OS6 CAN bus error handling
#include <mbed.h>
RawCAN can(CAN_RXD_pin, CAN_TXD_pin);
DigitalOut can_sleep(CAN_STANDBY_pin, 0);
int main() {
can.frequency(250000);
can.mode(CAN::Normal);
uint8_t tderr_prev = 0;
bool bus_state = true;
@pilotak
pilotak / mbed_dma_serial_unknown_length.cpp
Created October 30, 2019 14:01
Mbed DMA serial receive unknown length of data
#include "mbed.h"
const uint32_t baud = 9600;
uint8_t eQueue_buffer[3 * EVENTS_EVENT_SIZE];
EventQueue eQueue(3 * EVENTS_EVENT_SIZE, eQueue_buffer);
LowPowerTimeout rs232Timeout;
Serial rs232(TX_pin, RX_pin, baud);
#include "mbed.h"
#if DEVICE_SERIAL_ASYNCH
Serial pc(USBTX, USBRX);
#else
#error "Platform not compatible with Serial async"
#endif
#define BUFF_LENGTH 5

Install CUPS

sudo apt-get install cups
sudo usermod -a -G lpadmin pi
sudo cupsctl --remote-any
sudo /etc/init.d/cups restart

Add printer via web interface http://ipaddresofraspberry:631

Install Samba

  • On SD card in Windows locate config.txt add new line with dtoverlay=dwc2
  • open file cmdline.txt and just after rootwait add modules-load=dwc2,g_ether with space inbetween
  • insert card to Pi and insert USB cable to USB labeled micro USB
  • driver will install itself, if not select manual install of driver -> From list -> Network device -> Microsoft -> Remote NDIS compatible device
  • SSH to Pi with name raspberrypi.local (Bonjour must be installed)

Set static IP address

so that you don't need to run Bonjour

echo -e "interface usb0 \nstatic ip_address=169.254.71.164" | sudo tee -a /etc/dhcpcd.conf

Setup MQTT with SSL

  • :1883 will be for local use only
  • :8083 websocket secure
  • :8883 mqtt secure
sudo apt-get install mosquitto

Getting certificate & Auto-Renewal

Don't forget to change the domain and allow port 443 through firewall

Install OpenVPN server

sudo apt-get install openvpn easy-rsa
make-cadir ~/openvpn-ca
cd ~/openvpn-ca
nano vars

Now configure variables

@pilotak
pilotak / VPS: iptables+node+pm2.md
Last active February 25, 2017 16:35
Ubuntu 16.04: VPS setting + node.js + pm2

If you have an access as a root to your Ubuntu 16.04 VPS you should setup another user giving him sudo access

Create user

adduser pavel # my user is called "pavel"; enter password and leave all the rest
usermod -aG sudo pavel
nano /etc/ssh/sshd_config # disable root access
# find 
    PermitRootLogin # change value to: no
# add
    AllowUsers pavel
sudo apt-get update
sudo apt-get upgrade

sudo wget http://repo.mosquitto.org/debian/mosquitto-repo.gpg.key
sudo apt-key add mosquitto-repo.gpg.key
sudo rm mosquitto-repo.gpg.key

cd /etc/apt/sources.list.d/