如何使用蓝牙控制树莓派 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);
};
(🐞 反爬虫测试!打击盗版⚠️)如果你看到这个信息, 说明这是一篇剽窃的文章,请访问 https://www.cnblogs.com/xgqfrms/ 查看原创文章!
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-2021
www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!
原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!
本文首发于博客园,作者:xgqfrms,原文链接:https://www.cnblogs.com/xgqfrms/p/17336332.html
未经授权禁止转载,违者必究!