当前位置: 首页 > news >正文

Python 在树莓派上实现WIFI连接

开发语言:Python

硬件环境:树莓派 4B

运行环境:Raspberry Pi OS 64-bit

连接WIFI还是比较简单的,用了好几个Python 库都效果不怎么理想,最后还是使用命令的方式是最自在的

先断开当前的连接  wlan0 可以替换成你当前设备的网卡

ssid和pwd 可以通过入参的方式传进来

            # 先断开连接cmd = "sudo nmcli device disconnect wlan0"print(cmd)# 使用subprocess模块执行命令try:output = subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT)print("disconnect Command executed successfully:")print(output.decode('utf-8'))except subprocess.CalledProcessError as e:print("disconnect Command execution failed:")print(e.output.decode('utf-8'))command = f"sudo nmcli device wifi connect {ssid} password {psw}"print(command)# 使用subprocess模块执行命令res=""try:output = subprocess.check_output(command, shell=True, stderr=subprocess.STDOUT)res=output.decode('utf-8')print("connect Command executed successfully:")print(output.decode('utf-8'))except subprocess.CalledProcessError as e:print("connect Command execution failed:")print(e.output.decode('utf-8'))res=output.decode('utf-8')if("成功" in res):return BaseResult(True,res)else:return BaseResult(False,res)

http://www.lryc.cn/news/460659.html

相关文章:

  • vmware下ubuntu18.04中使用笔记本的摄像头
  • 【Linux】最基本的杂项设备驱动
  • RadioGroup RadioButton底部导航栏
  • SQL分类中的DQL
  • 1.3.ReactOS系统 PAGED_CODE 宏函数的实现
  • 【论文速看】DL最新进展20241015-目标检测、图像超分
  • 京准电钟:NTP时间服务器让大数据时钟同步
  • SSL免费证书申请(七牛云/阿里云等)
  • 十二、结构型(代理模式)
  • 使用 python 下载 bilibili 视频
  • DevExpress WinForms中文教程:Data Grid - 如何点击获取信息?
  • 真空牛肉滚揉机的优点:
  • 【物流配送中心选址问题】基于退火算法混合粒子群算法
  • elasticsearch 8.2 版本账号密码设置及SSL设置
  • git gui基本使用
  • 从automaxprocs库浅窥Linux容器的资源控制
  • AI 读文献(二):综述论文10倍速读和整理
  • 【AAOS】Android Automotive 10模拟器源码下载及编译
  • 前端开发攻略---使用css实现滚动吸附效果
  • 解析 MySQL 查询优化:提升性能的十个关键策略
  • QT--QPushButton设置文本和图标、使能禁能、信号演示
  • PostgreSQL学习笔记六:模式SCHEMA
  • 基础IO -- 理解文件(1)
  • golang包管理
  • outlook 添加企业邮箱账号出现 553 authentication is required 错误解决
  • 一个开源可本地部署的英文翻译服务----EnToZhAPI
  • 【unity】编辑器扩展——在OnValidate中创建、删除游戏物体
  • 学习记录:js算法(六十四):最后一块石头的重量
  • 单片机探秘:从理论到应用
  • options妙用