Bridge broken after trying to read a file
i'm using yun sd "embedded" in filesystem using yundiskspander. have created file /root/users
a program reads file using function readuser.
the function works first time called, second time reports error
so, function works in first call, in second 1 seems when executes if(usersfile.available()==0) the bridge crash.
i have power cycle yun because after can't connect concole.
the ethernet connection running, can connect yun using ssh, , can reprogram (and bridge starts again)
i can't find why.
code: [select]
root@arduinoyun:~# cat users
4442048:fperal
4438376:test
3333333:bogus
root@arduinoyun:~#
a program reads file using function readuser.
code: [select]
#include <fileio.h>
#include <bridge.h>
int readuser(file, char *tag, char *username);
void setup()
{
bridge.begin(); //start communication linino
console.begin(); //start communication ethernet console (300bps)
while (!console); //wait until console ready
console.println("arduino starting......");
}
void loop()
{
char tag[14];
int index=0;
int i;
char rfid[10],user[25];
//create objets usersfile, linked users in linino, open reading
file usersfile=filesystem.open("/root/users",file_read);
console.println("start reading user file");
while(readuser(usersfile,rfid, user)==0)
{
console.print("username=");
console.println(user);
console.print("tag=");
console.println(rfid);
}
console.println("finish reading user file");
delay(10000);
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////
// readuser
//
// reads linino file next tag id
// returns tagid in string format @ tag , username in string format @ username
// returns 0 if went ok , >0 if there error:
// 1 -> error reading file /root/users
// 2 -> error: /root/users may empty?
int readuser(file usersfile, char *tag, char *username)
{
static int counter=0;
counter++;
console.print("call num ");
console.print(counter);
console.println(" readuser");
if(usersfile==0)
{
console.println("error reading file /root/users ");
return 1;
}
console.print("usersfile=");console.println(usersfile);
if(usersfile.available()==0)
{
console.println("error: /root/users may empty?");
return 2; //no data found. maybe eof?
}
console.println("usersfile.available>0");
char data[25]="xx";
int i=0;
console.println("start reading file "); //
while(usersfile.available()>0 && data[i]!='\n') //read file until eof or lf found
{
data[i]=usersfile.read();
console.print(data[i]);
if(data[i]!='\n') i++; //next char until lf found
}
console.println(" --> line completed ");
i=0;
do //read tag, until : found
{
tag[i]=data[i];
} while(data[++i]!=':');
tag[i++]='\0'; //add string terminator
int n=0;
do //read username, until lf found
{
username[n++]=data[i];
} while(data[++i]!='\n');
username[n]='\0'; //add end of string
console.print("line read users: ");
console.println(data);
return 0; //all went ok
}
the function works first time called, second time reports error
code: [select]
start reading user file
call num 1 readuser
usersfile=1
usersfile.available>0
start reading file
4442048:fperal
--> line completed
line read users: 4442048:fperal
username=fperal
tag=4442048
call num 2 readuser
usersfile=1
connection closed foreign host
so, function works in first call, in second 1 seems when executes if(usersfile.available()==0) the bridge crash.
i have power cycle yun because after can't connect concole.
the ethernet connection running, can connect yun using ssh, , can reprogram (and bridge starts again)
i can't find why.
Arduino Forum > Products > Arduino Yún (Moderator: fabioc84) > Bridge broken after trying to read a file
arduino
Comments
Post a Comment