树莓派烧录openwrt后无法上网的解决

How to fix OpenWRT opkg Failed to send request: Operation not permitted – TechOverflow

先设定ip地址(防止与现有路由器地址冲突),同时必须配置网关地址(路由器地址)

进入管理界面, 进入菜单Network/Interfaces 编辑 interface. Set Use custom DNS servers to:

1.1.1.1
1.0.0.1

以上设置完一定要“Save & Apply”

安装中文软件包

opkg update
opkg install luci-i18n-base-zh-cn

Sony摄像机IMX-519接入树莓派

Step 1: sudo -i
Step 2: nano /boot/config.text
Step 3: Add this in # Automatically load overlays for detected cameras OR [all] section "dtoverlay=imx519"
Step 4: reboot
Step 5: execute this command in terminal libcamera-hello

pico w 联网获取网页信息

import network
import urequests

# set your WiFi Country
rp2.country('CN')
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
# set power mode to get WiFi power-saving off (if needed)
wlan.config(pm = 0xa11140)
wlan.connect('YourHomeSSID', 'YourSSIDPassword')

# Make GET request
r = urequests.get("http://mixleg.com")
print(r.content)
r.close()

远程网页控制

#webled.py
import netman
import socket

from machine import Pin

led = Pin("LED", Pin.OUT)

country = 'CN'
ssid = '2312'
password = 'only'

wifi_connection = netman.connectWiFi(ssid,password,country)

html = """<!DOCTYPE html>
<html>
<head> <title>Pico W</title> </head>
<body> <h1>Pico W</h1>
<p>Current status: %s</p>
<p><a href="http://"""+wifi_connection[0]+"""/light/on">Turn ON</a></p>
<p><a href="http://"""+wifi_connection[0]+"""/light/off">Turn OFF</a></p>
<p>by <a href="http://mixdiy.com">mixdiy.com</a></p>
</body>
</html>
"""


# Open socket
addr = socket.getaddrinfo('0.0.0.0', 80)[0][-1]
s = socket.socket()
s.bind(addr)
s.listen(1)

print('listening on', addr)

# Initialize LED status
led.value(0)
stateis = "LED is OFF"

# Listen for connections
while True:
  try:
    cl, addr = s.accept()
    print('client connected from', addr)
    request = cl.recv(1024)
    print(request)

    request = str(request)[0:50] # The [0:50] avoids getting the url directory from referer 
    led_status = request.find('GET / HTTP')
    led_on = request.find('/light/on')
    led_off = request.find('/light/off')
    print( 'led on = ' + str(led_on))
    print( 'led off = ' + str(led_off))

    if led_status >0:
      print("LED status request") # No LED action

    if led_on >0:
      print("led on")
      led.value(1)
      stateis = "LED is ON"

    if led_off >0:
      print("led off")
      led.value(0)
      stateis = "LED is OFF"

    response = html % stateis

    cl.send('HTTP/1.0 200 OK\r\nContent-type: text/html\r\n\r\n')
    cl.send(response)
    cl.close()

  except OSError as e:
    cl.close()
    print('connection closed')
#netman.py
import network, rp2
import time

def connectWiFi(ssid,password,country):
   rp2.country(country)
   wlan = network.WLAN(network.STA_IF)
   wlan.config(pm = 0xa11140)
   wlan.active(True)
   wlan.connect(ssid, password)
   # Wait for connect or fail
   max_wait = 10
   while max_wait > 0:
      if wlan.status() < 0 or wlan.status() >= 3:
        break
      max_wait -= 1
      print('waiting for connection...')
      time.sleep(1)

   # Handle connection error
   if wlan.status() != 3:
      raise RuntimeError('network connection failed')
   else:
      print('connected')
      status = wlan.ifconfig()
      print( 'ip = ' + status[0] )
   return status

AP

import socket
import network
import machine

ssid = 'MicroPython-AP'
password = '123456789'

led = machine.Pin("LED",machine.Pin.OUT)

ap = network.WLAN(network.AP_IF)
ap.config(essid=ssid, password=password)
ap.active(True)

while ap.active() == False:
  pass

print('Connection successful')
print(ap.ifconfig())

html = """<!DOCTYPE html>
<html>
    <head> <title>Pico W</title> </head>
    <body> <h1>Pico W</h1>
        <p>Hello from Pico W.</p>
    </body>
</html>
"""

addr = socket.getaddrinfo('0.0.0.0', 80)[0][-1]
s = socket.socket()
s.bind(addr)
s.listen(1)

print('listening on', addr)
led.off()

# Listen for connections
while True:
    try:
        cl, addr = s.accept()
        print('client connected from', addr)
        request = cl.recv(1024)
        led.on()
        print(request)

        cl.send('HTTP/1.0 200 OK\r\nContent-type: text/html\r\n\r\n')
        cl.send(html)
        cl.close()
        led.off()

    except OSError as e:
        cl.close()
        print('connection closed')

树莓派cron 和 Crontab设置开机定时任务

树莓派默认系统下启动、重启、停止、查询状态的命令

service cron start
service cron restart
service cron stop
service cron status

树莓派默认系统下设置crontab【定时任务】为开机启动和开机不启动

systemctl is-enabled cron.service  --- 查看crond是否为开机自启动
systemctl enable cron.service  --- 将服务设置为开启启动
systemctl disable cron.service  --- 关闭服务开机自启动

树莓派——Cron和Crontab(定时任务)

Cron是Unix系统的一个配置定期任务的工具,用于定期或者以一定的时间间隔执行一些命令或者脚本;可执行的任务范围可以是每天夜里自动备份用户的home文件夹,也可以每个小时记录CPU的信息日志。

crontab(cron table)命令用于编辑执行中的定期任务列表,并且操作是基于每个用户的,每一个用户(包括root用户)都拥有自己的crontab。

EDITING CRONTAB(编辑crontab)

运行crontab和-e选项来编辑cron table:

crontab -e

SELECT AN EDIROR(选择一个编辑器)

第一次运行crontab命令的时候会提示你选择一个编辑器。如果你不确定使用哪一个,你可以直接回车选择默认的nano编辑器。

每一项cron实体的内容都包含六个部分:分钟、小时、月份中的哪一天、年份中的哪一月、星期中的哪一天,还有定时执行的命令。

# m h  dom mon dow   command

# * * * * *  command to execute
# ┬ ┬ ┬ ┬ ┬
# │ │ │ │ │
# │ │ │ │ │
# │ │ │ │ └───── 星期中的哪一天(0-7)(从0到6代表星期日到星期六,也可以使用名字;7是星期天,等同于0)
# │ │ │ └────────── 月份 (1 - 12)
# │ │ └─────────────── 月份中的日 (1 - 31)
# │ └──────────────────── 小时 (0 - 23)
# └───────────────────────── 分钟 (0 - 59)

例如:

0 0 * * *  /home/pi/backup.sh

这项cron实例将会在每一天的午夜执行backup.sh脚本。

*/5 * * * * sudo python /home/pi/Downloads/DDNS-master/run.py

这项cron实例将会每5分钟执行run.py脚本。

利用树莓派建立打印共享服务器

利用树莓派建立打印共享服务器

https://zhuanlan.zhihu.com/p/496961274

安装插件

https://developers.hp.com/hp-linux-imaging-and-printing/plugins

Plugins

hplip-3.17.11-plugin.run

hplip-3.17.11-plugin.run.asc

hplip-3.18.3-plugin.run

hplip-3.18.3-plugin.run.asc

hplip-3.18.4-plugin.run

hplip-3.18.4-plugin.run.asc

hplip-3.18.5-plugin.run

hplip-3.18.5-plugin.run.asc

hplip-3.18.6-plugin.run

hplip-3.18.6-plugin.run.asc

hplip-3.18.7-plugin.run

hplip-3.18.7-plugin.run.asc

hplip-3.18.9-plugin.run

hplip-3.18.9-plugin.run.asc

hplip-3.18.10-plugin.run

hplip-3.18.10-plugin.run.asc

hplip-3.18.12-plugin.run

hplip-3.18.12-plugin.run.asc

hplip-3.19.1-plugin.run

hplip-3.19.1-plugin.run.asc

hplip-3.19.3-plugin.run

hplip-3.19.3-plugin.run.asc

hplip-3.19.5-plugin.run

hplip-3.19.5-plugin.run.asc

hplip-3.19.6-plugin.run

hplip-3.19.6-plugin.run.asc

hplip-3.19.8-plugin.run

hplip-3.19.8-plugin.run.asc

hplip-3.19.10-plugin.run

hplip-3.19.10-plugin.run.asc

hplip-3.19.11-plugin.run

hplip-3.19.11-plugin.run.asc

hplip-3.19.12-plugin.run

hplip-3.19.12-plugin.run.asc

hplip-3.20.3-plugin.run

hplip-3.20.3-plugin.run.asc

hplip-3.20.5-plugin.run

hplip-3.20.5-plugin.run.asc

hplip-3.20.6-plugin.run

hplip-3.20.6-plugin.run.asc

hplip-3.20.9-plugin.run

hplip-3.20.9-plugin.run.asc

hplip-3.20.11-plugin.run

hplip-3.20.11-plugin.run.asc

hplip-3.21.2-plugin.run

hplip-3.21.2-plugin.run.asc

hplip-3.21.4-plugin.run

hplip-3.21.4-plugin.run.asc

hplip-3.21.6-plugin.run

hplip-3.21.6-plugin.run.asc

hplip-3.21.8-plugin.run

hplip-3.21.8-plugin.run.asc

hplip-3.21.10-plugin.run

hplip-3.21.10-plugin.run.asc

hplip-3.21.12-plugin.run

hplip-3.21.12-plugin.run.asc

hplip-3.22.2-plugin.run

hplip-3.22.2-plugin.run.asc

