@groupe-savoy/nestjs-teltonika
v0.1.0
Published
A NestJS library for easily integrating Teltonika devices.
Downloads
8
Readme
nestjs-teltonika
A NestJS module for integrating Teltonika telematics devices using the Teltonika SDK. It provides decorators and services to easily handle TCP and TLS connections with Teltonika devices, enabling seamless GPS tracking and IoT integrations.
The module supports several use cases:
- TCP Server: A ready-to-use TCP server for communicating with Teltonika devices
- TLS Server: A secure TLS server for encrypted communications
- Event Handling: Decorators for listening to device events like data reception and initialization
- Command Sending: Utilities for sending GPRS commands to devices
Installation
Install the module via npm:
npm install @groupe-savoy/nestjs-teltonikaUsage
Below is a basic example showing how to use the module. For more advanced examples, see the examples directory.
Setting Up a TCP Server
The following example shows how to create a TCP server to receive data from Teltonika devices. First, configure your AppModule to import the TeltonikaTCPModule:
import { Module } from '@nestjs/common';
import { TeltonikaTCPModule } from '@groupe-savoy/nestjs-teltonika';
@Module({
imports: [
TeltonikaTCPModule.forRoot({
port: 4041,
host: '0.0.0.0',
}),
],
providers: [AppService],
})
export class AppModule {}Then, create an AppService to handle events:
import { Injectable } from '@nestjs/common';
import { OnTeltonikaEvent, TeltonikaTCPService, TeltonikaDevice, TeltonikaCodec8eAVLPacket } from '@groupe-savoy/nestjs-teltonika';
import { Socket } from 'net';
@Injectable()
export class AppService {
constructor(private teltonikaTCPService: TeltonikaTCPService) {}
@OnTeltonikaEvent('init')
onInit(device: TeltonikaDevice<Socket>) {
console.log('Device IMEI:', device.imei);
}
@OnTeltonikaEvent('data')
onData(device: TeltonikaDevice<Socket>, data: TeltonikaCodec8eAVLPacket) {
console.log('Device IMEI:', device.imei);
console.log('Data Packet:', data);
}
}Setting Up a TLS Server
For secure communications, use the TLS module:
import { Module } from '@nestjs/common';
import { TeltonikaTLSModule } from 'nestjs-teltonika';
import fs from 'fs';
@Module({
imports: [
TeltonikaTLSModule.forRoot({
port: 4041,
host: '0.0.0.0',
key: fs.readFileSync('./path/to/server.key'),
cert: fs.readFileSync('./path/to/server.crt'),
}),
],
})
export class AppModule {}Learn More
The online documentation for the underlying Teltonika SDK is the best place to learn how to use the codecs and commands efficiently.
Development
Clone the repository:
git clone https://github.com/Groupe-Savoy/nestjs-teltonika.git
cd nestjs-teltonikaInstall dependencies:
pnpm installRun tests:
pnpm testBuild the library:
pnpm buildLicense
This project is released under the MIT License.
Support
For questions, issues, or feedback, please visit the GitHub Issues page.
Contributing
Contributions are welcome! Please read the CONTRIBUTING guide for more information.
