不明白为什么我没有从我的 raspberry pi 3 接收到任何 rssi 数据到我的服务器 [英] Not understanding why I am not receiving any rssi data from my raspberry pi 3 to my server
问题描述
我在尝试显示来自我的 raspberry pi 3 的 RSSI 值以在我的服务器上显示时遇到问题.连接成功 如图所示我已经能够成功连接我的客户端和服务器,但没有显示 rssi 数据.
以下代码是我从pi执行的:
var noble = require('noble');//用你服务器的IP替换localhost;var socket = require('socket.io-client')('http://localhost:3000/scanner');//替换为你的硬件地址var addressToTrack = '7c669d9b2dda';socket.on('connect', function(){console.log('连接到服务器');});贵族.on('发现',功能(外设){if(peripheral.uuid == addressToTrack){socket.emit('deviceData', {mac:peripheral.uuid, rssi:peripheral.rssi});}});高贵的开始扫描([],真)
接下来的代码是我用来设置我的服务器以及它应该如何接收从 pi 发送的信息的代码:
var express = require('express');var app = require('express')();var http = require('http').Server(app);var io = require('socket.io')(http);var scan = io.of('/scanner');扫描仪.on('连接',功能(套接字){console.log('扫描仪已连接');socket.on('message', function(msg) {//从扫描仪接收消息//在这里做一些处理});socket.on('断开', function() {console.log('扫描仪断开');});});http.listen(3000, function() {console.log('监听 *:3000');});
以下代码摘自https://blog.truthlabs.com/beacon-tracking-with-node-js-and-raspberry-pi-794afa880318 如果您想知道我从哪里引用代码.
我对这一切都很陌生,所以如果我不断要求澄清,请原谅.
您在服务器上缺少 deviceData
的侦听器,这是您从客户端发出的事件.
>
socket.on('deviceData', function(msg) {//从扫描仪接收消息//在这里做一些处理});
I am having problems trying to display the RSSI values from my raspberry pi 3 to show on my server. Connection Success as you can see by the picture I have been able to successfully connect my client and server but no rssi data are showing.
The following code is what I executed from the pi:
var noble = require('noble');
//replace localhost with your server's IP;
var socket = require('socket.io-client')('http://localhost:3000/scanner');
//replace with your hardware address
var addressToTrack = '7c669d9b2dda';
socket.on('connect', function(){
console.log('connected to server');
});
noble.on('discover', function(peripheral){
if(peripheral.uuid == addressToTrack){
socket.emit('deviceData', {mac: peripheral.uuid, rssi:peripheral.rssi});
}
});
noble.startScanning([], true)
This next code is the code I used to setup my server and how it should receive the information sent from the pi:
var express = require('express');
var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);
var scanner = io.of('/scanner');
scanner.on('connection', function(socket) {
console.log('Scanner Connected');
socket.on('message', function(msg) {
//received message from scanner
//do some processing here
});
socket.on('disconnect', function() {
console.log('Scanner Disconnected');
});
});
http.listen(3000, function() {
console.log('listening on *:3000');
});
The following code is taken from https://blog.truthlabs.com/beacon-tracking-with-node-js-and-raspberry-pi-794afa880318 if you're wondering where I am referencing the code from.
I am new to all this so forgive if I continuously ask for clarifications.
You're missing a listener for deviceData
on the server, which is the event you're emitting from the client.
socket.on('deviceData', function(msg) {
//received message from scanner
//do some processing here
});
这篇关于不明白为什么我没有从我的 raspberry pi 3 接收到任何 rssi 数据到我的服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!