Pi Pico 2 W – UF2 flash – install

  • While connect to your PC first press the BOOTSEL cutton on the pico 2 w and then connect the USB
  • It will be connected as new drive(FS mode). you can view in “files”

Pico W with MQ-135 air quality sensor – Prometheus pushgateway

If you want to make portable Air quality sensor this is very easy setup. Make sure to include you mobile hostspot wifi ssid so that you can easily collect data from anywhere on the go.

Gas sensor normal takes 2-3 min to normalized it’s output vaules.

  • Pins
VCC = 3v3(OUT) - GP36
GND = GND -GP38
Input = ADC0 - GP26
  • Code
import network
import urequests
import machine
import time
import ubinascii

#only needed if sending over public ip with https.
USERNAME_P = "basic-auth-username"
PASSWORD_P = 'basic-auth-pass'

# WiFi Credentials
SSID = 'WIFI-SSID'
PASSWORD = 'WIFI-PASSWORD'

# PushGateway Configuration
PUSHGATEWAY_URL = 'https://pushgateway.example.com/metrics/job/gas_sensor/instance/pico-1/sensor/mq135'

# ADC Setup for MQ-135 on GP26 (ADC0)
adc = machine.ADC(26)

def connect_wifi():
    wlan = network.WLAN(network.STA_IF)
    wlan.active(True)
    if not wlan.isconnected():
        print('Connecting to WiFi...')
        wlan.connect(SSID, PASSWORD)
        while not wlan.isconnected():
            time.sleep(0.5)
    print('Connected, IP:', wlan.ifconfig()[0])

def read_gas_sensor():
    raw_value = adc.read_u16()  # 0–65535
    voltage = raw_value * 3.3 / 65535  # Convert to voltage if needed
    return raw_value, voltage

def send_to_pushgateway(value):
    # Prometheus format (you can include labels if you want)
    payload = f"gas_sensor_value {value}\n"
    auth_string = "{}:{}".format(USERNAME_P, PASSWORD_P)
    auth_encoded = ubinascii.b2a_base64(auth_string.encode()).decode().strip()
    
    headers = {
        "Content-Type": "text/plain",
        "Authorization": "Basic " + auth_encoded
    }
    try:
        res = urequests.post(PUSHGATEWAY_URL, data=payload, headers=headers, timeout=5)
        print("Pushed to gateway:", res.status_code)
        res.close()
    except Exception as e:
        print("Push failed:", e)

def main():
    connect_wifi()
    while True:
        raw, voltage = read_gas_sensor()
        print(f"Gas Sensor Raw: {raw} | Voltage: {voltage:.3f}V")
        send_to_pushgateway(raw)
        time.sleep(1)  # Push every 10 seconds

main()

  • timeout=5 is to fix the error code -110, [Errno 110] , ETIMEDOUT, [Errno 115] EINPROGRESS
  • Read data from pico over USB tty
#find device
dmesg | grep tty

$ read X < /dev/ttyACM0
hello
$ echo $X
Gas Sensor Raw: 2496 | Voltage: 0.126V
  • Read using screen command
screen /dev/ttyACM0

#with Baud rate

screen /dev/ttyACM0 9600

check LAN max speed- iperf3

apt install iperf3

#on server 192.168.0.10
iperf -s


#on client
iperf -c 192.168.0.10


root@lp-arm-3:~# iperf3 -c 192.168.0.10
Connecting to host 192.168.0.10, port 5201
[  5] local 192.168.0. port 50976 connected to 192.168.0.10
port 5201
[ ID] Interval           Transfer     Bitrate         Retr  Cwnd
[  5]   0.00-1.00   sec  11.4 MBytes  95.6 Mbits/sec  248   48.1 KBytes       
[  5]   1.00-2.00   sec  10.9 MBytes  91.2 Mbits/sec  260   38.2 KBytes       
[  5]   2.00-3.00   sec  10.9 MBytes  91.7 Mbits/sec  251   38.2 KBytes       
[  5]   3.00-4.00   sec  11.2 MBytes  93.8 Mbits/sec  245   48.1 KBytes       
[  5]   4.00-5.00   sec  10.8 MBytes  90.7 Mbits/sec  277   36.8 KBytes       
[  5]   5.00-6.00   sec  11.3 MBytes  94.9 Mbits/sec  247   38.2 KBytes       
[  5]   6.00-7.00   sec  11.1 MBytes  92.8 Mbits/sec  231   52.3 KBytes       
[  5]   7.00-8.00   sec  10.9 MBytes  91.7 Mbits/sec  260   46.7 KBytes       
[  5]   8.00-9.00   sec  10.8 MBytes  90.7 Mbits/sec  241   50.9 KBytes       
[  5]   9.00-10.00  sec  10.9 MBytes  91.7 Mbits/sec  245   46.7 KBytes       
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bitrate         Retr
[  5]   0.00-10.00  sec   110 MBytes  92.5 Mbits/sec  2505             sender
[  5]   0.00-10.05  sec   110 MBytes  91.9 Mbits/sec                  receiver

iperf Done.

Ref- https://www.jeffgeerling.com/blog/2025/exploring-wifi-7-2-gbps-on-raspberry-pi-5

Adafruit_DHT22 python3 issue fixed – RuntimeError: Unknown platform

git clone https://github.com/adafruit/Adafruit_Python_DHT.git

cd Adafruit_Python_DHT


if [ $(cat /proc/cpuinfo | grep Hardware | wc -l) != "1" ] ; then
  cat /proc/cpuinfo > /etc/cpuinfo 
  echo -e "\nHardware       : BCM2709" >> /etc/cpuinfo 
  mount --bind /etc/cpuinfo /proc/cpuinfo
  echo "Mounted cpuinfo with Hardware info"
fi

python3 setup.py install

https://stackoverflow.com/questions/72554099/error-installing-adafruit-dht-for-python-on-raspberry-pi-400

Ubuntu – Linux thermal / temperature sensor

#!/bin/bash
cpu=$(</sys/class/thermal/thermal_zone6/temp)

cpu_temp=$(echo "$cpu/1000" | /usr/bin/bc -l)

echo "CPU_temp $cpu_temp"
root@lp-knode-2:~# cat /sys/class/thermal/thermal_zone*/type
INT3400 Thermal
SEN1
SEN2
SEN3
SEN4
SEN5
pch_cannonlake
B0D4
iwlwifi_1
x86_pkg_temp



root@lp-knode-2:~# cat /sys/class/thermal/thermal_zone*/temp
20000
41050
47050
41050
45050
50
54000
46050
48000
46000

https://askubuntu.com/questions/1110943/what-do-the-different-thermal-zones-actually-correspond-to

wake on lan – wol – ubutnu

https://help.ubuntu.com/community/WakeOnLan

apt install ethtool

ethtool eth


root@home:/home# ethtool enp3s0
Settings for enp3s0:
	Supported ports: [ TP	 MII ]
	Supported link modes:   10baseT/Half 10baseT/Full
	                        100baseT/Half 100baseT/Full
	                        1000baseT/Full
	Supported pause frame use: Symmetric Receive-only
	Supports auto-negotiation: Yes
	Supported FEC modes: Not reported
	Advertised link modes:  10baseT/Half 10baseT/Full
	                        100baseT/Half 100baseT/Full
	                        1000baseT/Full
	Advertised pause frame use: Symmetric Receive-only
	Advertised auto-negotiation: Yes
	Advertised FEC modes: Not reported
	Speed: Unknown!
	Duplex: Unknown! (255)
	Auto-negotiation: on
	master-slave cfg: preferred slave
	master-slave status: unknown
	Port: Twisted Pair
	PHYAD: 0
	Transceiver: external
	MDI-X: Unknown
	Supports Wake-on: pumbg
	Wake-on: g
	Link detected: no
wol p|u|m|b|a|g|s|d...
                  Sets Wake-on-LAN options.  Not  all  devices  support  this.
                  The argument to this option is a string of characters speci‐
                  fying which options to enable.

                  p   Wake on PHY activity
                  u   Wake on unicast messages
                  m   Wake on multicast messages
                  b   Wake on broadcast messages
                  a   Wake on ARP
                  g   Wake on MagicPacket™
                  s   Enable SecureOn™ password for MagicPacket™
                  d   Disable (wake on  nothing).   This  option
                      clears all previous options.

wake command

apt install etherwake
etherwake MAC-ADDRESS

Disable USB power in ubuntu

  • find list of usb
lsusb

ls /sys/bus/usb/devices
  • disable USB on startup
echo disabled | sudo tee /sys/bus/usb/devices/usb2/power/wakeup
  • Remove power from port
echo suspend | sudo tee /sys/bus/usb/devices/usb2/power/level
  • add power to port again
echo auto | sudo tee /sys/bus/usb/devices/usb2/power/level

https://askubuntu.com/questions/1338682/is-it-possible-to-disable-usb-port-with-known-physical-location

