zabsalahid / serialport-gsm

SerialPort-GSM is a simplified plugin for communicating with gsm modems. (Primarily for sms) (Focused in PDU mode)
MIT License
90 stars 47 forks source link

getNetworkSignal() does not return any data #20

Closed zabsalahid closed 5 years ago

zabsalahid commented 5 years ago

Hey @karianpour !

Upon checking, getNetworkSignal does not return and had resulted to timeout.

item.logic = (newpart) => {
      let resultData;
      if (newpart.substr(0, 5) == '+CSQ:') {
        let signal = newpart.split(' ')
        signal = signal[1].split(',')
        resultData = {
          status: 'success',
          request: 'getNetworkSignal',
          data: { 'signalQuality': signal[0] }
        }
      }
      if ((newpart == ">" || newpart == "> " || newpart == 'OK') && resultData) {
        return {
          resultData,
          returnResult: true,
        }
      } else if (newpart == "ERROR") {
        return {
          resultData: {
            status: 'ERROR',
            request: 'getNetworkSignal',
            data: 'Cannot Get Signal'
          },
          returnResult: true,
        }
      }
    }

resultData is always set to undefined every time item.logis() is called, will not enter

((newpart == ">" || newpart == "> " || newpart == 'OK') && resultData)

part.

image

karianpour commented 5 years ago

I see the bug, the variable should be defined out side of the function to let the closure hold the data. Tonight I will fix it.

karianpour commented 5 years ago

@zabsalahid I made a pull request for it.