This guide explains how to send GPRS commands to a Teltonika device using the Teltonika SDK. GPRS commands allow you to remotely interact with a device, for example to:
To send commands, your server must:
Below is a complete example showing how to:
import {
TeltonikaDataCodec,
TeltonikaGPRSCodec,
TeltonikaTCPServer
} from '@groupe-savoy/teltonika-sdk';
const server = new TeltonikaTCPServer({
codecs: {
data: TeltonikaDataCodec.Codec8e,
gprs: TeltonikaGPRSCodec.Codec12,
},
timeout: 60000,
});
// Triggered when the device is initialized and ready
server.on('init', (device) => {
// Send commands directly from the device instance
setTimeout(() => device.sendCommand('getver'), 1000);
setTimeout(() => device.sendCommand('getinfo'), 2000);
// The server can also send a command using the device IMEI
setTimeout(() => {
server.sendCommand(device.imei!, 'cpureset');
}, 10000);
});
// Triggered when the device sends a command response
server.on('response', (device, data) => {
console.log('Response from device:', device.imei);
console.log(data.records);
});
// Handle errors
server.on('error', (device, error) => {
console.error('Error:', device?.imei, error);
});
// Start listening for device connections
server.listen(4041, '0.0.0.0');
device.sendCommand('getver');
Use this approach when you already have access to the connected device object.
server.sendCommand('123456789012345', 'getinfo');
This is useful when:
Command responses are emitted through the response event:
server.on('response', (device, data) => {
console.log(data.records);
});
data.records contains the parsed response payloadSome commonly used commands include:
getver – Get firmware versiongetinfo – Get device informationcpureset – Restart the deviceAvailable commands depend on the device model and firmware version. Always refer to the official Teltonika documentation.
response eventtimeout values appropriate for your network conditionsYou can now control Teltonika devices remotely using GPRS commands.