hplip-3.22.4-plugin.run

hplip-3.22.4-plugin.run.asc

hplip-3.22.6-plugin.run

hplip-3.22.6-plugin.run.asc

安装驱动及打印程序
首先更新源并安装Hp的打印机驱动 hplip
$ sudo apt update
$ sudo apt install hplip

然后安装Apple开源的远程打印工具 cups,并配置相应权限
$ sudo apt install cups # Install cups package
$ sudo usermod -aG lpadmin pi # Add user to lpadmin group,pi is your user name
$ sudo cupsctl --remote-any # open remote access

然后使用在同一局域网的电脑,访问 https://树莓派IP:631

连接打印机和树莓派,点击Add Printer添加打印机,在弹出的窗口中输入对应的用户信息,使用在上一步中用户组中添加的用户

然后按着一步步的指引,选择HP LaserJet 1020打印机,然后按照提示,选择和名称对应的驱动,我们会发现 LaserJet 1020 对应驱动会提示:HP laserjet requires proprietary plugin,也就是我们不仅需要这个通用的驱动,而且需要一些额外的插件,打印机才能正常工作。

查阅资料发现:HP官方已经给出了说明,我们需要查看hplip版本,然后安装对应的驱动插件。

首先我们查看一下版本,发现是3.20.3版本
$ sudo apt show hplip
Package: hplip
Version: 3.20.3+dfsg0-2
Priority: optional
Section: utils
Origin: Ubuntu
Maintainer: Ubuntu Developers [email protected]
Original-Maintainer: Debian Printing Team [email protected]
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Installed-Size: 518 kB

然后在 插件列表 中找到 3.20.3 对应的hplip-3.20.3-plugin.run和hplip-3.20.3-plugin.run.asc,使用wget下载到树莓派本地。
Package: hplip
Version: 3.17.10+repack0-5
Priority: optional
Section: utils
Origin: Ubuntu
Maintainer: Ubuntu Developers <[email protected]>
Original-Maintainer: Debian Printing Team <[email protected]>
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Installed-Size: 1,595 kB
Depends: adduser, cups, hplip-data (= 3.17.10+repack0-5), libhpmud0 (= 3.17.10+repack0-5), libsane-hpaio (= 3.17.10+repack0-5), lsb-base, printer-driver-hpcups (= 3.17.10+repack0-5), python3-dbus, python3-gi, python3-pexpect, python3-pil, python3-reportlab, wget, python3 (<< 3.7), xz-utils, python3 (>= 3.6~), libc6 (>= 2.17), libcups2 (>= 1.6.0), libdbus-1-3 (>= 1.9.14), libsane1 (>= 1.0.24)
Recommends: avahi-daemon, policykit-1, printer-driver-postscript-hp, sane-utils
Suggests: hplip-doc, hplip-gui, python3-notify2, system-config-printer
Homepage: https://developers.hp.com/hp-linux-imaging-and-printing
Task: ubuntu-desktop, kubuntu-desktop, xubuntu-core, xubuntu-desktop, lubuntu-desktop-share, lubuntu-gtk-desktop, lubuntu-desktop, lubuntu-qt-desktop, ubuntustudio-desktop-core, ubuntustudio-desktop, ubuntukylin-desktop, ubuntu-mate-core, ubuntu-mate-desktop, ubuntu-budgie-desktop
Supported: 5y
Download-Size: 1,030 kB
APT-Manual-Installed: yes
APT-Sources: http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports bionic/main arm64 Packages
Description: HP Linux Printing and Imaging System (HPLIP)

运行 hp-setup -i 使用命令行进行安装,按照提示命令,进行插件的安装。

[scode type=“yellow”]这里建议提前下好安装,而不是直接联网下载,速度较快,指定路径需要为绝对路径[/scode]

至此,我们可以尝试使用手机或者电脑搜索打印机来进行打印测试,没有其他意外的话,可以发现打印成功!

另一种办法

raspberry 4安装HP 1020 plus打印机,利用树莓派4制作无线打印服务器

安装php扩展extension-xml等

安装Brizy时会出现缺失的安装

extension-xml/extension-zip/extension-curl

sudo apt-get install php7.4-xml
sudo apt-get install php7.4-zip
sudo apt-get install php7.4-curl

为ubuntu添加desktop应用

.Desktop文件

  • 为某一应用创建.desktop文件
[Desktop Entry]
Name=application_name
Exec=/xxx/xxx/xx.AppImage # 可执行文件,非root权限
Icon=/xxx/xxx/xxx.png	#icon path
Type=Application
StartupNotify=true
  • 为该.desktop添加可执行权限,并移动到/usr/share/applications/目录下。
sudo chmod +x xxx.desktop
sudo mv xxx.desktop /usr/share/applications/            

刷新图标

在我们修改某.desktop图标后,发现并没有更新。这是因为系统对这些应用的图标进行了缓存,这时就需要刷新图标缓存。

sudo update-icon-cache /usr/share/icons/*