
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
gr-device-init
Advanced tools
version 1.2.0
Server should use websocket transports
Of course, for first time user 'testtoken' to connect to socket
I did this to control linux-based robots with Raspberry Pi or Banana pi.
Also, It can work on Windows-based devices.
added 'this.robotObject.updateState' to update state for robotObject more useful
- We have deployed socket server
- Should just create connections for main and robot (or client/user and robot).
- Don't need to think about logic on server
- RobotController has several controllers and update his state by time.
This library provides simple controller and connection to connect to the GRobotics server - this server has some methods to controll devices using socket.
It is a device and user's part.
You can see examples in 'example' folder.
At first, install npm package:
run npm i gr-device-init
const { User, newGroboticsClientConnection } = require("gr-device-init");
Create new user that should be pass into connection
const user = new User({
id: 'USER_ID',
setUserStatus(st) {
console.log('user accepted', st);
},
robotMessageHandler(state) {
console.log('state', state);
},
deviceMessageHandler(userId, msg) {
console.log('received from device', msg);
}
});
Now we can create connection with our user on this robot. Also, robot should get access to this user.
const connection = newGroboticsClientConnection(user, 'https://grobotics-socket-server.herokuapp.com/', 'testtoken');
Before send commands to robot, we should init user
connection.initUser('MY_ROBOT_ID');
Also, user can has a few robots
So, now we are possible to send command!
connection.send('MY_ROBOT_ID', 'ROBOT_DEVICE_ID', 'my message')
At first, let's create robot controller
const {
createRobotController,
DeviceController,
newGroboticsConnection,
} = require("gr-device-init");
const robotController = createRobotController(robotObject, "MY_ROBOT_ID");
Where robotObject is something to work with inner state as middleware, for example:
const robotObject = {
init() {
console.log("init robots");
},
validate() {
// This method needs to validate command to robot. Just return true if does not need.
return true;
},
initUser() {
console.log("initUser");
},
serverConnected() {
console.log("serverConnected");
},
serverDisconnected() {
console.log("serverDisconnected");
},
};
Now create some controller with device
const testDevice = {
id: "TEST_DEVICE",
messagesIdsMap: {
serverConnected: "serverConnected",
serverDisconnected: "serverDisconnected",
initUser: "initUser",
},
initDevice(args) {
console.log("init in testDevice");
},
attachMsgFromDevice(cb) {
let count = 0;
setInterval(() => {
cb(count++)
}, 100);
},
sendMessage(msg) {
console.log("send testDevice", msg);
// here should be validation for message 'initUser'
// just return true or false.
// At this moment, each device should return true to create access for user
},
};
const testController = new DeviceController({
id: "TEST",
device: testDevice,
});
robotController.addController(testController);
robotController.addController(testController1);
robotController.addController(testController2);
....
After adding controllers, we should connect robotController to server, like this:
const connection = newGroboticsConnection(
"SOCKET SERVER URL",
"/api/str/",
"MY_ROBOT_ID",
"testtoken"
);
connection(robotController);
FAQs
provide methods and models to connect to server
We found that gr-device-init demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.