FOR TIPS, gUIDES & TUTORIALS

subscribe to our Youtube

GO TO YOUTUBE

4167 questions

4739 answers

3460 comments

0 members

We are migrating to our new platform at https://community.teltonika.lt. Moving forward, you can continue discussions on this new platform. This current platform will be temporarily maintained for reference purposes.
0 votes
598 views
in Vehicle tracking by anonymous
Code
 

import net from "net";

import { ProtocolParser, parseIMEI, Data, GPRS  } from "complete-teltonika-parser";

const server = net.createServer();

server.on("connection", (socket) => {

    console.log('connection..')

    console.log('setEncoding=hex')

    socket.setEncoding("hex");

    socket.on("data", (packet) => {

        console.log('data Event...')

        var buffer = Buffer.from(packet);

        //console.log(bufferPacket)

        let parsed = new ProtocolParser(buffer.data)

        // if (parsed.CodecType == "data sending") {

        //     let data = parsed.Content as Data

        //     data.AVL_Datas.map(row=>{

        //       console.log('row=>',row)

        //     })

        //     //console.log('data====>',data.AVL_Datas[0].IOelement)

        //     //console.log('data====>',data.AVL_Datas[0])

        // } else {

        //     let gprs = parsed.Content as GPRS

        //     console.log('gprs====>',gprs)

        // }

      //socket.write("\x01");

      //console.log(data);

    });

    socket.on("close",()=>{console.log('close Event...')});

    socket.on("error",(err)=>{ console.log('error Event ErrorMessage==>',err.message); });

});

server.listen(786, () => {

    console.log(`Server Listning TCP Poket from Iot Device..`);

});

Output

TSError: ⨯ Unable to compile TypeScript:

src/index.ts:21:41 - error TS2345: Argument of type 'Buffer' is not assignable to parameter of type 'string'.

21         let parsed = new ProtocolParser(packet)

                                           ~~~~~~

1 Answer

0 votes
by anonymous

Hi 

Good day!

We would like to analyze your issue. Please contact your sales manager.

If you don't have any contact with our Sales managers, please contact with them on our official website https://teltonika-gps.com/ and click on the "Contact Us" button. When you will click, please fill out the form and submit it. Note: as a topic, please choose "Vehicle telematics". Or you can send an e-mail with the description of your situation to info@teltonika.lt

Best Regards,

Maynard C.