Skip to content

Instantly share code, notes, and snippets.

#!/bin/bash -e
SERVER_CERT_FILE=server.cert
SERVER_KEY_FILE=server.key
SERVER_CSR_FILE=server.csr
CA_CERT_FILE=ca.cert
CA_KEY_FILE=ca.key
# Generate the Certificate Authority (CA) Private Key
openssl ecparam -name prime256v1 -genkey -noout -out $CA_KEY_FILE
@farshidtz
farshidtz / lighting.py
Created January 3, 2023 10:35
Simple Matter on/off handler in Python. See https://stackoverflow.com/a/74992066/3041544
from chip.server import (
GetLibraryHandle,
PostAttributeChangeCallback,
)
CLUSTER_ONOFF = 6
ATTR_ONOFF = 0
@PostAttributeChangeCallback
@farshidtz
farshidtz / ubuntu-core-intel-nuc.md
Created August 29, 2022 12:50
Install Ubuntu Core on Intel NUC with 1 USB drive

[This guide][intel-nuc] describes how to install Ubuntu Core on Intel NUC using two USB flash drives.

Here are a few alternative options to remove the reliance on a second USB flash drive:

Download the image on live Ubuntu

This is self explained. Boot into the live Ubuntu and download the image. Flash it according to the [official instructions][intel-nuc].

This is not always practical:

  • We may need to reuse that image without downloading it every time
  • We may need to use a custom-built image that isn't available online
@farshidtz
farshidtz / ubuntu-core-debugging.md
Last active September 16, 2022 15:56
Debugging an Ubuntu Core installation with QEMU

Debugging an Ubuntu Core installation with QEMU

The Ubuntu Core installation fails if one of the required seeded snaps fail to start. When a required snap fails, the system starts shutting down, snapd stops, and we end up with the following strange error:

cannot obtain system details: cannot communicate with server: Get http://localhost/v2/system-info: dial unix /run/snapd.socket: connect: connection refused

or

/usr/share/subiquity/console-conf-wrapper: line 32: snap: command not found
@farshidtz
farshidtz / dht22-mqtt.py
Last active March 31, 2022 12:49
Publish DHT22 readings to MQTT broker
# Original script from https://learn.adafruit.com/dht-humidity-sensing-on-raspberry-pi-with-gdocs-logging/python-setup
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT
# RUN:
# BROKER=localhost python read.py
import time
import board
@farshidtz
farshidtz / dht22.py
Last active October 20, 2021 10:59
Read from DHT22 and submit to edgex-device-rest
# Original script from https://learn.adafruit.com/dht-humidity-sensing-on-raspberry-pi-with-gdocs-logging/python-setup
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT
# RUN:
# REST_SERVER=http://myserver:59986 python3 read.py
import time
import board
@farshidtz
farshidtz / amzn2-unattended-upgrades.md
Last active February 26, 2022 14:45
AWS Amazon Linux 2 Unattended Upgrades with Email Notifications

This guide provides instructions for setting up unattended security upgrades on Amazon Linux 2 with optional Email notifications.

To send notifications by Email, an SMTP server is required; more details below this page.

Yum-cron

For unattended upgraded, use yum-cron as recommended in https://stackoverflow.com/a/46248515/3041544

Configure yum-cron: /etc/yum/yum-cron.conf.

Relevant yum-cron config options are: