#StackBounty: #python #raspberry-pi Car computer in Python / GPS tracking VERSION 2

Bounty: 50

This is an updated question with new code, taking into account your comments from last time: Car computer in python / GPS tracking

I have an old car that I use for long distance driving and have coded an onboard computer based on a Raspberry Pi 3 and a few other modules. I use a FONA 808 from Adafruit as the cellular modem (via serial), the Sparkfun NEO-M9N as a GPS sensor (i2c), an OLED display (i2c) and a small temperature sensor via 1-wire. Here is a picture of the computer in action, just so you have a better picture of it:

car computer

Notable improvements compared to version 1 in the old questions are (in a nutshell):

  • config.ini file
  • communication with remote server either per DB direct insert or per POST to a PHP script
  • cleaned up use of globals, imports
  • using the DRY principle as much as possible, creating new helper functions
  • shortening of code where possible
  • testing function for GPS module

Without further ado, here the code, split up in a few files:

car_computer.py

import os
from threading import Thread
import glob
import serial
import board
import subprocess
import smbus
import time
from time import sleep
import datetime
import configparser
import re
import urllib
from urllib import request
import random
from luma.core.interface.serial import i2c
from luma.core.render import canvas
from luma.oled.device import sh1106
from PIL import ImageFont, Image, ImageDraw
import pymysql
import csv
import json
import hashlib 
import pynmea2
from haversine import haversine, Unit
config = configparser.ConfigParser()
config.read('/home/pi/Desktop/car_computer.ini')

################## start display ##################
device = sh1106(i2c(port=1, address=config['display']['i2c_port']), rotate=0)
device.clear()
pending_redraw = False
output = Image.new("1", (128,64))
add_to_image = ImageDraw.Draw(output)
def setup_font(font_filename, size):
    return ImageFont.truetype(os.path.join(config['general']['folder'],config['general']['folder_fonts'],font_filename), size)
fa_solid = setup_font('fa-solid-900.ttf', 12)
fa_solid_largest = setup_font('fa-solid-900.ttf', 40)
text_largest = setup_font('digital-7.ttf', 58)
text_medium = setup_font('digital-7.ttf', 24)
text_small = setup_font('digital-7.ttf', 18)
icons = { #to look up the icons on FontAwesome.com, remove quote marks and u from the search query 
    "save": "uf56f","cloud": "uf0c2","check": "uf058","upload": "uf382","no_conn": "uf127","location": "uf124","question": "uf128","altitude": "uf077","distance": "uf1b9","temperature": "uf2c9" }
def wipe(zone):
    add_to_image.rectangle(tuple(int(v) for v in re.findall("[0-9]+", config['display'][zone])), fill="black", outline ="black")
def icon(zone,name):
    add_to_image.text(tuple(int(v) for v in re.findall("[0-9]+", config['display'][zone])), icons[name], font=fa_solid, fill="white")
def text(zone,text,fontsize=text_medium):
    add_to_image.text(tuple(int(v) for v in re.findall("[0-9]+", config['display'][zone])), text, font=fontsize, fill="white")

################## upload data from GPS folder via FONA to MySQL ##################
def fix_nulls(s):
    return (line.replace('', '') for line in s)
def upload_data():
    global pending_redraw
    while True:
        sleep(5)
        current_dir = os.path.join(config['general']['folder'],config['general']['folder_data'])
        archive_dir = os.path.join(config['general']['folder'],config['general']['folder_data_archive'])
        path, dirs, files = next(os.walk(current_dir))
        file_count = len(files)
        if file_count < 2:
            print("Not enough GPS.csv files found so it's probably in use now or doesn't exist")
            return
        list_of_files = glob.glob(current_dir+"/*.csv")
        oldest_file = min(list_of_files, key=os.path.getctime)
        oldest_file_name = os.path.basename(oldest_file)
        
        try:
            openPPPD()
            
            if config['db']['mode'] == "db":
                print("mode = db")
                db = pymysql.connect(config['db']['db_host'],config['db']['db_user'],config['db']['db_pw'],config['db']['db_name'])
                cursor = db.cursor()
                csv_data = csv.reader(fix_nulls(open(oldest_file)))
                next(csv_data)
                for row in csv_data:
                    if row:
                        statement = 'INSERT INTO '+config['db']['db_table']+' (gps_time, gps_lat, gps_long, gps_speed) VALUES (%s, %s, %s, %s)'
                        cursor.execute(statement,row)
                print("Committing to db")
                db.commit()
                cursor.close()
            
            if config['db']['mode'] == "server":
                print("mode = server")
                csv_data = csv.reader(fix_nulls(open(oldest_file)))
                next(csv_data)
                row_nb = 1
                row_data = {}
                rows_encoded_nb = 1
                rows_encoded = {}
                for row in csv_data:
                    if row:
                        row_data[row_nb] = {'gps_time': int(row[0]), 'gps_lat' : round(float(row[1]), 5), 'gps_long' : round(float(row[2]), 5), 'gps_speed' : round(float(row[3]), 1)}
                        if row_nb % int(config['db']['server_batchsize']) == 0:
                            rows_encoded[rows_encoded_nb] = row_data
                            rows_encoded_nb +=1
                            row_data = {}
                        row_nb +=1
                rows_encoded[rows_encoded_nb] = row_data
                row_data = {}
                   
                for i in rows_encoded : 
                    checksum = hashlib.md5(str(rows_encoded[i]).encode())
                    checksum = checksum.hexdigest()
                    
                    req = request.Request(config['db']['server_addr'], method="POST")
                    req.add_header('Content-Type', 'application/json')
                    data = {
                        "hash": checksum,
                        "ID": config['db']['server_ID'],
                        "pw": config['db']['server_pw'],
                        "data": rows_encoded[i]
                    }
                    data = json.dumps(data)
                    data = data.encode()
                    r = request.urlopen(req, data=data)
                    print(r.read())
                    
                    #sleep(1)

            closePPPD()
            print("Successfully committed to db")
            wipe('GPRS_ZONE')
            icon('GPRS_START',"check")
            pending_redraw = True

            os.rename(current_dir+"/"+oldest_file_name, archive_dir+"/archive_"+oldest_file_name)        
            sleep(60)
            wipe('GPRS_ZONE')
            
        except Exception as e:
            print("Database error:", e)
            wipe('GPRS_ZONE')
            icon('GPRS_START',"no_conn")
            pending_redraw = True
            closePPPD()
            sleep(60)
            wipe('GPRS_ZONE')
            pending_redraw = True
            return
        
        sleep(300)
        
################## config and start GPS ##################
BUS = None
reading_nr = 1
reading_nr_upload = 1
reading_nr_upload_nbrowsinlog = 0
total_km = 0
prev_lat = 0
prev_long = 0

def connectBus():
    global BUS
    BUS = smbus.SMBus(1)

def debug_gps():
    sleep(1)
    time = datetime.datetime.now()
    gga1 = pynmea2.GGA('GN', 'GGA', (time.strftime("%H%M%S"), '1929.045', 'S', '02410.516', 'E', '1', '04', '2.6', '69.00', 'M', '-33.9', 'M', '', '0000'))
    gga2 = pynmea2.GGA('GN', 'GGA', (time.strftime("%H%M%S"), '1929.075', 'S', '02410.506', 'E', '1', '04', '2.6', '73.00', 'M', '-33.9', 'M', '', '0000'))
    rmc1 = pynmea2.RMC('GN', 'RMC', (time.strftime("%H%M%S"), 'A',  '1929.055', 'S', '02411.516', 'E', '28', '076.2', time.strftime("%d%m%y"), 'A'))
    rmc2 = pynmea2.RMC('GN', 'RMC', (time.strftime("%H%M%S"), 'A',  '1929.045', 'S', '02411.506', 'E', '29', '076.2', time.strftime("%d%m%y"), 'A'))
    nmea = [gga1,rmc1,gga2,rmc2]
    return str(random.choice(nmea))

def parseResponse(gpsLine):
    global pending_redraw
    gpsChars = ''.join(chr(c) for c in gpsLine)
    
    ##### uncomment only for testing when the GPS chip has no reception #####
    gpsChars = debug_gps()
    #print(gpsChars)
    
    if "GGA" in gpsChars:
        if ",1," not in gpsChars:
            print("GGA?")
            wipe('STATUS_ICON_ZONE')
            wipe('STATUS_ZONE')
            icon('STATUS_ICON_START', "location")
            icon('STATUS_START', "question")
            pending_redraw = True
            sleep(1)
            return False
        try:
            nmea = pynmea2.parse(gpsChars, check=True)
            if "0.0" in str(nmea.latitude) or "0.0" in str(nmea.longitude):
                return False
            
            #show that we have a location and delete whatever was there
            wipe('STATUS_ICON_ZONE')
            icon('STATUS_ICON_START', "location")
            wipe('STATUS_ZONE')
            
            ## update altitude
            icon('ALTI_ICON_START', "altitude")
            wipe('ALTI_ZONE')
            text('ALTI_START', str('%.0f'%(nmea.altitude)))
            
            ## update total distance
            global reading_nr
            global total_km
            global prev_lat
            global prev_long
            dist = 0
            if reading_nr != 1:
                dist = haversine(((float(prev_lat)), (float(prev_long))), ((float(nmea.latitude)), (float(nmea.longitude))))
                total_km = total_km+dist
                icon('DIST_ICON_START', "distance")
                wipe('DIST_ZONE')
                text('DIST_START', "%0.1f" % total_km)
            prev_lat = nmea.latitude
            prev_long = nmea.longitude
            
            pending_redraw = True
            reading_nr +=1
            
        except Exception as e:
            print("GGA parse error:", e)
            wipe('STATUS_ZONE')
            pending_redraw = True
            pass
        
    if "RMC" in gpsChars:
        if ",A," not in gpsChars: # 1 for GGA, A for RMC
            print("RMC?")
            wipe('STATUS_ICON_ZONE')
            wipe('STATUS_ZONE')
            icon('STATUS_ICON_START', "location")
            icon('STATUS_START', "question")
            pending_redraw = True
            sleep(1)
            return False
        try:
            nmea = pynmea2.parse(gpsChars, check=True)
            if "0.0" in str(nmea.latitude) or "0.0" in str(nmea.longitude):
                return False
            
            #show that we have a location and delete whatever was there
            wipe('STATUS_ICON_ZONE')
            icon('STATUS_ICON_START', "location")
            wipe('STATUS_ZONE')
            
            ## update speed
            wipe('SPEED_ZONE')
            text('SPEED_START', str('%.0f'%(nmea.spd_over_grnd*1.852)), fontsize=text_largest)
            
            ## log every log_frequency nth GPS coordinate in CSV file
            global reading_nr_upload
            global reading_nr_upload_nbrowsinlog
            if reading_nr_upload % int(config['gps']['log_frequency']) == 0:
                t = datetime.datetime.combine(nmea.datestamp, nmea.timestamp).strftime("%s")
                d = datetime.datetime.combine(nmea.datestamp, nmea.timestamp).strftime("%Y%m%d%H")
                filename = os.path.join(config['general']['folder'],config['general']['folder_data'],'gps_' + d + '.csv')
                with open(filename, 'a', newline='') as csvfile:
                    gps_writer = csv.writer(csvfile, delimiter=',', quotechar='|', quoting=csv.QUOTE_MINIMAL)
                    gps_writer.writerow([t, nmea.latitude, nmea.longitude, nmea.spd_over_grnd*1.852])
                reading_nr_upload_nbrowsinlog +=1
                #print("Added to log. Total in Log from this session is", reading_nr_upload_nbrowsinlog)
                wipe('STATUS_ZONE')
                icon('STATUS_START',"save")

            reading_nr_upload +=1
            pending_redraw = True
            
        except Exception as e:
            print("RMC parse error:", e)
            wipe('STATUS_ZONE')
            pending_redraw = True
            pass

def readGPS():
    c = None
    response = []
    try:
        while True: # Newline, or bad char.
            global BUS
            c = BUS.read_byte(int(config['gps']['i2c_port'], 16))
            if c == 255:
                return False
            elif c == 10:
                break
            else:
                response.append(c)
        parseResponse(response)
    except IOError:
        time.sleep(0.5)
        connectBus()

connectBus()
def updateGPS():
    while True:
        readGPS()

################## config external thermometer ##################
def update_temp_ext(temp_signature='t=', update_interval=config['temp_ext']['update_interval']):
    global pending_redraw
    icon('TEMP_ICON_START', "temperature")
    base_dir = config['temp_ext']['w1_folder']
    device_folder = glob.glob(base_dir + '28*')[0]
    device_file = device_folder + '/w1_slave'
    while True:
        f = open(device_file, 'r')
        lines = f.readlines()
        f.close()
        equals_pos = lines[1].find(temp_signature)
        if equals_pos != -1:
            temp_string = lines[1][equals_pos+2:]
            temp_c = round(float(temp_string) / 1000.0)
            wipe('TEMP_ZONE')
            text('TEMP_START', str(temp_c))
            pending_redraw = True
            time.sleep(int(update_interval))
            

################## update display ##################
def update_display():
    sleep(0.5)
    while True:
        global pending_redraw
        if pending_redraw:
            device.display(output)
            pending_redraw = False
        time.sleep(0.2)
            

################## start cellular connection ##################          
def openPPPD():
    subprocess.call("sudo pon fona", shell=True)
    print("FONA on")
    wipe('GPRS_ZONE')
    icon('GPRS_START', "cloud")
    global pending_redraw
    pending_redraw = True
    sleep(20)
    try:
        urllib.request.urlopen(config['db']['ping'])
        print("Connection is on")
        wipe('GPRS_ZONE')
        icon('GPRS_START', "upload")
        pending_redraw = True
        return True
    except:
        print("Connection error")
        wipe('GPRS_ZONE')
        icon('GPRS_START', "no_conn")
        pending_redraw = True
        return False

# Stop PPPD
def closePPPD():
    print("turning off PPPD")
    subprocess.call("sudo poff fona", shell=True)
    print("turned off")
    return True
            
################## threading and program execution ##################
if __name__ == '__main__':
    temp_ext_thread = Thread(target = update_temp_ext)
    display_thread = Thread(target=update_display)
    gps_thread = Thread(target = updateGPS)
    data_thread = Thread(target = upload_data)
    
    display_thread.start() 
    gps_thread.start()
    data_thread.start()
    temp_ext_thread.start()
    
    display_thread.join()

car_computer.ini

[general]
folder = /home/pi/Desktop
folder_fonts = fonts
folder_data = data/gps
folder_data_archive = data/gps/archive

[db]
mode = server
ping = https://XXX
db_host = XXX
db_user = XXX
db_pw = XXX
db_name = XXX
db_table = gps_data
server_addr = https://www.XXX.com/gps_logger.php
server_batchsize = 50
server_ID = XXX
server_pw = XXX

[display]
i2c_port = 0x3c
### coordinates always: padding-left, padding-top. the first pair of zone is mostly = start (except to offset small icons)
# temp_ext
TEMP_ZONE = [(14,44), (36,64)]
TEMP_START = (14,44)
TEMP_ICON_ZONE = [(0,48), (15,64)]
TEMP_ICON_START = (3,48)
# alti
ALTI_ZONE = [(14,22), (69,40)]
ALTI_START = (14,22)
ALTI_ICON_ZONE = [(0,24), (15,40)]
ALTI_ICON_START = (0,26)
# distance
DIST_ZONE = [(14,0), (69,21)]
DIST_START = (14,0)
DIST_ICON_ZONE = [(0,4), (15,21)]
DIST_ICON_START = (0,4)
# speed
SPEED_ZONE = [(66,0), (128,45)]
SPEED_START = (66,0)
# GPRS status
GPRS_ZONE = [(114,46), (128,64)]
GPRS_START = (114,50)
# GPS status, incl. GPS startup icon
STATUS_ICON_ZONE = [(70,50), (88,64)]
STATUS_ICON_START = (70,50)
STATUS_ZONE = [(86,46), (113,64)]
STATUS_START_TEXT = (86,46)
STATUS_START = (86,50)

[gps]
i2c_port = 0x42
log_frequency = 5

[temp_ext]
update_interval = 30
w1_folder = /sys/bus/w1/devices/

gps_logger.php

<?php 

$mysqli = new mysqli($hostname_db, $username_db, $password_db,$database_db);

$json = file_get_contents('php://input');

if($data = json_decode($json)) {

  $sql = "SELECT * FROM gps_computers WHERE gc_ID = ? AND gc_pw = ?";
  $statement = $mysqli->prepare($sql);
  $statement->bind_param('is', $data->ID, $data->pw);
  if(!$statement->execute()) { die("Query error: ".$statement->error); } 
  $auth = $statement->get_result();
  $totalRows_auth = $auth->num_rows;

  if($totalRows_auth == 1) {
    echo "";
  } else {
    echo "no auth match found";
    die;
  }

  $i = 0;
  foreach ($data->data as $key => $record) {
    $sql = "SELECT * FROM gps_data WHERE gps_time = ? AND gps_computerID = ?";
    $statement = $mysqli->prepare($sql);
    $statement->bind_param('ii', $record->gps_time, $data->ID);
    if(!$statement->execute()) { die("Query error: ".$statement->error); } 
    $doublecheck = $statement->get_result();
    $totalRows_doublecheck = $doublecheck->num_rows;

    if($totalRows_doublecheck != 1) {
      $i++;
      $sql = "INSERT INTO `gps_data` (`gps_time`, `gps_lat`, `gps_long`, `gps_speed`, `gps_computerID`) VALUES (?, ?, ?, ?, ?);";
      $statement = $mysqli->prepare($sql);
      $statement->bind_param('isssi', $record->gps_time, $record->gps_lat, $record->gps_long, $record->gps_speed, $data->ID);
      if(!$statement->execute()) { die("Query error: ".$statement->error); } 
    }

  }
  echo $i." records inserted";

} else {
  echo "error reading json";
}

?>

I have to say I’m quite proud of how it’s turned out! Happy to edit the question if you want more info to better help 🙂


Get this bounty!!!

#StackBounty: #ubuntu #raspberry-pi #monitors #mate-desktop Run Linux with or without monitor

Bounty: 50

I am trying to run an program on Ubuntu MATE 20.04 that needs to have a graphical output to function. Sometimes I will attach a monitor and sometimes I will not. I would like to configure my computer(a raspberry pi 4) so that it will boot into MATE with or without a monitor.

For background, this program is a radio scanner software written in java and I want the be able to have the program startup at boot. It requires a graphical output in order to function. I did not write the program and trying to tackle launching it outside of X is beyond my capabilities.

Currently I have it set to start as a startup program inside of the MATE desktop and that is working fine when there is a monitor.

I don’t care if the desktop is running when there isn’t a monitor, system resources are less important to me than getting the program to run.

It is also acceptable to run the program on a "Fake" X session however I need to prevent that from happening when a monitor is attached. This could also be handled by killing the process manually (but preferably automatically) once the desktop has launched. Again, this is less important to me than getting it to work in the first place.


Get this bounty!!!

#StackBounty: #wifi #raspberry-pi #wlan #hostapd Raspberry Pi 4 Model B – External RT3070 WiFi adapter – Hostapd crashing

Bounty: 100

I’m attempting to use my Raspberry Pi 4 Model B with one of these ModMyPi Ralink RT3070-based-chipset usb wireless adapters as an AP via hostapd.

The issue I’m facing is as follows:

  • Start hostapd
  • AP works fine (DHCP/DNS/routing/etc) for an undetermined period of time
  • hostapd eventually crashes with little useful information in logs (that I can see) to help indicate why this is the case.

Restarting hostapd after this seems to bring it back online.


The USB WiFi dongle is showing as utilising the rt2800 family of drivers:

pi@raspberrypi:/tmp $ lsusb
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 004: ID 046d:c52b Logitech, Inc. Unifying Receiver
Bus 001 Device 005: ID 148f:3070 Ralink Technology, Corp. RT2870/RT3070 Wireless Adapter
Bus 001 Device 002: ID 2109:3431 VIA Labs, Inc. Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

dmesg output is as follows:

...
[13591.906444] usb 1-1.1: new high-speed USB device number 6 using xhci_hcd
[13592.069548] usb 1-1.1: New USB device found, idVendor=148f, idProduct=3070, bcdDevice= 1.01
[13592.069569] usb 1-1.1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[13592.069586] usb 1-1.1: Product: 802.11 n WLAN
[13592.069601] usb 1-1.1: Manufacturer: Ralink
[13592.069616] usb 1-1.1: SerialNumber: 1.0
[13592.177043] usb 1-1.1: reset high-speed USB device number 6 using xhci_hcd
[13592.318245] ieee80211 phy3: rt2x00_set_rt: Info - RT chipset 3070, rev 0201 detected
[13592.344614] ieee80211 phy3: rt2x00_set_rf: Info - RF chipset 0005 detected
[13592.344939] ieee80211 phy3: Selected rate control algorithm 'minstrel_ht'
[13592.351931] ieee80211 phy3: rt2x00lib_request_firmware: Info - Loading firmware file 'rt2870.bin'
[13592.352027] ieee80211 phy3: rt2x00lib_request_firmware: Info - Firmware detected - version: 0.36
...

Loaded modules as follows:

pi@raspberrypi:/tmp $ lsmod | grep rt2
rt2800usb              28672  0
rt2800lib             114688  1 rt2800usb
rt2x00usb              24576  1 rt2800usb
rt2x00lib              57344  3 rt2800lib,rt2800usb,rt2x00usb
mac80211              729088  3 rt2800lib,rt2x00lib,rt2x00usb
crc_ccitt              16384  1 rt2800lib
cfg80211              679936  3 rt2x00lib,mac80211,brcmfmac

My hostapd configuration looks like:

auth_algs=1
wpa_key_mgmt=WPA-PSK
ssid=<REDACTED>
channel=7
hw_mode=g
wpa_passphrase=<REDACTED>
interface=wlan1
wpa=2
wpa_pairwise=CCMP
country_code=AU
ignore_broadcast_ssid=0
disassoc_low_ack=0
ctrl_interface=/var/run/hostapd

iwconfig is showing this device as not being powered managed:

pi@raspberrypi:/tmp $ iwconfig wlan1
wlan1     IEEE 802.11  ESSID:off/any
          Mode:Managed  Access Point: Not-Associated   Tx-Power=36 dBm
          Retry short  long limit:2   RTS thr:off   Fragment thr:off
          Power Management:off

I had a cron job setup to run every 5 minutes with iwconfig wlan1 power off to see if that made any difference but it did not appear to.

Below are some log entries that might be of interest:

pi@raspberrypi:/var/log $ grep wlan1 * | grep -v CRON | grep -v dhcp | grep -v avahi | grep -v dns | grep -v "24:62:ab:fd:24:34" | grep -v "light" | grep -v "iwconfig wlan1 power off"
daemon.log:Sep 20 18:42:25 raspberrypi vnstatd[504]: Info: Interface "wlan1" disabled.
daemon.log:Sep 20 18:42:30 raspberrypi vnstatd[504]: Info: Interface "wlan1" enabled.
daemon.log.1:Sep 13 13:16:42 raspberrypi vnstatd[504]: Info: Interface "wlan1" enabled.
daemon.log.1:Sep 14 21:51:28 raspberrypi vnstatd[504]: Info: Interface "wlan1" disabled.
daemon.log.1:Sep 14 21:51:33 raspberrypi vnstatd[504]: Info: Interface "wlan1" enabled.
daemon.log.1:Sep 15 19:09:21 raspberrypi vnstatd[504]: Info: Interface "wlan1" disabled.
daemon.log.1:Sep 15 19:09:26 raspberrypi vnstatd[504]: Info: Interface "wlan1" enabled.
daemon.log.1:Sep 17 11:09:18 raspberrypi vnstatd[504]: Info: Interface "wlan1" disabled.
daemon.log.1:Sep 17 11:09:23 raspberrypi vnstatd[504]: Info: Interface "wlan1" enabled.
daemon.log.1:Sep 17 11:38:23 raspberrypi vnstatd[504]: Info: Interface "wlan1" disabled.
daemon.log.1:Sep 17 11:38:28 raspberrypi vnstatd[504]: Info: Interface "wlan1" enabled.
kern.log:Sep 20 14:08:07 raspberrypi kernel: [927055.823706] IPv6: ADDRCONF(NETDEV_CHANGE): wlan1: link becomes ready
kern.log:Sep 20 14:29:07 raspberrypi kernel: [928315.433328] IPv6: ADDRCONF(NETDEV_CHANGE): wlan1: link becomes ready
kern.log:Sep 20 14:38:19 raspberrypi kernel: [928867.033359] IPv6: ADDRCONF(NETDEV_CHANGE): wlan1: link becomes ready
kern.log:Sep 20 14:55:46 raspberrypi kernel: [    8.827781] IPv6: ADDRCONF(NETDEV_CHANGE): wlan1: link becomes ready
kern.log:Sep 20 14:56:01 raspberrypi kernel: [   23.574682] IPv6: ADDRCONF(NETDEV_CHANGE): wlan1: link becomes ready
kern.log.1:Sep 13 13:40:12 raspberrypi kernel: [320571.239666] IPv6: ADDRCONF(NETDEV_CHANGE): wlan1: link becomes ready
kern.log.1:Sep 13 13:57:22 raspberrypi kernel: [321601.827227] IPv6: ADDRCONF(NETDEV_CHANGE): wlan1: link becomes ready
kern.log.1:Sep 13 20:33:56 raspberrypi kernel: [345395.775302] IPv6: ADDRCONF(NETDEV_CHANGE): wlan1: link becomes ready
kern.log.1:Sep 13 20:47:40 raspberrypi kernel: [346220.238577] device wlan1 entered promiscuous mode
kern.log.1:Sep 13 20:47:43 raspberrypi kernel: [346222.405713] device wlan1 left promiscuous mode
kern.log.1:Sep 13 20:49:55 raspberrypi kernel: [346355.010522] device wlan1 entered promiscuous mode
kern.log.1:Sep 13 20:51:01 raspberrypi kernel: [346420.542532] device wlan1 left promiscuous mode
kern.log.1:Sep 14 18:16:09 raspberrypi kernel: [423530.404296] IPv6: ADDRCONF(NETDEV_CHANGE): wlan1: link becomes ready
kern.log.1:Sep 17 11:38:42 raspberrypi kernel: [658886.773095] IPv6: ADDRCONF(NETDEV_CHANGE): wlan1: link becomes ready
messages:Sep 20 14:08:07 raspberrypi kernel: [927055.823706] IPv6: ADDRCONF(NETDEV_CHANGE): wlan1: link becomes ready
messages:Sep 20 14:29:07 raspberrypi kernel: [928315.433328] IPv6: ADDRCONF(NETDEV_CHANGE): wlan1: link becomes ready
messages:Sep 20 14:38:19 raspberrypi kernel: [928867.033359] IPv6: ADDRCONF(NETDEV_CHANGE): wlan1: link becomes ready
messages:Sep 20 14:55:46 raspberrypi kernel: [    8.827781] IPv6: ADDRCONF(NETDEV_CHANGE): wlan1: link becomes ready
messages:Sep 20 14:56:01 raspberrypi kernel: [   23.574682] IPv6: ADDRCONF(NETDEV_CHANGE): wlan1: link becomes ready
messages.1:Sep 13 13:40:12 raspberrypi kernel: [320571.239666] IPv6: ADDRCONF(NETDEV_CHANGE): wlan1: link becomes ready
messages.1:Sep 13 13:57:22 raspberrypi kernel: [321601.827227] IPv6: ADDRCONF(NETDEV_CHANGE): wlan1: link becomes ready
messages.1:Sep 13 20:33:56 raspberrypi kernel: [345395.775302] IPv6: ADDRCONF(NETDEV_CHANGE): wlan1: link becomes ready
messages.1:Sep 13 20:47:40 raspberrypi kernel: [346220.238577] device wlan1 entered promiscuous mode
messages.1:Sep 13 20:47:43 raspberrypi kernel: [346222.405713] device wlan1 left promiscuous mode
messages.1:Sep 13 20:49:55 raspberrypi kernel: [346355.010522] device wlan1 entered promiscuous mode
messages.1:Sep 13 20:51:01 raspberrypi kernel: [346420.542532] device wlan1 left promiscuous mode
messages.1:Sep 14 18:16:09 raspberrypi kernel: [423530.404296] IPv6: ADDRCONF(NETDEV_CHANGE): wlan1: link becomes ready
messages.1:Sep 17 11:38:42 raspberrypi kernel: [658886.773095] IPv6: ADDRCONF(NETDEV_CHANGE): wlan1: link becomes ready
syslog:Sep 20 14:08:07 raspberrypi kernel: [927055.823706] IPv6: ADDRCONF(NETDEV_CHANGE): wlan1: link becomes ready
syslog:Sep 20 14:29:07 raspberrypi kernel: [928315.433328] IPv6: ADDRCONF(NETDEV_CHANGE): wlan1: link becomes ready
syslog:Sep 20 14:38:19 raspberrypi kernel: [928867.033359] IPv6: ADDRCONF(NETDEV_CHANGE): wlan1: link becomes ready
syslog:Sep 20 14:55:46 raspberrypi kernel: [    8.827781] IPv6: ADDRCONF(NETDEV_CHANGE): wlan1: link becomes ready
syslog:Sep 20 14:56:01 raspberrypi kernel: [   23.574682] IPv6: ADDRCONF(NETDEV_CHANGE): wlan1: link becomes ready
syslog:Sep 20 18:42:25 raspberrypi vnstatd[504]: Info: Interface "wlan1" disabled.
syslog:Sep 20 18:42:30 raspberrypi vnstatd[504]: Info: Interface "wlan1" enabled.

Here are some interesting log entries from hostapd:

Configuration file: /etc/hostapd/hostapd.conf
wlan1: AP-ENABLED 
wlan1: interface state ENABLED->DISABLED
wlan1: AP-DISABLED 
wlan1: CTRL-EVENT-TERMINATING 
nl80211: deinit ifname=wlan1 disabled_11b_rates=0
Configuration file: /etc/hostapd/hostapd.conf
wlan1: AP-ENABLED 
wlan1: interface state ENABLED->DISABLED
wlan1: AP-DISABLED 
wlan1: CTRL-EVENT-TERMINATING 
nl80211: deinit ifname=wlan1 disabled_11b_rates=0
Configuration file: /etc/hostapd/hostapd.conf
wlan1: AP-ENABLED 
wlan1: INTERFACE-DISABLED 
wlan1: INTERFACE-ENABLED 
Failed to set beacon parameters
wlan1: INTERFACE-DISABLED 
wlan1: INTERFACE-ENABLED 
Failed to set beacon parameters
wlan1: INTERFACE-DISABLED 
wlan1: INTERFACE-ENABLED 
Failed to set beacon parameters
wlan1: INTERFACE-DISABLED 
Could not set interface wlan1 flags (UP): Input/output error
nl80211: Could not set interface 'wlan1' UP
Could not set interface wlan1 flags (UP): No such device
nl80211: Could not set interface 'wlan1' UP
wlan1: INTERFACE-ENABLED 
Failed to set beacon parameters
wlan1: INTERFACE-DISABLED 
wlan1: INTERFACE-ENABLED 
Failed to set beacon parameters
wlan1: INTERFACE-DISABLED 
wlan1: INTERFACE-ENABLED 
Failed to set beacon parameters
wlan1: INTERFACE-DISABLED 
wlan1: INTERFACE-ENABLED 
Failed to set beacon parameters
wlan1: INTERFACE-DISABLED 
wlan1: INTERFACE-ENABLED 
Failed to set beacon parameters
wlan1: interface state ENABLED->DISABLED
wlan1: AP-DISABLED 
wlan1: CTRL-EVENT-TERMINATING 
nl80211: deinit ifname=wlan1 disabled_11b_rates=0
Configuration file: /etc/hostapd/hostapd.conf
wlan1: AP-ENABLED 
wlan1: INTERFACE-DISABLED 
Could not set interface wlan1 flags (UP): Input/output error
nl80211: Could not set interface 'wlan1' UP
Could not set interface wlan1 flags (UP): Device or resource busy
nl80211: Could not set interface 'wlan1' UP
wlan1: INTERFACE-ENABLED 
Failed to set beacon parameters
wlan1: INTERFACE-DISABLED 
wlan1: INTERFACE-ENABLED 
Failed to set beacon parameters
wlan1: interface state ENABLED->DISABLED
wlan1: AP-DISABLED 
wlan1: CTRL-EVENT-TERMINATING 
nl80211: deinit ifname=wlan1 disabled_11b_rates=0
Configuration file: /etc/hostapd/hostapd.conf
wlan1: AP-ENABLED 
wlan1: interface state ENABLED->DISABLED
wlan1: AP-DISABLED 
wlan1: CTRL-EVENT-TERMINATING 
nl80211: deinit ifname=wlan1 disabled_11b_rates=0
Configuration file: /etc/hostapd/hostapd.conf
wlan1: AP-ENABLED 
wlan1: INTERFACE-DISABLED 
wlan1: INTERFACE-ENABLED 
Failed to set beacon parameters
wlan1: INTERFACE-DISABLED 
wlan1: INTERFACE-ENABLED 
Failed to set beacon parameters
wlan1: INTERFACE-DISABLED 
wlan1: INTERFACE-ENABLED 
Failed to set beacon parameters
wlan1: INTERFACE-DISABLED 
wlan1: INTERFACE-ENABLED 
Failed to set beacon parameters
wlan1: INTERFACE-DISABLED 
wlan1: INTERFACE-ENABLED 
Failed to set beacon parameters
wlan1: INTERFACE-DISABLED 
Could not set interface wlan1 flags (UP): No such device
nl80211: Could not set interface 'wlan1' UP
Could not set interface wlan1 flags (UP): No such device
nl80211: Could not set interface 'wlan1' UP
wlan1: INTERFACE-ENABLED 
Failed to set beacon parameters
wlan1: INTERFACE-DISABLED 
wlan1: INTERFACE-ENABLED 
Failed to set beacon parameters
wlan1: interface state ENABLED->DISABLED
wlan1: AP-DISABLED 
wlan1: CTRL-EVENT-TERMINATING 
nl80211: deinit ifname=wlan1 disabled_11b_rates=0
Configuration file: /etc/hostapd/hostapd.conf
wlan1: AP-ENABLED 
wlan1: interface state ENABLED->DISABLED
wlan1: AP-DISABLED 
wlan1: CTRL-EVENT-TERMINATING 
nl80211: deinit ifname=wlan1 disabled_11b_rates=0
Configuration file: /etc/hostapd/hostapd.conf
wlan1: AP-ENABLED 
wlan1: interface state ENABLED->DISABLED
wlan1: AP-DISABLED 
wlan1: CTRL-EVENT-TERMINATING 
nl80211: deinit ifname=wlan1 disabled_11b_rates=0
Configuration file: /etc/hostapd/hostapd.conf
wlan1: AP-ENABLED 
wlan1: INTERFACE-DISABLED 
wlan1: INTERFACE-ENABLED 
Failed to set beacon parameters
wlan1: INTERFACE-DISABLED 
wlan1: INTERFACE-ENABLED 
Failed to set beacon parameters
wlan1: interface state ENABLED->DISABLED
wlan1: AP-DISABLED 
wlan1: CTRL-EVENT-TERMINATING 
nl80211: deinit ifname=wlan1 disabled_11b_rates=0
Configuration file: /etc/hostapd/hostapd.conf
wlan1: AP-ENABLED 
wlan1: INTERFACE-DISABLED 
wlan1: INTERFACE-ENABLED 
Failed to set beacon parameters
wlan1: INTERFACE-DISABLED 
wlan1: INTERFACE-ENABLED 
Failed to set beacon parameters
wlan1: INTERFACE-DISABLED 
wlan1: INTERFACE-ENABLED 
Failed to set beacon parameters
wlan1: INTERFACE-DISABLED 
wlan1: INTERFACE-ENABLED 
Failed to set beacon parameters
wlan1: INTERFACE-DISABLED 
wlan1: INTERFACE-ENABLED 
Failed to set beacon parameters
wlan1: INTERFACE-DISABLED 
wlan1: INTERFACE-ENABLED 
Failed to set beacon parameters
wlan1: INTERFACE-DISABLED 
wlan1: INTERFACE-ENABLED 
Failed to set beacon parameters
wlan1: INTERFACE-DISABLED 
wlan1: INTERFACE-ENABLED 
Failed to set beacon parameters
wlan1: INTERFACE-DISABLED 
wlan1: INTERFACE-ENABLED 
Failed to set beacon parameters
wlan1: INTERFACE-DISABLED 
wlan1: INTERFACE-ENABLED 
Failed to set beacon parameters
wlan1: INTERFACE-DISABLED 
wlan1: INTERFACE-ENABLED 
Failed to set beacon parameters
wlan1: INTERFACE-DISABLED 
wlan1: INTERFACE-ENABLED 
Failed to set beacon parameters
wlan1: INTERFACE-DISABLED 
wlan1: INTERFACE-ENABLED 
Failed to set beacon parameters
wlan1: INTERFACE-DISABLED 
wlan1: INTERFACE-ENABLED 
Failed to set beacon parameters
wlan1: INTERFACE-DISABLED 
Could not set interface wlan1 flags (UP): Input/output error
nl80211: Could not set interface 'wlan1' UP
wlan1: INTERFACE-ENABLED 
Failed to set beacon parameters
wlan1: INTERFACE-DISABLED 
wlan1: INTERFACE-ENABLED 
Failed to set beacon parameters
wlan1: INTERFACE-DISABLED 
wlan1: INTERFACE-ENABLED 
Failed to set beacon parameters
wlan1: INTERFACE-DISABLED 
wlan1: INTERFACE-ENABLED 
Failed to set beacon parameters
wlan1: INTERFACE-DISABLED 
wlan1: INTERFACE-ENABLED 
Failed to set beacon parameters
wlan1: INTERFACE-DISABLED 
Could not set interface wlan1 flags (UP): Input/output error
nl80211: Could not set interface 'wlan1' UP
Could not set interface wlan1 flags (UP): Input/output error
nl80211: Could not set interface 'wlan1' UP
wlan1: INTERFACE-ENABLED 
Failed to set beacon parameters
wlan1: INTERFACE-DISABLED 
wlan1: INTERFACE-ENABLED 
Failed to set beacon parameters
wlan1: INTERFACE-DISABLED 
Could not set interface wlan1 flags (UP): No such device
nl80211: Could not set interface 'wlan1' UP
wlan1: INTERFACE-ENABLED 
Failed to set beacon parameters
wlan1: INTERFACE-DISABLED 
wlan1: INTERFACE-ENABLED 
Failed to set beacon parameters
wlan1: INTERFACE-DISABLED 
wlan1: INTERFACE-ENABLED 
Failed to set beacon parameters
wlan1: INTERFACE-DISABLED 
wlan1: INTERFACE-ENABLED 
Failed to set beacon parameters
wlan1: interface state ENABLED->DISABLED
wlan1: AP-DISABLED 
wlan1: CTRL-EVENT-TERMINATING 
nl80211: deinit ifname=wlan1 disabled_11b_rates=0
Configuration file: /etc/hostapd/hostapd.conf
wlan1: AP-ENABLED 
wlan1: INTERFACE-DISABLED 
wlan1: INTERFACE-ENABLED 
Failed to set beacon parameters
wlan1: INTERFACE-DISABLED 
wlan1: INTERFACE-ENABLED 
Failed to set beacon parameters
wlan1: interface state ENABLED->DISABLED
wlan1: AP-DISABLED 
wlan1: CTRL-EVENT-TERMINATING 
nl80211: deinit ifname=wlan1 disabled_11b_rates=0
Configuration file: /etc/hostapd/hostapd.conf
wlan1: AP-ENABLED 
wlan1: interface state ENABLED->DISABLED
wlan1: AP-DISABLED 
wlan1: CTRL-EVENT-TERMINATING 
nl80211: deinit ifname=wlan1 disabled_11b_rates=0
Configuration file: /etc/hostapd/hostapd.conf
wlan1: AP-ENABLED 

OS details:

