如何使用蓝牙控制树莓派 All In One
如何使用蓝牙控制树莓派 All In One
Raspberry Pi & Bluetooth & Node.js
$ sudo apt-get update
$ sudo apt-get upgrade
# nvm
$ nvm -h
$ nvm ls
$ nvm ls-remote | grep "Latest LTS"
$ nvm install 18.16.0
$ nvm use 18.16.0
$ nvm alias default 18.16.0
$ nvm alias default node
# $ sudo apt-get install nodejs
$ node -v
$ npx -v
$ npm -v
$ which node
# /home/pi/.nvm/versions/node/v18.16.0/bin/node
# bleno 依赖其它一些软件框架,主要包括 bluetooth 及 bluez
$ sudo apt-get install bluetooth bluez libbluetooth-dev libudev-dev
# iot-bluetooth
$ npm init
# ✅
$ npm install bleno
# ❌
$ npm install mraa
# ❓
$ npm install noble
# 想要在 Pi 上实现 central 功能,则要使用 noble
模块依赖:
bleno,实现 BLE
peripheral (外设) 的功能由该模块来实现;
mraa,是 intel 推出的一个低级硬件库
,包括 C/Python/Node.js 等实现,
除了支持 intel 自家的 galileo 及 edison 等硬件外,还支持包括 RPI 在内的许多硬件;
另外还有一个 upm 库,支持大量的传感器及输出外设;
# test
$ cd ./node_modules/bleno && sudo node test bleno
https://github.com/sandeepmistry/bleno
https://www.npmjs.com/package/bleno
https://www.npmjs.com/package/mraa
https://github.com/intel-iot-devkit/mraa
https://github.com/eclipse/mraa
http://mraa.io/
# hciconfig 命令来查看设备信息
$ hciconfig dev
demos
nordic nrf connect
App 应用 ❓ 可以写个简单的 APP 来控制 RPI3
向 LedCharacteristic
写入 0x01
值,代表点亮
LED 灯
var led = new mraa.Gpio(36);
led.dir(mraa.DIR_OUT);
var name = 'RPI3';
var service_rpi3_uuid = '98860000ca0011e7b3fcf714f9f939b3';
var charact_led_uuid = '98860001ca0011e7b3fcf714f9f939b3';
LedCharacteristic.prototype.onWriteRequest = function(data, offset, withoutResponse, callback) {
console.log('LedCharacteristic write request: ' + data.toString('hex') + ' ' + offset + ' ' + withoutResponse);
if(data.readUInt8(0) == 0) {
console.log('led off');
led.write(0);
} else {
console.log('led on');
led.write(1);
}
callback(this.RESULT_SUCCESS);
};
macOS
Intel CPU
s
Intel(R) Core(TM)
i7-8750H
CPU @ 2.20GHz
$ node ./os-module.mjs
os.arch() = x64
os.cpus().length = 12
os.cpus()[0] = {
model: 'Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz',
speed: 2200,
times: { user: 3276490, nice: 0, sys: 2014940, idle: 30180650, irq: 0 }
}
os.hostname() = xgqfrms-mbp.local
os.platform() = darwin
os.userInfo() = {
uid: 501,
gid: 20,
username: 'xgqfrms-mbp',
homedir: '/Users/xgqfrms-mbp',
shell: '/bin/zsh'
}
os.version() = Darwin Kernel Version 21.4.0: Mon Feb 21 20:34:37 PST 2022; root:xnu-8020.101.4~2/RELEASE_X86_64
https://www.cnblogs.com/xgqfrms/p/17400616.html
refs
用超低功耗蓝牙控制树莓派3
https://mp.weixin.qq.com/s/cX-BHxC8RBJ8Etj3-f2LtA
https://mp.weixin.qq.com/s/Cznb6XXOUhp54cyX66a0BQ
https://mp.weixin.qq.com/s/EKZ-V97h_U5BcFaVxpFXJg
https://mp.weixin.qq.com/s/riT3WyRoo0wvvcWRMMo6tg
https://mp.weixin.qq.com/s/cICESlwpPk3cBXILYNdQPg
https://mp.weixin.qq.com/s/qrHUE3PPw2bfsALWawnWxg
©xgqfrms 2012-2025
www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!
原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!
本文首发于博客园,作者:xgqfrms,原文链接:https://www.cnblogs.com/xgqfrms/p/17336332.html
未经授权禁止转载,违者必究!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库
2022-04-20 vite ts pinia project, vue devtools not work for pinia bug All In One
2022-04-20 js regexp group & RegExp.`$1`~`$9` All In One
2022-04-20 Vue 3.x & Pinia Actions All In One
2022-04-20 Vue 3.x disable ESlint error All In One
2021-04-20 Node.js express server render HTML template All In One
2020-04-20 Angular Routing
2020-04-20 Angular 2020