Pages: [1]   Go Down
Author Topic: Json or parse myself?  (Read 1476 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 39
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Im building a "Login" system with RFID tags and I would like to hear some inputs on what would be the best way to store the userdata.
The system will be built on a Arduino MEGA 2650 with a SD-card reader and a LCD display.
the data that will be held for each user is, RFID(String), Username(String), logins(int), usagesleft(int), lastlogin(date)
and the system should be able to store 1000 users atleast.

First I was thinking of just making a comma separated textfile that i would search in and find what I want. but it seems that its impossible to search for a string, you can only do a search for one caracter, that will make that idea more or less impossible.
Or is there a way?

The other way would be to use the aJson library. with the functionality of that library it seems to be easy to pickout data from my list of users. But I have hurd that the aJson library can only hold 256 lines? is that really true?

Anyone built something similar? how did you approach this problem?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 39
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

On the json problematics, im trying to find some working examples over how to work with this library,
Anyone got a link?

on https://github.com/interactive-matter/aJson they mention that you could fetch a file directly into a aJson object, that would be awesome, but I did not get it to work.. ¨

tried something like this:
(first i open the SDcard, that works fine, and I can read the file normally.. but this does not work at all...

Code:
aJsonObject* jsonObject = aJson.parse(SD.open("students.txt", FILE_WRITE));

error: no matching function for call to 'aJsonClass::parse(File)'


dont know if thats of any importance, but my json will look something like this:

Code:
{
"users": {
"234-234-123-231-566": {
"namn": "Zakarias Persson",
"pass_kvar": 10,
"pass_forb": 34,
"pass_senaste": "2013-02-08"
},
"24-234-123-2323-566": {
"namn": "Anders Anka",
"pass_kvar": 4,
"pass_forb": 44,
"pass_senaste": "2013-02-05"
}
},
"statistik": {
"2013-02-01": {
"betalande": 0,
"gratis": 32
},
"2013-02-05": {
"betalande": 31,
"gratis": 4
},
"2013-02-08": {
"betalande": 22,
"gratis": 8
}
}
}
« Last Edit: September 15, 2013, 03:00:22 pm by Yamat0 » Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 547
Posts: 45993
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
RFID(String), Username(String), logins(int), usagesleft(int), lastlogin(date)
I hope you mean NULL-terminated array of chars (aka string), rather than String.

Quote
but this does not work at all
C and C++ are case sensitive. A File (a class/instance) and a FILE are not the same thing. One (FILE) appears to be supported. The other is not.

Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 39
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Well, depending on how that data is saved it could be a String or a string, that does not realy matter. But i kind of like working with Strings, they are more natural to my brain for some reason:)

the information will be on an SD-card, in  some format that can be used and read.
I need to be able to search in the information to fetch the "right" row in the file, or the right object in a json.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 39
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

C and C++ are case sensitive. A File (a class/instance) and a FILE are not the same thing. One (FILE) appears to be supported. The other is not.

how do I create a FILE instead of a File then?
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 547
Posts: 45993
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
how do I create a FILE instead of a File then?
Install an operating system on the Arduino. Good luck with that.
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 547
Posts: 45993
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
But i kind of like working with Strings, they are more natural to my brain for some reason:)
Must be an age thing. I don't like crutches, and the String class is just that. People were writing extensive text processing applications long before the String class came along. Under the covers, everything that String does is based on NULL terminated arrays of chars.

But, whatever floats your boat. It's your boat, after all.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 39
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

from the examples with Json i read this: (its the basic question about File and FILE)
Quote
Parsing streams

As you can see this will eat up lots of memory. Storing the original string and the JSON object is a bit too much for your Arduino - it will most likely use up all the memory. Therefore it is better to parse streams instead of strings. A stream in C is a FILE* - on Arduino there are some special streams, but later adapters will be provided. So if you for example read from a FILE* stream you can simply call

 aJsonObject* jsonObject = aJson.parse(file);
By that you will not have to store the JSON string in memory.

the question is how he ment this to work?
Anyone who have worked with aJson ?
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 547
Posts: 45993
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
the question is how he ment this to work?
He says how, right here:
Quote
So if you for example read from a FILE* stream you can simply call
Now, given that the Arduino doesn't have an operating system that can proved a FILE pointer, this implies (to me, at least) that you can't use this method.

Now, he also says:
Quote
on Arduino there are some special streams, but later adapters will be provided.
If you want to use a stream directly, I guess you'll have to wait until later.

At the top of the page you linked to, there are comments that the library was updated 11 months ago to use Wiring-style streams. I suspect that that means Arduino-style streams, too, since the concept is the same on both platforms, and there are far more Arduino users than Wiring users.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 39
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If i was to toss the idea of using Json(it seams that none has tried it and none knows how to work with it on an arduino)
the logical choice for my data would be a comma separated textfile, right?

Has anyone built some example with data in such a way, where you can search for a specific line and alter text in the middle of the string? changing values mostly i guess.

If not, I will build it from scratch, but ideas from other peoples codes are nice to start with.. Making the wheel is only fun when none has done it before you:)

Logged

Pages: [1]   Go Up
Jump to: