LowPowerLab Forum

Hardware support => Moteino => Topic started by: Clemens on January 10, 2015, 02:55:39 PM

Title: How to transfer the content of a (txt-)file via RFMxx lib
Post by: Clemens on January 10, 2015, 02:55:39 PM
I'm logging data in a 5 min interval. The node should run from battery about one year so I try to minimize data transfer to the gateway to once a day to save power.

The logfile looks like this:


date,temp-1a,press,light,temp-2a,temp-2b,moist-out,temp-3,moist-in,s1,s2,s3,s4,s5,s6,s7
2013/06/08 02:05:39,20.9,1011,0,35.31,12,83,29,47,97,133,181,220,356,568,425
2013/06/08 02:10:48,21.2,1011,0,35.25,13,83,29,47,94,170,189,277,393,414,430
2013/06/08 02:15:58,21.3,1011,0,35.25,12,85,29,47,77,122,180,237,281,581,469
2013/06/08 02:20:08,21.5,1011,0,35.31,13,84,29,48,93,151,181,208,253,326,415
2013/06/08 02:25:18,21.7,1011,0,35.31,13,84,29,48,97,141,179,187,209,323,428
2013/06/08 02:30:28,21.8,1011,0,35.25,12,85,28,50,86,124,166,197,328,345,459
2013/06/08 02:35:37,21.9,1011,0,35.25,12,84,28,51,89,127,163,198,312,372,473
2013/06/08 02:40:47,22,1011,0,35.25,12,84,28,51,97,133,153,170,227,340,412
...



1. How to transfer this data stored in a file on the Flash chip via RFMxx lib?
The example files in the lib transferring always only one character. So this is ok for demonstration but it is ineffective for a big file. Is there an example / function were I can put a whole file or at least a big variable as payload and the lib calculates and divides this in optimal packages. And sent this to the gateway. In case this is not a function in the lib. Is there code available that do this?


2. CRC vx. ACK
As I understand it the integrity of a single package is no problem because it is checked via CRC. So for what is ACK? to repeat sending in case a packet was not correct? Or only to check if the node could also receive messages?

3. reduce upload cycles to reduce power?
How can I calculate the battery power I save (or need) for letz say 500KB data. Is this doable or are the circumstances so non-calculateble ?

1. The "All about Moteino" page says "32 KB" in the shop it is "512 KB"
What is the size of the Flash atm, the Moteino page says 32 KB, in the shop I found 512 KB. Btw is there a method to figure out how full the Flash is via lib? So I could check if the chip is 90 % full and now sent the data to the gateway

Is the Flash intended to save data? Or only for wireless progrmming? I noticed that other clones (Anarduino) have 128 Mbit vs 4Mbit on the Moteino.
Title: Re: How to transfer the content of a (txt-)file via RFMxx lib
Post by: TomWS on January 10, 2015, 05:50:07 PM
Quote from: Clemens on January 10, 2015, 02:55:39 PM
I'm logging data in a 5 min interval. The node should run from battery about one year so I try to minimize data transfer to the gateway to once a day to save power.

<snip...>
The complexity you are introducing by waiting, far outweighs the difference in power consumed and, in fact, is more likely to discharge your battery faster than if you simply send it each time you sample.

In your case, you're sampling every 300 seconds.  The whole transaction, not including the time you need to sample your data, from waking up, sending your data with acknowlege, and going back to sleep will take less than 6milliseconds (roughly) with most of the time in RX, not TX.  Further, let's assume that it takes you 2 seconds to do your data sample, if you leave the radio off, then you're only pulling radio and peripheral power during that time (5mA?)
Your duty cycle is roughly 0.67%.  During that time you will consume, on average, about 5.18mA.  With a 0.67% duty cycle and 5.18mA during the on time and approximately 23uA during sleep, you will on average consume 68.33 uA 100% of the time. 

If you are using a 1250mAH battery, your battery should last about 2 years...

Notice, in the above calculations, the radio power consumption is virtually negligible compared to the power you HAVE to consume anyway to take your logged measurements.  Why?  Because the transmission time is SOOOOO short...  6mS out of 5minutes is nothing! And these calculations are using an RFM69HW running at medium transmit power.

Net:  Do the math, don't just look at the radio power consumption.  Think about how little it's actually on.

Tom
Title: Re: How to transfer the content of a (txt-)file via RFMxx lib
Post by: Felix on January 11, 2015, 10:10:51 AM
@Clemens

Tom's comments are very valid. Let me try to answer your points.

