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

你说的曾经没有我的故事 提交于 2021-01-28 11:57:28

问题


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 are the AT commands I am using:

AT+FSCREATE=tts2.amr 
AT+FSWRITE=tts2.amr,0,5030,10 
AT+FSLS=C:\\

I made a nodeJS program to do the job, but I am openned to any other language that works on linux.

  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); });

In case you were wondering I've already seen this post which helped neither the OP nor me.

I've also 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.

UPDATE:


From the docs:

Here they have mentionned a data parameter for reading operation, so you can have the read data. But for write operation there is no such thing, so I'm pretty much confused.


回答1:


I think the post you mentioned is right. In App note, page 13, there is also an example.

So in your program, suppose you have a local file ~/tts0.amr with size 5030 bytes, (tts2.amr is the file name inside modem)

  1. read file ~/tts0.amr to memeory variable, like amr_data for exam;
  2. send "AT+FSWRITE=tts2.amr,0,5030,10" to modem, waiting for ">" instead of "OK";
  3. write amr_data to modem, just like the step above;
  4. if the size matching, modem shall return "OK" now.



回答2:


By using @ximingr's answer i came up with this code which works fine.

var fs= require("fs");
let serialportgsm  = require('serialport-gsm');
let modem = serialportgsm.Modem();
let serialport = serialportgsm.serialport;


serialportgsm .list((err, result) => {
    // console.log(result);
})

let options = {
    baudRate: 115200,
    dataBits: 8,
    stopBits: 1,
    parity: 'none',
    rtscts: false,
    xon: false,
    xoff: false,
    xany: false,
    autoDeleteOnReceive: true,
    enableConcatenation: true,
    incomingCallIndication: true,
    incomingSMSIndication: true,
    pin: '',
    customInitCommand: '',
    logger: console
}

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);
                });
             });
            }
        });     
    });

});


来源:https://stackoverflow.com/questions/56914146/sim800c-gsm-at-command-how-to-upload-amr-audio-file-programmatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!