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

SIM800C GSM AT COMMAND How to upload .amr audio file programmatically #38

Closed Xsmael closed 5 years ago

Xsmael commented 5 years ago

I am desperatly trying to upload some audio file to the internal memory of a SIM800C, so far this is what I've been able to do, but the uploaded file seems void, and doesnt play any sound. But with AT+FSLS=C:\\ I can see the file is there.

Here is what I have tried:

        modem.executeCommand('AT+FSCREATE=tts2.amr',(result) => { log.debug(result); });
        modem.executeCommand('AT+FSWRITE=tts2.amr,0,5030,10',(result) => { log.debug(result); });
        modem.executeCommand('AT+FSLS=C:\\',(result) => { log.debug(result); });

I've seen this post but it doesnt suit to me, because it uses a tool (AmrFile Download.exe) to do the job manually, I need to do it programmatically. I thought if that tool could do it so can I, there must be a way, but have not yet found...

What really bugs me is how is the file located from my computer, and its content read before even loading it. I've kept the audio file tts2.amr in the same directory than the nodejs script since the AT commands shows me no way to specify a path for the source file it only considers the destination, so I've no clue how to do it, and I feel it doesnt work like that.

Xsmael commented 5 years ago

I was finally able to do it, and this is the code, for any one needing it:

modem.open('COM11', options);

modem.on('open', data => {
    modem.initializeModem(function(p) {

        fs.readFile('tts2.amr', function(err,amr_data) {
            if(!err) {
                let fsize= fs.statSync('tts2.amr').size;
                modem.executeCommand('AT+FSCREATE=C:\\User\\tts2.amr',(result) => { log.debug(result); });
                modem.executeCommand('AT+FSWRITE=C:\\User\\tts2.amr,0,'+fsize+',100',(result) => { 
                modem.port.write(amr_data);
                });
             });
            }
        });     
    });

});
travisfimmel743 commented 2 years ago

Hello bro, I need send wav audio over serialport sim800c can you help me for that anny at command can do that like ivr system auto answer

Xsmael commented 1 year ago

What have you already tried ?