Go Down

Topic: Writing to SARA-U201 file system (Read 410 times) previous topic - next topic

MohitB

Jun 15, 2018, 12:08 pm Last Edit: Jun 15, 2018, 12:10 pm by MohitB
I am working with MKR GSM 1400 to upload file to FTP server from Sdcard interfaced to the board. I read the data sheet of GSM modem SARA-U201 and found that first you have to create a file in U201 file system and then transfer to FTP server. I am able to create and write to the file system of U201 but it takes around 7-8 minutes to copy data from SDCARD to gsm modem file system for 1MB file. Can anyone tell me faster way to copy data.

Code: [Select]
#include <SPI.h>
#include <SD.h>

unsigned long baud = 19200;

bool debug = 1;

char* file_name1 = "REC00000.wav";
File File1;
int file_size_sd;
long int bytes;   

void setup()
{
  pinMode(2, OUTPUT);

  while (!Serial)
  {
        ; // wait for serial port to connect. Needed for native USB port only
  }
 
  pinMode(GSM_RESETN, OUTPUT);
  digitalWrite(GSM_RESETN, HIGH);
  delay(100);
  digitalWrite(GSM_RESETN, LOW);
  delay(5000);

  Serial.begin(baud);
  SerialGSM.begin(baud);

  if (!SD.begin(2)) {
    Serial.println("Initialization failed!");
    return;
    while(true);
  }else {
    Serial.println("Initialization done.");
  }

  File1 = SD.open(file_name1);
  if (File1) {
    Serial.println("Opening the file: " + String(file_name1) + " done.");
  }else {
    Serial.println("Error opening " + String(file_name1));
    while(true);
  }

   if (File1) {
     int i = 0;
     file_size_sd = File1.size();
     Serial.println(file_size_sd);

     sendATcommand("AT+ULSTFILE=","OK", 1000);                   //List all the files in the file system

     sendATcommand("AT+ULSTFILE=1","OK", 1000);                   //get free space in file system
   
     sendATcommand("AT+UDWNFILE=\"sound.wav\",2000000","OK", 1000);     //create a file in gsm file system

     Serial.println("Copy file data");   
     
     while (File1.available()>0) {

      SerialGSM.write(File1.read());
     }
     delay(2000);
     
     Serial.println("Done Writing");

   File1.close();
   }
}

void loop()
{
 
}

unsigned char sendATcommand(char* ATcommand, char* expected_answer1, unsigned int timeout) {
  unsigned char x = 0;
  unsigned char answer = 0;
  char response[100];
  unsigned long previous;
  memset(response, '\0', 100);
  delay(100);
  while( SerialGSM.available() > 0) SerialGSM.read();
  SerialGSM.println(ATcommand);
  x = 0;
  previous = millis();
  do{
    if(SerialGSM.available() != 0){   
      response[x] = SerialGSM.read();
      x++;
      if (strstr(response, expected_answer1) != NULL) {
        answer = 1;
      }
    }
  } while((answer == 0) && ((millis() - previous) < timeout));
  if (debug) {Serial.println(response);}
  return answer;
}

smgs

In the Serial Passthrough Example sketch the Baud rate is set to "115200", any reason your Baud rate is set to only "19200"?

Have you tried just creating a simple text file instead of a .wav file? I'd imagine that would cut your copy time down significantly too.

Very cool project by the way.

MohitB

Changing the baud rate worked, now i am able to write it faster than before. Is 115200 highest baud rate that can be used with this board?

Go Up