Let me recap for Linux >= 2.6.38: The file power/level is deprecated now; use power/control instead. (power/wakeup is ok.)

https://stackoverflow.com/questions/4702216/controlling-a-usb-power-supply-on-off-with-linux

apt install powertop
powertop

OpenMediaVault rsync – ubuntu

  • Edit the file /etc/default/rsync
RSYNC_ENABLE=inetd

#install
apt-get -y install xinetd
  • create /etc/xinetd.d/rsync
service rsync
{
    disable = no
    socket_type = stream
    wait = no
    user = root
    server = /usr/bin/rsync
    server_args = --daemon
    log_on_failure += USERID
    flags = IPv4
}
  • Create /etc/rsyncd.conf
max connections = 2
log file = /var/log/rsync.log
timeout = 300

[share]
comment = Public Share
path = /home/share
read only = no
list = yes
uid = 0
gid = 0
auth users = user
secrets file = /etc/rsyncd.secrets
cat /etc/rsyncd.secrets 

user1:user1

chmod 600 /etc/rsyncd.secrets
  • Restart
/etc/init.d/xinetd restart
  • Verify
home@home:~$ rsync user1@192.168.29.142::share
Password: 
drwxr-xr-x          4,096 2025/03/21 11:21:47 .
-rw-r--r--              0 2025/03/21 11:21:47 1.txt

bluetooth – bluetoothctl service on ubuntu

  • Check service status
systemctl status bluetooth.service


● bluetooth.service - Bluetooth service
     Loaded: loaded (/usr/lib/systemd/system/bluetooth.service; enabled; preset: enabled)
     Active: active (running) since Fri 2025-03-21 07:57:38 IST; 1min 18s ago
       Docs: man:bluetoothd(8)
   Main PID: 21633 (bluetoothd)
     Status: "Running"
      Tasks: 1 (limit: 76673)
     Memory: 1.1M (peak: 1.6M)
        CPU: 55ms
     CGroup: /system.slice/bluetooth.service
             └─21633 /usr/libexec/bluetooth/bluetoothd
  • Auto connect script for device when it’s on(add it to cronjob or create service)
#!/bin/bash

if [[ $(hcitool con | grep '00:1B:66:0F:XX:XX' | wc -l) != 1 ]]
then
    echo "connect 00:1B:66:0F:XX:XX" | bluetoothctl

else
    echo "Already connected to 00:1B:66:0F:XX:XX"
fi
  • For monitoring events on Bluetooth
root@home:~# bluetoothctl
bluetooth]# [NEW] Device F4:C8:8A:7F:xx:xx CP250003
[bluetooth]# hci0 type 7 discovering off
[bluetooth]# hci0 type 7 discovering on
[bluetooth]# hci0 type 7 discovering off
[bluetooth]# hci0 type 7 discovering on
[bluetooth]# [DEL] Device F4:C8:8A:7F:xx:xx CP250003
[bluetooth]# [NEW] Device F4:C8:8A:7F:xx:xx CP250003
[bluetooth]# hci0 type 7 discovering off
[bluetooth]# hci0 type 7 discovering on
[bluetooth]# [CHG] Device D0:49:7C:8F:xx:xx RSSI: 0xffffffab (-85)



list                                              List available controllers
show [ctrl]                                       Controller information
select <ctrl>                                     Select default controller
devices [Paired/Bonded/Trusted/Connected]         List available devices, with an optional property as the filter
system-alias <name>                               Set controller alias
reset-alias                                       Reset controller alias
power <on/off>                                    Set controller power
pairable <on/off>                                 Set controller pairable mode
discoverable <on/off>                             Set controller discoverable mode
discoverable-timeout [value]                      Set discoverable timeout
agent <on/off/auto/capability>                    Enable/disable agent with given capability
default-agent                                     Set agent as the default one
advertise <on/off/type>                           Enable/disable advertising with given type
set-alias <alias>                                 Set device alias
scan <on/off/bredr/le>                            Scan for devices
info [dev/set]                                    Device/Set information
pair [dev]                                        Pair with device
cancel-pairing [dev]                              Cancel pairing with device
trust [dev]                                       Trust device
untrust [dev]                                     Untrust device
block [dev]                                       Block device
unblock [dev]                                     Unblock device
remove <dev>                                      Remove device
connect <dev>                                     Connect device
disconnect [dev]                                  Disconnect device
menu <name>                                       Select submenu
version                                           Display version
quit                                              Quit program
exit                                              Quit program
help                                              Display help about this program
export                                            Print environment variables