Not understanding why I am not receiving any rssi data from my raspberry pi 3 to my server

*爱你&永不变心* 提交于 2020-05-16 06:32:25

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!