Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing Characters in a message (PDU) when sending over 160 characters #136

Open
amnon18 opened this issue Jan 31, 2024 · 9 comments
Open

Comments

@amnon18
Copy link

amnon18 commented Jan 31, 2024

Hello Everyone,

I started using this library about 2 weeks ago and it's amazing how it works well, except for the long messages. It seems that for any message over 160 characters long I lose the first character of the next block. If I add a space in my text to send, the space will be removed when sent. Is there a way to find out why and where this is done so we can fix it?

Thank you in advance

Ronen

@JulianWowra
Copy link

That sounds like a problem with the dependency node-pdu

@amnon18
Copy link
Author

amnon18 commented Feb 1, 2024 via email

@JulianWowra
Copy link

Please provide a code to reproduce the issue and I will have a look.

Thank you

@justlester
Copy link

Hi Julian, I’ve solved by adding a % sign every 132 characters. I know it’s not the best but it works. Let me know if you figure this out eventually. Thank you Ronen Get Outlook for iOShttps://aka.ms/o0ukef

________________________________ From: Julian W. @.> Sent: Thursday, February 1, 2024 8:17:59 AM To: zabsalahid/serialport-gsm @.> Cc: Ronen Tadmor @.>; Author @.> Subject: Re: [zabsalahid/serialport-gsm] Missing Characters in a message (PDU) when sending over 160 characters (Issue #136) That sounds like a problem with the dependency node-pduhttps://github.com/jackkum/node-pdu/issues/new — Reply to this email directly, view it on GitHub<#136 (comment)>, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AIBT24XV4FOJEFSNLKJ5VJDYROIYPAVCNFSM6AAAAABCTSPELGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSMRRGMYDKNZQGU. You are receiving this because you authored the thread.Message ID: @.***>

How did you implement the %? Can you provide the workaround code?

@blackchineykh
Copy link

Can you help here as well? I am having the issue of the missing characters. I noticed that the node-pdu dependecy isnt updated on this project to the latest as well

@blackchineykh
Copy link

blackchineykh commented Jun 26, 2024

Please provide a code to reproduce the issue and I will have a look.

Thank you

const number = "19991234567";
const message = "Hi Friend, we found 73 new results for your Search criteria. View these new matches at https://mywebsiteonlineresults.com/profile/search-results.html?id=12345&passw=rilkb806s1h"

let submit = pdu.Submit()
submit.setAddress(number)
submit.setData(message)

let parts = submit.getParts()

console.log(`Original long message: `, message)

let result = "";
for (let i = 0; i < parts.length; i++) {
console.log(`Encoded message part ${i} is: `, parts[i].toString())

const decodedMessage = pdu.parse(parts[i].toString());
console.log(`Decoded message part ${i} is: `, decodedMessage.getData().getText())
result += decodedMessage.getData().getText();
}

console.log(`Resulting long message: `, result)

Output:

Original long message:  Hi Friend, we found 73 new results for your Search criteria. View these new matches at https://mywebsiteonlineresults.com/profile/search-results.html?id=12345&passw=rilkb806s1h
Encoded message part 0 is:  0041000B919199214365F700008C060804ACC60201C834C8284F97DD6416E85E0699DF753719749B81DCE53B485E9ED7D9F439C8FC9683F2EFBA1C342D87E56334682C4FD3CBF274D805B2A6CB77101D5D9E9741EEF21DD40ED3C7E8F21C14A683D0743A7CAE7BBDDAF97B593C4FD3CB6F373BED2ECBCBF33A9B3E778DDFED175CFE36A7D9E5D7BC1C06
Decoded message part 0 is:  Hi Friend, we found 73 new results for your Search criteria. View these new matches at https://mywebsiteonlineresults.com/profile/se
Encoded message part 1 is:  0041000B919199214365F7000032060804ACC60202F231BA252FCFEB6CFADC85A6B7D9BF34B91793CD6835133C3C9FDF7BF2347B2DC6C16CF3181A
Decoded message part 1 is:  rch-results.html?id=12345&passw=rilkb806s1
Resulting long message:  Hi Friend, we found 73 new results for your Search criteria. View these new matches at https://mywebsiteonlineresults.com/profile/serch-results.html?id=12345&passw=rilkb806s1

I know its the depency of node-pdu that seems to be the issue here but i see that its also outdated in this project.

@justlester
Copy link

Hi, is there any update or possible work around on this?

@JulianWowra
Copy link

Here is the issue in the node-pdu dependency. Unfortunately, I have not yet found a solution to the problem. Please feel free to help

@justlester
Copy link

justlester commented Jul 25, 2024

Since this is a node-pdu issue on parsing the message.
I tried to recreate the sendSMS method and used a package called node-sms-pdu which is a SMS-SUBMIT PDU (Packet Data Unit) generator.

I was able to work with it with messages longer than 160 characters.
Flash messages will not work on this.

Let me know if this works for you.

   const smsPdu = require('node-sms-pdu');
   
   //still use the serialport-gsm to open the port modem, initialize modem and set modem mode to PDU 
  //before using the  sendSMS2 method

  const sendSMS2 = function(number, message, callback) {
    try {
      if (number && message) {
        let messageID = modem.makeId(25);

        //use node-sms-pdu
        let parts = smsPdu.generateSubmit(number,message);

        for (let i = 0; i < parts.length; i++) {
          modem.executeCommand(`AT+CMGS=${(parts[i].hex.length / 2) - 1}`, (data) => {}, false, 100)
          modem.executeCommand(`${parts[i].hex}` + '\x1a', function(data, error) {
            if (!data) {
              // console.log('no data for sms send', {data, error})
              return
            }
            let channel
            if (data.status === 'fail') {
              channel = 'onMessageSendingFailed'
            } else {
              channel = 'onMessageSent'
            }

            if (i === parts.length - 1) {
              const result = {
                status: data.status,
                request: data.request,
                data: {
                  messageId: data.data.messageId,
                  message: data.data.message,
                  recipient: data.data.recipient,
                  response: data.data.response
                }
              }
              modem.emit(channel, result)
              callback(result)
            }
          }, false, 30000, messageID, message, number, true)
        }
        // if it is called with promise (the promise callback has 2 args)
        // it is better not to callback until the message is sent or failed,
        // the call back send above inside the call back
        if (callback.length === 1) {
          callback({
            status: 'success',
            request: 'sendSMS',
            data: {
              messageId: messageID,
              response: 'Successfully Sent to Message Queue'
            }
          })
        }

      } else {
        callback({
          status: 'Error',
          request: 'sendSMS',
          error: 'Missing Arguments'
        })
      }
    } catch (error) {
      callback({
        status: 'Error',
        request: 'sendSMS',
        error: error
      })
    }
  }
    

to use the method

  sendSMS2(number, message, (result, error) => {
        console.log('sendSMS', { result, error });
  });  

Explaination

I just replaced the node-pdu to generate the parts.

from:

 //use node-pdu
        let submit = pdu.Submit()
        submit.setAddress(number)
        submit.setData(message)
        if (alert) {
          submit.getDcs().setUseMessageClass(alert)
        }
        let parts = submit.getParts()

to

 //use node-sms-pdu
        let parts = smsPdu.generateSubmit(number,message);

and update the executeCommands in the loop.

from:

   modem.executeCommand(`AT+CMGS=${(parts[i].toString().length / 2) - 1}`, (data) => {}, false, 100)
   modem.executeCommand(`${parts[i].toString()}` + '\x1a', function(data, error) {
    //callback process here
   }, false, 30000, messageID, message, number, true)

to:

   modem.executeCommand(`AT+CMGS=${(parts[i].hex.length / 2) - 1}`, (data) => {}, false, 100)
   modem.executeCommand(`${parts[i].hex}` + '\x1a', function(data, error) {
              //callback process here
   }, false, 30000, messageID, message, number, true)

Documentation of the node-sms-pdu can be found here: https://www.npmjs.com/package/node-sms-pdu

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants