I'm doing some tests with bleno installed on a Raspberry Pi, and i'm experiencing big issues with secure characteristics.
I can replicate this scenario with LightBlue on android and iPhone.
If i define a service with a secure charachteristic, when i try to read this charachteristic, bleno fires the disconnect callback, and it freezes until i restart it.
I've already upgraded to bluez 5.64, nothing changed.
var StaticReadOnlyCharacteristic = function() {
StaticReadOnlyCharacteristic.super_.call(this, {
uuid: 'fffffffffffffffffffffffffffffff1',
properties: ['read'],
secure:['read'],
value: Buffer.from('value'),
descriptors: [
new BlenoDescriptor({
uuid: '2901',
value: 'user description'
})
]
});
};
util.inherits(StaticReadOnlyCharacteristic, BlenoCharacteristic);
function SampleService() {
SampleService.super_.call(this, {
uuid: 'fffffffffffffffffffffffffffffff0',
characteristics: [
new StaticReadOnlyCharacteristic()
]
});
}
util.inherits(SampleService, BlenoPrimaryService);
bleno.on('stateChange', function(state) {
console.log('on -> stateChange: ' + state + ', address = ' + bleno.address);
if (state === 'poweredOn') {
bleno.startAdvertising('test', ['fffffffffffffffffffffffffffffff0']);
} else {
bleno.stopAdvertising();
}
});
Related
I am developing a small game (similar to tictactoe) in React which uses socket.io. He is a description of a scenario were a player makes a move:
Move is sent to the server by emitting a game-move event (from the react client).
Server updates local board array then emits an event containing a copy of the board to the clients(s) via a ${gameId}-board event (clients listen based on the gameId they have).
Upon, the client(s), receiving the event, they update the board with the move played before step one and this reflects on the screen.
The issue is I only see the changes on the screen of the player who played the move and wanted to updated all clients that are in that game (subscribed to the gameId). In other words, updates are only occurring if either person makes a move.
I am using componentDidUpdate() which uses a socket connection to receive events and update the state but for some reason the problem I mentioned above is happening and would appreciate some input. Below is the code for what I just described (minus the server and other components as those are working fine):
class Board extends React.Component<any, any> {
constructor(props: any) {
super(props);
this.state = {
squares: Array(6).fill([]).map(() => Array(7).fill(null)),
errorOccured: false,
errorMessage: "",
gameId: "",
};
}
componentDidMount(): void {
...
}
componentDidUpdate(): void {
// #NOTE: This is not triggering on a different tab/screen
socketConnection.on(`${this.state.gameId}-board`, (message) => {
const data = JSON.parse(message);
this.handleMessage(data);
});
}
handleMessage(data: any) {
if(data && data.errorOccured) {
this.setState({errorOccured: true, errorMessage: data.errorMessage});
} else if(data && !data.errorOccured) {
let updatedBoard = data.game.gameState
this.setState({
board: updatedBoard
});
} else {
this.setState({errorOccured: true, errorMessage: "An error occurred, please try again."});
}
}
handleMove(column: number) {
let isValid = this.isMoveValid(column);
if(!isValid) {
this.setState({
errorOccured: true,
errorMessage: "Invalid Move!"
})
} else {
socketConnection.emit(`game-move`,
...
);
}
}
renderSquare(row: number, col: number, key: number) {
return (
<Square
key = { key }
value = { this.state.squares[row][col] }
onClick = { () => this.handleMove(col) }
/>
);
}
render() {
const status = "Current Player: " + ( this.state.xIsNext ? '👻' : '🤡' );
let square = 0;
return (
<div>
<div className="status">{status}</div>
{
this.state.squares.map((row: any, rowIndex: number) =>
(
<div className="row" key={rowIndex} >
{
(row.map((value: any, colIndex: number) => (
this.renderSquare(rowIndex, colIndex, square++)
)))
}
</div>
)
)
}
</div>
)
}
}
export default Board;
Please don't worry/focus about the design, I am simply using this tiny project as an introduction to React.
I'm new to webrtc so and i'm using the simple-peer package ! and i'm working on like a discord clone where someone opens a room then other people can go and join ! sometimes the connections between them work perfectly fine ! and sometimes it works just from one side or not work at all !
this is the peer config that i'm using
export const prepareNewPeerConnection = (connUserSocketId, isInitiator) => {
const localStream = store.getState().room.localStream;
if (isInitiator) {
console.log("preparing as initiator");
} else {
console.log("preparing not as an initiator");
}
peers[connUserSocketId] = new Peer({
initiator: isInitiator,
config: {
iceServers: [{ urls: "stun:stun.l.google.com:19302" }],
},
stream: localStream,
});
peers[connUserSocketId].on("signal", (data) => {
const signalData = {
signal: data,
connUserSocketId,
};
signalPeerData(signalData);
});
peers[connUserSocketId].on("stream", (remoteStream) => {
remoteStream.connUserSocketId = connUserSocketId;
addNewRemoteStream(remoteStream);
});
};
i have seen people talking about the turn and stun servers which i don't really understand how they work ! can they be the problem in here ?
When load testing the program i was using pubnub for creating some integration i sent around 2000 request and on each request pubnub instance was created with different pub,sub keys and subscription to channel and listeners added but after some time when there is network issue pubnub throws socket hang up error and the memory starts spiking and eventually process is killed though i am destroying pubnub object when there is failure in subscription.
class pubnub{
private config;
private pubnub;
constructor(options){
this.config = options
}
register(callback) {
let timetoken = null;
this.pubnub = new Pubnub({
publish_key: options.publish_key,
subscribe_key: options.subscribe_key,
ssl: true,
keepAlive: true
});
this.pubnub.addListener({
message: function (m) {
// console.log('----------------- ', m);
if (timetoken !== m.timetoken) {
timetoken = m.timetoken;
}
},
status: function (m) {
console.log(m);
if (m && m.error === true) {
this.pubnub.destroy(true);
return callback(m.errorData);
}
callback(null, true);
}
}
});
this.pubnub.subscribe({
channels: option.channels
});
}
}
I'm using the VM2 package to run user code. I'm trying to intercept console output and have set the NodeVM object's console property to 'redirect':
// Create a new sandbox VM for this request
const vm = new NodeVM( {
console: 'redirect',
timeout: 30000,
sandbox: { request, state, response },
require: {
external: true
}
});
According to the documentation that redirects console output to 'events'. I'm new to NodeJS, how do I hook into those events to capture the console.log messages executed inside the Sandbox?
After digging through the source code, I found this file where the event emit is occuring:
sandbox.js
if (vm.options.console === 'inherit') {
global.console = Contextify.readonly(host.console);
} else if (vm.options.console === 'redirect') {
global.console = {
log(...args) {
vm.emit('console.log', ...Decontextify.arguments(args));
return null;
},
info(...args) {
vm.emit('console.info', ...Decontextify.arguments(args));
return null;
},
warn(...args) {
vm.emit('console.warn', ...Decontextify.arguments(args));
return null;
},
error(...args) {
vm.emit('console.error', ...Decontextify.arguments(args));
return null;
},
dir(...args) {
vm.emit('console.dir', ...Decontextify.arguments(args));
return null;
},
time: () => {},
timeEnd: () => {},
trace(...args) {
vm.emit('console.trace', ...Decontextify.arguments(args));
return null;
}
};
}
All you need to do to listen to these events is to bind an event listener on the vm you've created:
// Create a new sandbox VM for this request
const vm = new NodeVM( {
console: 'redirect',
require: {
external: ['request']
}
});
vm.on('console.log', (data) => {
console.log(`VM stdout: ${data}`);
});
Likewise, you can bind to console.log, console.info, console.warn, console.error, console.dir, and console.trace. Hopefully this will save someone else some time.
Using this exact code for my nodeJS file on my Intel Edison referenced from
http://cylonjs.com/documentation/drivers/maxbotix/
The only difference is in the line edison: { adaptor: 'intel-iot' }
var Cylon = require('cylon');
Cylon.robot({
connections: {
edison: { adaptor: 'intel-iot' }
},
devices: {
maxbotix: { driver: 'maxbotix' }
},
work: function(my) {
every((1).seconds(), function() {
my.maxbotix.range(function(data) {
console.log("range: " + data);
});
});
}
}).start();
I've done a npm install so all my modules are installed and doublechecked my wiring to ensure my sensor is connected properly.
Whenever I run the app I get the error
Error: No pin specified for Maxbotix. Cannot proceed
Any arduino, nodejs or cyclonjs experts able to suggest what is missing or wrong?
You need to specify the analog pin the maxbotix is connected to in the device definition, like this:
var Cylon = require('cylon');
Cylon.robot({
connections: {
edison: { adaptor: 'intel-iot' }
},
// should be one of the analog pins from 0 to 5
// if using the arduino shield.
devices: {
maxbotix: { driver: 'maxbotix', pin: '1' }
},
work: function(my) {
every((1).seconds(), function() {
my.maxbotix.range(function(data) {
console.log("range: " + data);
});
});
}
}).start();