Could someone help me with the following?
I’m trying to write temperature reading to an output file on my mbed device. It creates the output file but only ever puts in one value. Should be updating reading every 10 secs. I have tried various functions like “a” “a+” to see but only ever one value in my output file. attached below is code
#include “mbed.h” #include “LM75B.h” #include “C12832.h” #include
using std::string;
C12832 lcd(p5, p7, p6, p8, p11);
LM75B sensor(p28,p27);
Serial pc(USBTX,USBRX);
LocalFileSystem local(“local”); // Create the local filesystem under the name “local”
int count;
float temperature;
void writeValue (float temperature){
FILE *fp = fopen(“/local/out.txt”, “a+”); // Open “out.txt” on the local file system for writing
//if (!fp) fp = fopen(“/local/out.txt”, “w”);
fprintf(fp,“%f\r\n”,temperature);
//fputs(“f\r\n”,fp);
fclose(fp);
printf(“New Entry Added\r\n”);
return;
}
int main ()
{
//count = 0;
//Try to open the LM75B
while (1) {
writeValue((float)sensor);
displayValues((float)sensor);
readFile();
printf(“About to Wait 10 seconds\r\n”);
wait(10.0);
count++;
}
//printf(“We are done!”);
}
please be so kind and use formatting (simply add ``` before and after your code) for better presentation of your code.
I not see anything wrong with your implementation of the writeValue function. I use it similar but not with LocalFileSystem.
However, your code seems be not complete. The readFile is not there, so I not see how you verified your result.
Also your variable temperature is declared as global and also as input parameter of your function. That can lead to a collision or confusion, I think.
Attached is complete code I have tried.
I can see on Terra Term the read comments.
I can see Temp displayed on LCD of mbed and reading every 10 secs with blink of led light.
Problem is Out txt file. Don’t see values in that. Have use “a” “a+” etc . Was doing more research on line etc to see if I could fine any additional info.
This is a student related project. Any help you can provide would be greatly appreciated.
int main ()
{
count = 0;
//Try to open the LM75B
while (1) {
writeValue((float)sensor);
displayValues((float)sensor);
readFile();
printf(“About to Wait 10 seconds\r\n”);
wait(10.0);
count++;
}
//printf(“We are done!”);
}