Search code examples
cmsp430contiki

C - error: unknown type name ‘FILE’ on Zolertia z1 motes


My z1 mote acts as the base station and it is connected directly to the gateway (pc). I wanted to save the data coming on a text file using this code in the unicast-receiver.c:

//after printing on the screen then store
FILE *f = fopen("clients.txt", "wb");
fwrite(data, sizeof(char), sizeof(data), f);
fclose(f); 

but I am getting this error:

unicast-receiver.c: In function ‘receiver’:
unicast-receiver.c:49:1: error: unknown type name ‘FILE’

Eventhough stdio.h is included. Anyone faced the same kind of error before? How do I fix it? If there's no way to do this through z1 motes, then is any other way to store the data?

Here are the includes in the program

#include "contiki.h"
#include "lib/random.h"
#include "sys/ctimer.h"
#include "sys/etimer.h"
#include "net/ip/uip.h"
#include "net/ipv6/uip-ds6.h"
#include "net/ip/uip-debug.h"

#include "simple-udp.h"
#include "servreg-hack.h"

#include "net/rpl/rpl.h"

#include "dev/cc2420/cc2420.h"

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

Solution

  • msp430 is a very hardware-limited platform, so the complete C standard library functionality is not supported. In particular there is no hard disk or even SD card on typical msp430 platforms, so there's also little need to have a filesystem-related routines in software.

    If you look at msp430-libc source code, you can clearly see that it only support for the printf function family.

    It's possible to use the xmem interface to store data on the onboard flash. The interface is defined in contiki/core/dev/xmem.h. Using it is simple: first erase a whole sector, then you can write in that sector. Call xmem_erase with a flash address as an argument (any address in the sector you want to erase), then call xmem_write passing a buffer which to write and a flash address (start offset) where write to. Flash addresses typically start from zero.

    It's also possible to use the Coffee, Contiki file system.