问题
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.
回答1:
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
});
来源:https://stackoverflow.com/questions/61409653/not-understanding-why-i-am-not-receiving-any-rssi-data-from-my-raspberry-pi-3-to