# Why my files are empty every time I restast the RCM4300???

**URL:** <https://forums.digi.com/t/why-my-files-are-empty-every-time-i-restast-the-rcm4300/16657>\
**Category:** Rabbit\
**Tags:** sdcard, fat, rcm4300, ftp, sspec\
**Created:** [April 26, 2016, 12:20pm UTC](https://forums.digi.com/t/why-my-files-are-empty-every-time-i-restast-the-rcm4300/16657 "2016-04-26T12:20:38Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andreu](https://avatars.discourse-cdn.com/v4/letter/a/ce73a5/32.png) [@Andreu](https://forums.digi.com/u/Andreu)\
**Post date:** [April 26, 2016, 12:20pm UTC](https://forums.digi.com/t/why-my-files-are-empty-every-time-i-restast-the-rcm4300/16657/1 "2016-04-26T12:20:38Z")

</div>

Dear all,

My application is running on a RCM4300. The program is intended to acquire data and store them in the on-board SD Card, additionally there’s an FTP Server in charge to provide access to the stored data. The FTP Server is running as a Costate.

In principle it works fine. The problem is that after restarting the module the data in the files desappear. The files are there but not the data.

Any ideas?

---

<div class="post-metadata">

**Author:** ![petermcs](https://avatars.discourse-cdn.com/v4/letter/p/4af34b/32.png) [@petermcs](https://forums.digi.com/u/petermcs)\
**Post date:** [April 26, 2016, 4:50pm UTC](https://forums.digi.com/t/why-my-files-are-empty-every-time-i-restast-the-rcm4300/16657/2 "2016-04-26T16:50:35Z")

</div>

Do you have a battery connected for the RTC and SRAM? The FAT file system needs a block of battery backed RAM to work correctly over power cycles.

Regards,  
Peter

---

<div class="post-metadata">

**Author:** ![Andreu](https://avatars.discourse-cdn.com/v4/letter/a/ce73a5/32.png) [@Andreu](https://forums.digi.com/u/Andreu)\
**Post date:** [April 27, 2016, 8:10am UTC](https://forums.digi.com/t/why-my-files-are-empty-every-time-i-restast-the-rcm4300/16657/3 "2016-04-27T08:10:24Z")

</div>

Yes I have a battery, but I didn’t know such effect. I will check the voltage through the power up cycle.

The other possibility I’m thinking of is related to some sort of uncompatibility between the FAT\_file and the SSPEC library functions. If the battery back up works fine I will be back with a more detailed Explanation on the Problem.

Thanks for the help  
Andreu

---

<div class="post-metadata">

**Author:** ![Andreu](https://avatars.discourse-cdn.com/v4/letter/a/ce73a5/32.png) [@Andreu](https://forums.digi.com/u/Andreu)\
**Post date:** [April 27, 2016, 8:11am UTC](https://forums.digi.com/t/why-my-files-are-empty-every-time-i-restast-the-rcm4300/16657/4 "2016-04-27T08:11:32Z")

</div>

I already checked the back up battery. It Looks to be Ok. However, is a Kind of noisy. It shows spykes of about 1 Vpp. I will Change the battery anyway.

Here a little piece of my code. Please let me know if you see anything weird:

in my custom json library:

/\* START FUNCTION DESCRIPTION \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
json\_addValueNumber  
SYNTAX: int json\_addValueNumber(FATfile \*file, void \*value, int type, const far char \*after)

KEYWORDS: json

DESCRIPTION: function to write numerical values into a json formatted file.

END DESCRIPTION \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*_/  
int json\_addValueNumber(FATfile file, void value, int type, const far char after)  
{  
auto int rc=0;  
switch(type)  
{  
case UCHR:  
sprintf(buf, “%c\0”,(unsigned char)value);  
break;  
case UINT:  
sprintf(buf, “%u\0”,(unsigned int_)value);  
break;  
case INT:  
sprintf(buf, “%d\0”,_(int_)value);  
break;  
case USINT:  
sprintf(buf, “%u\0”,_(unsigned short_) value);  
break;  
case FLOAT:  
sprintf(buf, “%.2f\0”,_(float_)value);  
break;  
default:  
break;  
}  
if(after!=NULL) f\_strcat(buf, after);  
rc=fat\_xWrite(file, (long)buf, strlen(buf));  
return rc;  
}

in the main program:

// Mount SD card

fCheckError(sspec\_automount(SSPEC\_MOUNT\_ANY, NULL, NULL, NULL),FailedFunct017,“!=”,0);

while(1)  
{  
loophead();  
costate 1 //…  
costate 2 //…  
costate // data logging  
{  
waitfor(DelaySec(DataReg\_T));  
if (Exp\_running == 1)  
{  
sprintf(s,DataTmp);  
fCheckError(fat\_Open(fat\_part\_mounted[0],s,FAT\_FILE,FAT\_OPEN,&DataTemp\_file,&prealloc),FailedFunct041,“!=”,0);  
fat\_Seek(&DataTemp\_file, -6, SEEK\_END);  
fCheckError(fat\_Write(&DataTemp\_file,“,  
“,3),FailedFunct032,”!=”,3);  
sprintf(s,“#%d\0”,meascount);  
json\_addName(&DataTemp\_file,NULL,s,“[”);  
json\_addValueNumber(&DataTemp\_file,(unsigned int\*)&Stirring,FLOAT,“,”);  
json\_addValueNumber(&DataTemp\_file,(unsigned int\*)&InternalTemp,FLOAT,“,”);  
json\_addValueNumber(&DataTemp\_file,(unsigned int\*)&FeedTemp,FLOAT,“,”);  
json\_addValueNumber(&DataTemp\_file,(unsigned int\*)&HumidifierTemp,FLOAT,“,”);  
json\_addValueNumber(&DataTemp\_file,(unsigned int\*)&MBRTemp,FLOAT,“,”);  
json\_addValueNumber(&DataTemp\_file,(unsigned int\*)&DO,FLOAT,“,”);  
json\_addValueNumber(&DataTemp\_file,(unsigned int\*)&pHbis,FLOAT,“,”);  
json\_addValueNumber(&DataTemp\_file,(unsigned int\*)&P1,FLOAT,“,”);  
json\_addValueNumber(&DataTemp\_file,(unsigned int\*)&P2,FLOAT,“,”);  
json\_addValueNumber(&DataTemp\_file,(unsigned int\*)&P3,FLOAT,“,”);  
json\_addValueNumber(&DataTemp\_file,(unsigned int\*)&Flow1,FLOAT,“,”);  
json\_addValueNumber(&DataTemp\_file,(unsigned int\*)&Flow2,FLOAT,“,”);  
json\_addValueNumber(&DataTemp\_file,(unsigned int\*)&Flow3,FLOAT,“,”);  
json\_addValueNumber(&DataTemp\_file,(unsigned int\*)&ElapsedTime,FLOAT,“]”);  
fCheckError(fat\_Write(&DataTemp\_file,"  
}  
}“,6),FailedFunct032,”!=“,6);  
fCheckError(fat\_Close(&DataTemp\_file),FailedFunct042,”!=",0);  
meascount++;  
}  
}  
}

Somewhere else before powering down:

// Unmount all of the mounted FAT partitions & devices before exit  
for (i = 0; i \< num\_fat\_devices \* FAT\_MAX\_PARTITIONS;i += FAT\_MAX\_PARTITIONS)  
{  
if (fat\_part\_mounted[i]) fat\_UnmountDevice(fat\_part\_mounted[i]-\>dev);  
}

---

<div class="post-metadata">

**Author:** ![cpigilam](https://avatars.discourse-cdn.com/v4/letter/c/fbc32d/32.png) [@cpigilam](https://forums.digi.com/u/cpigilam)\
**Post date:** [May 5, 2016, 4:58am UTC](https://forums.digi.com/t/why-my-files-are-empty-every-time-i-restast-the-rcm4300/16657/5 "2016-05-05T04:58:33Z")

</div>

Hello, There is a sample application FTP\_FAT.C provided by Digi under C:\DCRABBIT\_10.72\Samples cpip\ftp

Test the RCM4300 with this sample app.