pi@raspberrypi:/tmp $ cat /etc/*release*
PRETTY_NAME="Raspbian GNU/Linux 10 (buster)"
NAME="Raspbian GNU/Linux"
VERSION_ID="10"
VERSION="10 (buster)"
VERSION_CODENAME=buster
ID=raspbian
ID_LIKE=debian
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"
pi@raspberrypi:/tmp $ uname -a
Linux raspberrypi 5.4.51-v7l+ #1333 SMP Mon Aug 10 16:51:40 BST 2020 armv7l GNU/Linux

At this point I’m wondering whether it could be a bad adapter but wanted to know what else I can do to troubleshoot this/resolve it?


Update 21/09/20 – Hostapd debug logs

I’ve pulled out lines that I believe to be of interest for the issue:

1600641182.604187: nl80211: Drv Event 16 (NL80211_CMD_STOP_AP) received for wlan1
1600641182.604214: wlan1: Event INTERFACE_UNAVAILABLE (28) received
1600641182.604228: Interface wlan1 is unavailable -- stopped
1600641182.605808: RTM_NEWLINK: ifi_index=466 ifname=wlan1 operstate=2 linkmode=0 ifi_family=0 ifi_flags=0x1002 ()
1600641182.605920: nl80211: Interface down (wlan1/wlan1)
1600641182.605943: wlan1: Event INTERFACE_DISABLED (26) received
1600641182.605961: wlan1: INTERFACE-DISABLED 
1600641182.606036: VLAN: RTM_NEWLINK: ifi_index=466 ifname=wlan1 ifi_family=0 ifi_flags=0x1002 ()
1600641182.606054: VLAN: vlan_newlink(wlan1)
1600641182.724045: RTM_DELLINK: ifi_index=466 ifname=wlan1 operstate=2 linkmode=0 ifi_family=0 ifi_flags=0x1002 ()
1600641182.724069: RTM_DELLINK: Interface 'wlan1' removed - mark if_removed=1
1600641182.724083: wlan1: Event INTERFACE_STATUS (5) received
1600641182.724092: Unknown event 5
1600641182.741668: VLAN: RTM_DELLINK: ifi_index=466 ifname=wlan1 ifi_family=0 ifi_flags=0x1002 ()
1600641182.741703: VLAN: vlan_dellink(wlan1)
1600641182.759151: nl80211: Ignored event (cmd=36) for foreign interface (ifindex -1 wdev 0x0)
1600641182.759221: nl80211: Drv Event 36 (NL80211_CMD_REG_CHANGE) received for wlan1
1600641182.759230: nl80211: Regulatory domain change
1600641182.759235:  * initiator=1
1600641182.759241:  * type=0
1600641182.759247:  * alpha2=AU
1600641182.759258: wlan1: Event CHANNEL_LIST_CHANGED (27) received
1600641183.536944: RTM_NEWLINK: ifi_index=2081 ifname=wlan1 operstate=2 linkmode=0 ifi_family=0 ifi_flags=0x1002 ()
1600641183.538906: nl80211: Update ifindex for a removed interface
1600641183.539417: nl80211: Supported cipher 00-0f-ac:1
1600641183.539444: nl80211: Supported cipher 00-0f-ac:5
1600641183.539461: nl80211: Supported cipher 00-0f-ac:2
1600641183.539476: nl80211: Supported cipher 00-0f-ac:4
1600641183.539491: nl80211: Supported cipher 00-0f-ac:10
1600641183.539506: nl80211: Supported cipher 00-0f-ac:8
1600641183.539520: nl80211: Supported cipher 00-0f-ac:9
1600641183.539534: nl80211: Supported cipher 00-0f-ac:6
1600641183.539548: nl80211: Supported cipher 00-0f-ac:13
1600641183.539562: nl80211: Supported cipher 00-0f-ac:11
1600641183.539577: nl80211: Supported cipher 00-0f-ac:12
1600641183.539647: nl80211: Using driver-based off-channel TX
1600641183.539717: nl80211: interface wlan1 in phy phy4
1600641183.539737: nl80211: Set mode ifindex 2081 iftype 3 (AP)
1600641183.539849: nl80211: Unsubscribe mgmt frames handle 0x89823791 (start AP)
1600641183.540033: nl80211: Setup AP(wlan1) - device_ap_sme=0 use_monitor=0
1600641183.540125: nl80211: Subscribe to mgmt frames with AP handle 0x10abf18
1600641186.653836: Could not set interface wlan1 flags (UP): Input/output error
1600641186.653876: nl80211: Could not set interface 'wlan1' UP
1600641186.653899: nl80211: Found matching own interface, but failed to complete reinitialization
1600641186.654069: VLAN: RTM_NEWLINK: ifi_index=2081 ifname=wlan1 ifi_family=0 ifi_flags=0x1002 ()
1600641186.654087: VLAN: vlan_newlink(wlan1)
1600641186.713941: RTM_DELLINK: ifi_index=2081 ifname=wlan1 operstate=2 linkmode=0 ifi_family=0 ifi_flags=0x1002 ()
1600641186.713965: nl80211: if_removed already set - ignore RTM_DELLINK event for wlan1
1600641186.725633: VLAN: RTM_DELLINK: ifi_index=2081 ifname=wlan1 ifi_family=0 ifi_flags=0x1002 ()
1600641186.725659: VLAN: vlan_dellink(wlan1)
1600641187.584495: RTM_NEWLINK: ifi_index=2082 ifname=wlan1 operstate=2 linkmode=0 ifi_family=0 ifi_flags=0x1002 ()
1600641187.585759: nl80211: Update ifindex for a removed interface
1600641187.586447: nl80211: Supported cipher 00-0f-ac:1
1600641187.586483: nl80211: Supported cipher 00-0f-ac:5
1600641187.586500: nl80211: Supported cipher 00-0f-ac:2
1600641187.586525: nl80211: Supported cipher 00-0f-ac:4
1600641187.586540: nl80211: Supported cipher 00-0f-ac:10
1600641187.586554: nl80211: Supported cipher 00-0f-ac:8
1600641187.586569: nl80211: Supported cipher 00-0f-ac:9
1600641187.586583: nl80211: Supported cipher 00-0f-ac:6
1600641187.586597: nl80211: Supported cipher 00-0f-ac:13
1600641187.586831: nl80211: Supported cipher 00-0f-ac:11
1600641187.586855: nl80211: Supported cipher 00-0f-ac:12
1600641187.586932: nl80211: Using driver-based off-channel TX
1600641187.587157: nl80211: interface wlan1 in phy phy5
1600641187.587184: nl80211: Set mode ifindex 2082 iftype 3 (AP)
1600641187.587421: nl80211: Unsubscribe mgmt frames handle 0x89823791 (start AP)
1600641187.587643: nl80211: Setup AP(wlan1) - device_ap_sme=0 use_monitor=0
1600641187.587741: nl80211: Subscribe to mgmt frames with AP handle 0x10abf18
1600641188.364296: nl80211: Connect handle already created (nl_connect=0x10ac970)
1600641188.364502: nl80211: Mark if_removed=0 for wlan1 based on RTM_NEWLINK event
1600641188.364583: wlan1: Event INTERFACE_STATUS (5) received
1600641188.364658: Unknown event 5
1600641188.364744: RTM_NEWLINK: ifi_index=2082 ifname=wlan1 operstate=0 linkmode=0 ifi_family=0 ifi_flags=0x1043 ([UP][RUNNING])
1600641188.364868: nl80211: Interface up (wlan1/wlan1)
1600641188.364980: wlan1: Event INTERFACE_ENABLED (25) received
1600641188.365049: wlan1: INTERFACE-ENABLED 
1600641188.365174: wpa_driver_nl80211_set_key: ifindex=2082 (wlan1) alg=3 addr=0x119324 key_idx=1 set_tx=1 seq_len=0 key_len=16
1600641188.365257: nl80211: KEY_DATA - hexdump(len=16): [REMOVED]
1600641188.365339:    broadcast key
1600641188.365571: nl80211: Set beacon (beacon_set=0)
1600641188.365975: nl80211: ifindex=2082
1600641188.366043: nl80211: beacon_int=100
1600641188.366112: nl80211: beacon_rate=0
1600641188.366186: nl80211: rate_type=0
1600641188.366261: nl80211: dtim_period=2
1600641188.366333: nl80211: ssid - hexdump_ascii(len=7):
     47 2d 57 41 47 4f 4e                              <REDACTED>         
1600641188.366503:   * beacon_int=100
1600641188.366581:   * dtim_period=2
1600641188.366657: nl80211: hidden SSID not in use
1600641188.366735: nl80211: privacy=1
1600641188.366810: nl80211: auth_algs=0x1
1600641188.366882: nl80211: wpa_version=0x2
1600641188.366961: nl80211: key_mgmt_suites=0x2
1600641188.367043: nl80211: pairwise_ciphers=0x10
1600641188.367126: nl80211: group_cipher=0x10
1600641188.367200: nl80211: beacon_ies - hexdump(len=10): 7f 08 00 00 00 02 00 00 00 40
1600641188.367281: nl80211: proberesp_ies - hexdump(len=10): 7f 08 00 00 00 02 00 00 00 40
1600641188.367368: nl80211: assocresp_ies - hexdump(len=10): 7f 08 00 00 00 02 00 00 00 40
1600641188.367517: nl80211: Beacon set failed: -22 (Invalid argument)
1600641188.367590: Failed to set beacon parameters
1600641188.367733: RTM_NEWLINK: ifi_index=2082 ifname=wlan1 operstate=2 linkmode=0 ifi_family=0 ifi_flags=0x1003 ([UP])
1600641188.367894: VLAN: RTM_NEWLINK: ifi_index=2082 ifname=wlan1 ifi_family=0 ifi_flags=0x1002 ()
1600641188.367971: VLAN: vlan_newlink(wlan1)
1600641188.368087: VLAN: RTM_NEWLINK: ifi_index=2082 ifname=wlan1 ifi_family=0 ifi_flags=0x1043 ([UP][RUNNING])
1600641188.368156: VLAN: vlan_newlink(wlan1)
1600641188.368274: VLAN: RTM_NEWLINK: ifi_index=2082 ifname=wlan1 ifi_family=0 ifi_flags=0x1003 ([UP])
1600641188.368340: VLAN: vlan_newlink(wlan1)
1600641188.398935: RTM_NEWLINK: ifi_index=2082 ifname=wlan1 operstate=2 linkmode=0 ifi_family=0 ifi_flags=0x1003 ([UP])
1600641188.399082: VLAN: RTM_NEWLINK: ifi_index=2082 ifname=wlan1 ifi_family=0 ifi_flags=0x1003 ([UP])
1600641188.399135: VLAN: vlan_newlink(wlan1)
1600641195.734325: Unknown Microsoft information element ignored (type=8 len=8)
1600641195.734536: Ignore Probe Request due to DS Params mismatch: chan=7 != ds.chan=1
1600642515.763249: nl80211: send_mlme - da= 64:1c:b0:ef:99:22 noack=1 freq=0 no_cck=0 offchanok=0 wait_time=0 fc=0x50 (WLAN_FC_STYPE_PROBE_RESP) nlmode=3
1600642515.763274: nl80211: send_mlme -> send_frame
1600642515.763287: nl80211: send_frame - Use bss->freq=2442
1600642515.763300: nl80211: send_frame -> send_frame_cmd
1600642515.763314: nl80211: CMD_FRAME freq=2442 wait=0 no_cck=0 no_ack=1 offchanok=0
1600642515.763568: nl80211: Frame command failed: ret=-16 (Device or resource busy) (freq=2442 wait=0)
1600642515.763591: handle_probe_req: send failed
1600642515.765742: nl80211: send_mlme - da= 64:1c:b0:ef:99:22 noack=1 freq=0 no_cck=0 offchanok=0 wait_time=0 fc=0x50 (WLAN_FC_STYPE_PROBE_RESP) nlmode=3
1600642515.765860: nl80211: send_mlme -> send_frame
1600642515.765957: nl80211: send_frame - Use bss->freq=2442
1600642515.766056: nl80211: send_frame -> send_frame_cmd
1600642515.766079: nl80211: CMD_FRAME freq=2442 wait=0 no_cck=0 no_ack=1 offchanok=0
1600642515.766282: nl80211: Frame command failed: ret=-16 (Device or resource busy) (freq=2442 wait=0)
1600642515.766304: handle_probe_req: send failed
1600643055.956614: Ignore Probe Request due to DS Params mismatch: chan=7 != ds.chan=4
1600643955.647033: nl80211: send_mlme - da= 64:1c:b0:ef:99:22 noack=1 freq=0 no_cck=0 offchanok=0 wait_time=0 fc=0x50 (WLAN_FC_STYPE_PROBE_RESP) nlmode=3
1600643955.647057: nl80211: send_mlme -> send_frame
1600643955.647070: nl80211: send_frame - Use bss->freq=2442
1600643955.647084: nl80211: send_frame -> send_frame_cmd
1600643955.647097: nl80211: CMD_FRAME freq=2442 wait=0 no_cck=0 no_ack=1 offchanok=0
1600643955.647326: nl80211: Frame command failed: ret=-16 (Device or resource busy) (freq=2442 wait=0)
1600643955.647353: handle_probe_req: send failed
1600643955.649431: nl80211: send_mlme - da= 64:1c:b0:ef:99:22 noack=1 freq=0 no_cck=0 offchanok=0 wait_time=0 fc=0x50 (WLAN_FC_STYPE_PROBE_RESP) nlmode=3
1600643955.649454: nl80211: send_mlme -> send_frame
1600643955.649467: nl80211: send_frame - Use bss->freq=2442
1600643955.649480: nl80211: send_frame -> send_frame_cmd
1600643955.649493: nl80211: CMD_FRAME freq=2442 wait=0 no_cck=0 no_ack=1 offchanok=0
1600643955.649688: nl80211: Frame command failed: ret=-16 (Device or resource busy) (freq=2442 wait=0)
1600643955.649717: handle_probe_req: send failed
1600643955.652399: nl80211: send_mlme - da= 64:1c:b0:ef:99:22 noack=1 freq=0 no_cck=0 offchanok=0 wait_time=0 fc=0x50 (WLAN_FC_STYPE_PROBE_RESP) nlmode=3
1600643955.652422: nl80211: send_mlme -> send_frame
1600643955.652434: nl80211: send_frame - Use bss->freq=2442
1600643955.652447: nl80211: send_frame -> send_frame_cmd
1600643955.652460: nl80211: CMD_FRAME freq=2442 wait=0 no_cck=0 no_ack=1 offchanok=0
1600643955.652650: nl80211: Frame command failed: ret=-16 (Device or resource busy) (freq=2442 wait=0)
1600643955.652674: handle_probe_req: send failed
1600645124.882081: Add randomness: count=10240 entropy=1010
1600645124.882096: random pool - hexdump(len=128): [REMOVED]
1600645124.882111: random_mix_pool - hexdump(len=8): [REMOVED]
1600645124.882126: random_mix_pool - hexdump(len=16): [REMOVED]
1600645124.882140: random pool - hexdump(len=128): [REMOVED]
1600647135.984635: nl80211: send_mlme - da= 64:1c:b0:ef:99:22 noack=1 freq=0 no_cck=0 offchanok=0 wait_time=0 fc=0x50 (WLAN_FC_STYPE_PROBE_RESP) nlmode=3
1600647135.984658: nl80211: send_mlme -> send_frame
1600647135.984672: nl80211: send_frame - Use bss->freq=2442
1600647135.984687: nl80211: send_frame -> send_frame_cmd
1600647135.984700: nl80211: CMD_FRAME freq=2442 wait=0 no_cck=0 no_ack=1 offchanok=0
1600647135.984925: nl80211: Frame command failed: ret=-16 (Device or resource busy) (freq=2442 wait=0)
1600647135.984952: handle_probe_req: send failed
1600647135.989488: nl80211: send_mlme - da= 64:1c:b0:ef:99:22 noack=1 freq=0 no_cck=0 offchanok=0 wait_time=0 fc=0x50 (WLAN_FC_STYPE_PROBE_RESP) nlmode=3
1600647135.989510: nl80211: send_mlme -> send_frame
1600647135.989523: nl80211: send_frame - Use bss->freq=2442
1600647135.989536: nl80211: send_frame -> send_frame_cmd
1600647135.989549: nl80211: CMD_FRAME freq=2442 wait=0 no_cck=0 no_ack=1 offchanok=0
1600647135.989752: nl80211: Frame command failed: ret=-16 (Device or resource busy) (freq=2442 wait=0)
1600647135.989775: handle_probe_req: send failed

Full debug log here.

Cheers.


Get this bounty!!!

#StackBounty: #linux #ssh #raspberry-pi #tunnel #ngrok ngrok kex_exchange_identification: read: Connection reset by peer

Bounty: 250

I’ve got a raspi (in my robot project) connected to the internet over a 3G connection using a dongle with a simcard. I then use ngrok to expose ssh to a static address so that I can always ssh into it using:

ssh -p 29xxx pi@1.tcp.ngrok.io

That has always worked great for me. Today I wanted to do another test with my robot, but I can’t ssh into the machine through ngrok anymore. It just gives me kex_exchange_identification: Connection closed by remote host

So this is what I did to debug it:

  1. I can ssh into it over the local network fine, so I guess sshd on the pi itself is not the problem.
  2. I checked the ngrok website to see if the pi connected to the ngrok network. It lists the connection saying it was established a couple minutes ago.
  3. I ssh’ed into the pi over the local network, stopped the tunnel and then manually started it to see the logs. It shows me this:
pi@myrobot:~$ ngrok tcp -remote-addr=1.tcp.ngrok.io:29xxx --log=stdout 22
INFO[09-11|09:39:33] no configuration paths supplied
INFO[09-11|09:39:33] using configuration at default config path path=/home/pi/.ngrok2/ngrok.yml                                                                             
INFO[09-11|09:39:33] open config file                         path=/home/pi/.ngrok2/ngrok.yml err=nil                                                                       
t=2020-09-11T09:39:33+0000 lvl=info msg="starting web service" obj=web addr=127.0.0.1:4040                                                                                  
t=2020-09-11T09:39:34+0000 lvl=info msg="tunnel session started" obj=tunnels.session
t=2020-09-11T09:39:34+0000 lvl=info msg="client session established" obj=csess id=1b6463ec0724                                                                              
t=2020-09-11T09:39:34+0000 lvl=info msg="started tunnel" obj=tunnels name=command_line addr=//localhost:22 url=tcp://1.tcp.ngrok.io:29xxx                                   
t=2020-09-11T09:39:38+0000 lvl=warn msg="failed to check for update" obj=updater err="Post https://update.equinox.io/check: context deadline exceeded"                      
  1. I then tried ssh’ing into the pi over the internet again using verbose output (ssh -v -p 29xxx pi@1.tcp.ngrok.io), which gives me the following output:
$ ssh -v -p 29xxx pi@1.tcp.ngrok.io
OpenSSH_8.2p1 Ubuntu-4ubuntu0.1, OpenSSL 1.1.1f  31 Mar 2020
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: include /etc/ssh/ssh_config.d/*.conf matched no files
debug1: /etc/ssh/ssh_config line 21: Applying options for *
debug1: Connecting to 1.tcp.ngrok.io [3.13.191.xxx] port 29xxx.
debug1: Connection established.
debug1: identity file /home/kramer65/.ssh/id_rsa type 0
debug1: identity file /home/kramer65/.ssh/id_rsa-cert type -1
debug1: identity file /home/kramer65/.ssh/id_dsa type -1
debug1: identity file /home/kramer65/.ssh/id_dsa-cert type -1
debug1: identity file /home/kramer65/.ssh/id_ecdsa type -1
debug1: identity file /home/kramer65/.ssh/id_ecdsa-cert type -1
debug1: identity file /home/kramer65/.ssh/id_ecdsa_sk type -1
debug1: identity file /home/kramer65/.ssh/id_ecdsa_sk-cert type -1
debug1: identity file /home/kramer65/.ssh/id_ed25519 type -1
debug1: identity file /home/kramer65/.ssh/id_ed25519-cert type -1
debug1: identity file /home/kramer65/.ssh/id_ed25519_sk type -1
debug1: identity file /home/kramer65/.ssh/id_ed25519_sk-cert type -1
debug1: identity file /home/kramer65/.ssh/id_xmss type -1
debug1: identity file /home/kramer65/.ssh/id_xmss-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_8.2p1 Ubuntu-4ubuntu0.1
kex_exchange_identification: Connection closed by remote host

In the terminal on the pi I see nothing happening. But the output above also suggests that it never actually reaches the pi.

Could it be that ngrok doesn’t pass on the connection properly? Is the problem in the pi? or on my laptop locally? All tips are welcome!

[EDIT]

After some more debugging I found the problem has to be with the mobile connection. When I remove the 3G-dongle and connect the pi to the internet over wifi I can perfectly ssh into it using the ngrok address. But when I connect over 3G I cannot. I checked whether the internet over 3G works by ssh’ing into the pi over the wifi network and using curl ip.me to check whether the public ip changes when I connect over 3G (plus, a ping to 8.8.8.8 increases from 10ms to about 40ms).

I also checked the syslog and that doesn’t say the anything about the incoming message (I would expect a Started Session c7 of user pi). Furthermore, when I start the ngrok tunnel over 3G it adds the line below to the output. The rest (including "client session established") is the same though

lvl=warn msg="failed to check for update" obj=updater err="Post https://update.equinox.io/check: context deadline exceeded"

So why would the tunnel fail over 3G? Could it be that my telco closes all kinds of ports or blocks traffic? Any way of debugging this further?


Get this bounty!!!

#StackBounty: #linux #ubuntu #cron #raspberry-pi #jenkins Play sound from Jenkins script

Bounty: 50

I run Jenkins on Ubuntu Mate on a Raspberry Pi 2 which has sound hardware (via HDMI).

When connected via SSH, sounds works great.

However, it does not work via Jenkins. I tried an espeak 'hi', the build succeedes, but it does not actually produce any sound at all in the speakers.

I assume the current behavior is the default Jenkins behavior, but I would like to be able to play audio files during the build (every hour).

How can I do that?


Get this bounty!!!

#StackBounty: #ffmpeg #raspberry-pi How to build ffmpeg with hardware decoding support for raspberry pi? (cross compilation if possible)

Bounty: 250

Is it possible to build ffmpeg with decoding support for Raspberry Pi? I’ve read that mmal can do hardware accelerated decoding on the Raspberry Pi.

I’ve tried on debian 10 x86_64:

./configure 
    --prefix=${BUILD_DIR}/desktop/${FFMPEG_ARCH_FLAG} 
    --disable-doc 
    --enable-cross-compile 
    --cross-prefix=${CROSS_PREFIX} 
    --target-os=linux 
    --arch=${FFMPEG_ARCH_FLAG} 
    --extra-cflags="-O3 -fPIC $EXTRA_CFLAGS" 
    --enable-mmal 
    --enable-omx 
    --enable-omx-rpi 
    --enable-shared 
    --disable-debug 
    --disable-runtime-cpudetect 
    --disable-programs 
    --disable-muxers 
    --disable-encoders 
    --disable-bsfs 
    --disable-pthreads 
    --disable-avdevice 
    --disable-network 
    --disable-postproc 

where CROSS_PREFIX=aarch64-linux-gnu- and FFMPEG_ARCH_FLAG=aarch64 but obviously I get ERROR: mmal not found. I couldn’t find MMAL to compile and install.


Get this bounty!!!

#StackBounty: #raspberry-pi #symlink #raspbian #cifs Access windows symbolic link from linux cifs

Bounty: 50

I have created symbolic link of the mapped drive (DOS share) on Windows 7 computer 200.90.12.25. Trying to access this from Linux (Raspberry PI) using CIFS command, I get mount error(5): Input/output error. CIFS command and dmesg attached below.

I cannot access the DOS share from Linux because of NETBEUI. Line diagram shown below for reference.

enter image description here

CIFS command

sudo mount -t cifs -o user=username,guest,vers=2.0 //200.90.12.25/DOSA /home/pi/myNAS/myShare

dmesg (also on the Linux client)

[1027098.510573] FS-Cache: Duplicate cookie detected
[1027098.510583] FS-Cache: O-cookie c=c6d9fc6c [p=33027f2d fl=222 nc=2 na=1]
[1027098.510588] FS-Cache: O-cookie d=e8ce4e52 n=203d934d
[1027098.510592] FS-Cache: O-key=[8] '020001bd0a090c12'
[1027098.510606] FS-Cache: N-cookie c=435e27ec [p=33027f2d fl=2 nc=0 na=1]
[1027098.510611] FS-Cache: N-cookie d=e8ce4e52 n=9f19c9a0
[1027098.510614] FS-Cache: N-key=[8] '020001bd0a090c12'
[1027098.515854] CIFS VFS: cifs_mount failed w/return code = -5

any alternative solution much appreciated.


Get this bounty!!!

#StackBounty: #audio #raspberry-pi #sound-card #raspbian #alsa Clone sound from Chromium to ALSA Loopback and also speakers

Bounty: 50

I have working setup on my RPi3 B+ with Raspbian where is sound from Chromium browser send directly to ALSA Loopback device (enabled by snd-aloop kernel module) by this Chromium’s parameter:

--alsa-output-device='plug:front'

This sound is successfully recorded from Loopback capture device hw:0,1.

But I also need this sound be played by external speakers which are connected to line-out (jack).
How Can be this done? Can you help me? How I can clone sound output?

# uname -a
Linux rpi3 4.19.114-v7+ #1303 SMP Tue Apr 7 15:44:16 BST 2020 armv7l GNU/Linux

# aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: Loopback [Loopback], device 0: Loopback PCM [Loopback PCM]
  Subdevices: 7/8
  Subdevice #0: subdevice #0
  Subdevice #1: subdevice #1
  Subdevice #2: subdevice #2
  Subdevice #3: subdevice #3
  Subdevice #4: subdevice #4
  Subdevice #5: subdevice #5
  Subdevice #6: subdevice #6
  Subdevice #7: subdevice #7
card 0: Loopback [Loopback], device 1: Loopback PCM [Loopback PCM]
  Subdevices: 8/8
  Subdevice #0: subdevice #0
  Subdevice #1: subdevice #1
  Subdevice #2: subdevice #2
  Subdevice #3: subdevice #3
  Subdevice #4: subdevice #4
  Subdevice #5: subdevice #5
  Subdevice #6: subdevice #6
  Subdevice #7: subdevice #7
card 1: ALSA [bcm2835 ALSA], device 0: bcm2835 ALSA [bcm2835 ALSA]
  Subdevices: 7/7
  Subdevice #0: subdevice #0
  Subdevice #1: subdevice #1
  Subdevice #2: subdevice #2
  Subdevice #3: subdevice #3
  Subdevice #4: subdevice #4
  Subdevice #5: subdevice #5
  Subdevice #6: subdevice #6
card 1: ALSA [bcm2835 ALSA], device 1: bcm2835 IEC958/HDMI [bcm2835 IEC958/HDMI]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: ALSA [bcm2835 ALSA], device 2: bcm2835 IEC958/HDMI1 [bcm2835 IEC958/HDMI1]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

# cat /proc/asound/cards
 0 [Loopback       ]: Loopback - Loopback
                      Loopback 1
 1 [ALSA           ]: bcm2835_alsa - bcm2835 ALSA
                      bcm2835 ALSA


Get this bounty!!!

#StackBounty: #networking #raspberry-pi #netplan When setting netplan static ip, connection seems to sleep if left for a while

Bounty: 150

I am trying to set static local ip
on ubuntu 20.04 server by disabling cloud-init,
then set my 50-cloud-init.yaml

This is on a Raspberry Pi 4 with wired connection.

network:
    ethernets:
        eth0:
            addresses: [192.168.1.11/24]
            dhcp4: false
            gateway4: 192.168.1.1
            nameservers:
                addresses: [8.8.8.8, 8.8.4.4]
    version: 2

executed netplan generate and then netplan try.
It works, and successfully set static local IP.

However, this causes "sleeps".
When i ssh to it, then leave it for a moment, input would take seconds to respond again.
This is not only on SSH, i also ran a TCP server and same thing happens, it seems to sleep if left for a while.

It only happens after setting static ip.

Can anyone suggest what is going on?


Get this bounty!!!

#StackBounty: #ubuntu #networking #raspberry-pi #netplan When setting netplan static ip, connection seems to sleep if left for a while

Bounty: 150

I am trying to set static local ip
on ubuntu 20.04 server by disabling cloud-init,
then set my 50-cloud-init.yaml

This is on a Raspberry Pi 4 with wired connection.

network:
    ethernets:
        eth0:
            addresses: [192.168.1.11/24]
            dhcp4: false
            gateway4: 192.168.1.1
            nameservers:
                addresses: [8.8.8.8, 8.8.4.4]
    version: 2

executed netplan generate and then netplan try.
It works, and successfully set static local IP.

However, this causes "sleeps".
When i ssh to it, then leave it for a moment, input would take seconds to respond again.
This is not only on SSH, i also ran a TCP server and same thing happens, it seems to sleep if left for a while.

It only happens after setting static ip.

Can anyone suggest what is going on?


Get this bounty!!!