1. The examples clearly show more than 1 character, take another look. The examples are also not meant to teach C++. You can read your data from the memory chip or another source and fill your buffers then send them over the radio, you will need to chunk it to fit it in the radio buffers 61bytes max at 1 time.

2. An ACK = acknowledgement = radio packet sent back to the sender by the receiver to notify the sender that the initial packet  was received.

3. I believe Tom addressed that here.

4? Moteino uses the atmega328p MCU which has a total internal flash memory of 32kb. The external memory flash chip I offer is 512kb, you can use this for any kind of data storage, also used for wireless programming. I don't care about other clones, bigger isn't always better - I tested other larger size chips before deciding this one gives the best speed/price ratio. You can do data logging in that 512kb but since you have a radio in there that's the main focus of the device, and getting data out through the radio not through temporary storage on the flash. Other larger chips can take many seconds to clear sectors or erase the entire chip, hence I never chose another chip. You can put whatever size memory you want actually, just match the pinout.
Title: Re: How to transfer the content of a (txt-)file via RFMxx lib
Post by: Clemens on January 12, 2015, 04:36:26 PM
Thanks for this hints, so I will come away from storing large data on the node and in return go to a more frequent transmission. I have to send the data anyway and it seems not to make much difference to send it in one go or in packages over time. I thought I have more advantages but with the small 61 bytes buffers size it seems reasonable to take the simple method with not much more power consumption. Thx for the math, Tom!

I tried for a full dataset sizeof and I got 77 for "2013/06/08 02:10:48,21.2,1011,0,35.25,13,83,29,47,94,170,189,277,393,414,430" That means I have to divide it in at least two buffers / packages. Now I see the problem that in case a package is lost the whole data structure is messed up (in case I count on always two packages arrived one after another are a dataset). So the super safe way would be single packages like

2013/06/08 02:10:48,temp-1a,21.2
2013/06/08 02:10:48,press,1011
2013/06/08 02:10:48,light,0
2013/06/08 02:10:48,temp-2a,35.25
2013/06/08 02:10:48,temp-2b,13
2013/06/08 02:10:48,,moi,83
...

but this blows the transmission and power consumption up! Do you have a method or idea to transfere a complete dataset efficient but also save for the structure?
Title: Re: How to transfer the content of a (txt-)file via RFMxx lib
Post by: TomWS on January 12, 2015, 04:51:00 PM
Quote from: Clemens on January 12, 2015, 04:36:26 PM
Thanks for this hints, so I will come away from storing large data on the node and in return go to a more frequent transmission. I have to send the data anyway and it seems not to make much difference to send it in one go or in packages over time. I thought I have more advantages but with the small 61 bytes buffers size it seems reasonable to take the simple method with not much more power consumption. Thx for the math, Tom!

I tried for a full dataset sizeof and I got 77 for "2013/06/08 02:10:48,21.2,1011,0,35.25,13,83,29,47,94,170,189,277,393,414,430" That means I have to divide it in at least two buffers / packages. Now I see the problem that in case a package is lost the whole data structure is messed up (in case I count on always two packages arrived one after another are a dataset). So the super safe way would be single packages like

2013/06/08 02:10:48,temp-1a,21.2
2013/06/08 02:10:48,press,1011
2013/06/08 02:10:48,light,0
2013/06/08 02:10:48,temp-2a,35.25
2013/06/08 02:10:48,temp-2b,13
2013/06/08 02:10:48,,moi,83
...

but this blows the transmission and power consumption up! Do you have a method or idea to transfere a complete dataset efficient but also save for the structure?
Where are you sending it?  Can you simply send it as a binary structure?  Timestamp alone would be only 4 bytes, most of your data would be no more than 1 or 2 bytes each, by the looks of it.

The only tricky part sending Binary data is if the 'endianess' of the two endpoint are different, but I suspect you have a Moteino at both ends, so... no problem...

Tom
Title: Re: How to transfer the content of a (txt-)file via RFMxx lib
Post by: Felix on January 12, 2015, 06:41:24 PM
Quote from: Clemens on January 12, 2015, 04:36:26 PM
but this blows the transmission and power consumption up! Do you have a method or idea to transfere a complete dataset efficient but also save for the structure?
You know ... these radios are optimized for low power, not for streaming large amounts of data. You can optimize squeezing more data through binary as Tom suggested, like using structures. See the struct examples (https://github.com/LowPowerLab/RFM69/tree/master/Examples) for an example how that is doable. A binary int will take 2 bytes no matter what, an ascii int can take up to 5 bytes though (for instance "65536").