Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 00:52 03 Aug 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Closing #1 after power failure

     Page 1 of 2    
Author Message
Chrisk

Senior Member

Joined: 21/12/2014
Location: Australia
Posts: 122
Posted: 03:31am 11 Sep 2021
Copy link to clipboard 
Print this post

Hi Guys
I have an old CMM programmed to have the days data stored on an SD card.
But after a power failure I restart using an autorun file when power is restored.
The only problem with that is that the file storing the day's data hasn't been closed, so I end up loosing the stored information.
Is there a way of checking within the autorun file whether the #1 file is still open.
I thought of inserting a "close #1" in the autorun file but that could be fraught with danger if somehow it was closed.
Under that condition I don't think the autostart program could run.
An ideas how to get around the problem.

Chrisk
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9610
Posted: 03:59am 11 Sep 2021
Copy link to clipboard 
Print this post

If it is important data, I would recommend simply using a 5v UPS such as this one here.

Extremely cheap at about one buck.  All you need to add is a suitable 3.7v battery.
The module has automatic charging and 3.7v-to-5v step-up all on-board, so connect your incoming 5v to this board, the output to the CMM, and install a suitable battery.

The board will keep the CMM2 running if there is a power cut.
Smoke makes things work. When the smoke gets out, it stops!
 
Andrew_G
Guru

Joined: 18/10/2016
Location: Australia
Posts: 871
Posted: 04:09am 11 Sep 2021
Copy link to clipboard 
Print this post

Hi Chris,
I like Grog's UPS idea but can you not have "ON ERROR SKIP" the line before your CLOSE #1 statement?

Cheers,

Andrew
(By the way are you ex ARRB?)
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9610
Posted: 04:23am 11 Sep 2021
Copy link to clipboard 
Print this post

Yeah, that's what I thought of first, but I THINK the issue is that the CMM is happily logging data - then the power fails.

In that situation, the power fails with the file still in the OPEN state, and so the data is lost as it has not been closed first.

When the power comes back on, the CMM will restart via AUTORUN, but as this is a clean restart, the port will be closed just by the fact the power was cycled.

The only other software thing I thought of was ONLY have the handle open while writing to the card.  IE: Don't leave the file open all day, just open it, write what you need to it, and close it again.  That would be safer then leaving the file handle open all the time IMHO.

I found another UPS thing here which is a bit cuter and has standard USB sockets on it, saving you having to wire up as in the cheaper one.  This one will set you back about four bucks, but it also has on-board 18650 battery holders, so it is probably a better choice for a plug-n-play kind of solution.
Smoke makes things work. When the smoke gets out, it stops!
 
Andrew_G
Guru

Joined: 18/10/2016
Location: Australia
Posts: 871
Posted: 04:49am 11 Sep 2021
Copy link to clipboard 
Print this post

Spot on Grogs!

Andrew
 
Chrisk

Senior Member

Joined: 21/12/2014
Location: Australia
Posts: 122
Posted: 05:13am 11 Sep 2021
Copy link to clipboard 
Print this post

Hi Guys
Thanks for the quick response.
I always toyed with the idea of power backup but thought is wasn't that vital.
It's only some greenhouse data.
I also thought of closing with "close #1" but the thought of doing that very three minutes might reduce the life of the memory.
The way I have constructed the unit lends itself to Grogs first suggestion.
Wasn't aware that a simple device like that was available.

Thanks again.

Chrisk
 
Turbo46

Guru

Joined: 24/12/2017
Location: Australia
Posts: 1642
Posted: 05:17am 11 Sep 2021
Copy link to clipboard 
Print this post

I think it was Bigmik who once suggested a USB powerbank.

Bill
Keep safe. Live long and prosper.
 
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 2642
Posted: 05:45am 11 Sep 2021
Copy link to clipboard 
Print this post

#Chrisk
"I also thought of closing with "close #1" but the thought of doing that very three minutes might reduce the life of the memory."
Had a similar problem with a MM+ based datalogger / controller so added Open #n and Close #n either side of all Print #n statements and it ran continuously for 3 years without problem. Data was recorded 2 to 15 times per hour. The MM+ & SD card are still working fine.
 
toml_12953
Guru

Joined: 13/02/2015
Location: United States
Posts: 442
Posted: 11:02am 11 Sep 2021
Copy link to clipboard 
Print this post

  Chrisk said  Hi Guys
I have an old CMM programmed to have the days data stored on an SD card.
But after a power failure I restart using an autorun file when power is restored.
The only problem with that is that the file storing the day's data hasn't been closed, so I end up loosing the stored information.
Is there a way of checking within the autorun file whether the #1 file is still open.
I thought of inserting a "close #1" in the autorun file but that could be fraught with danger if somehow it was closed.
Under that condition I don't think the autostart program could run.
An ideas how to get around the problem.

Chrisk


Close #1 in the autorun won't do any good. The file is not open at powerup. The data is already gone.
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3378
Posted: 01:43pm 11 Sep 2021
Copy link to clipboard 
Print this post

The 18650 "battery shield" items are nifty devices, but the problem I've seen with them is that if your mains power goes off and the battery itself runs down, then it won't start back up if your load power is significant.

If you disconnect the load, then the battery will charge up and then you can reconnect the load. I've resolved this problem by connecting a diode between the 5V mains usb connector and the 5V USB out connector. That's if your load is connected to the USB socket. If you have a 3V3 load, I'm not sure what you would do to solve this problem.
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 7938
Posted: 03:58pm 11 Sep 2021
Copy link to clipboard 
Print this post

Close#n writes anything remaining in buffer n followed by an EOF character IIRC. If that's so then only a UPS can save the data, as toml says.

Another way is to save data to battery-backed RAM until you have enough to write a block to the SD card then open the file, write the block, close it and delete the RAM. It may be possible to do this by using the registers on a RTC.
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
Chrisk

Senior Member

Joined: 21/12/2014
Location: Australia
Posts: 122
Posted: 04:44am 31 Dec 2021
Copy link to clipboard 
Print this post

Hi Guys
Hope you have a better 2022 than I did in 2021.

I would just like to inform you of my experience with AliExpress.
I took Grogster's suggestion and decided to purchase the UPS.
Well here we are over 4 months down the track and still no board.
Contacting them is a waste of time. I get the same old rubbish about
we will look after you.
Over many requests by the seller to wait I am now at
a point where I cannot lodge a complaint with AliExpress.
I seems our Chinese friends take us for fools.
I will not be purchasing from AliExpress again no matter how good a product or price is.
I know some of you have found good dealers in China but the supplier of this board isn't one of them.

Anyone know where I can purchase an equivalent board that doesn't cost the earth.



Happy New Year 2022  
Chrisk
 
Turbo46

Guru

Joined: 24/12/2017
Location: Australia
Posts: 1642
Posted: 05:58am 31 Dec 2021
Copy link to clipboard 
Print this post

You still could use a USB power bank and leave the power bank supplied via a mains 'wall wart'.

With an opto coupler you could monitor the input to the power bank and use its output signal to indicate power failure and use that to initiate closing the file (or not).

Alternatively a supercap could hold the power up long enough for you to detect a power failure and close the file.

Bill
Keep safe. Live long and prosper.
 
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 2642
Posted: 06:57am 31 Dec 2021
Copy link to clipboard 
Print this post

With AliExpress the suppliers range from excellent to shady. If your order hasn't arrived at the 2 months + 3 weeks point you must open a dispute or no refund.
 
Pluto
Guru

Joined: 09/06/2017
Location: Finland
Posts: 375
Posted: 11:58am 31 Dec 2021
Copy link to clipboard 
Print this post

Even if you open a dispute the outcome is quite uncertain. I lost about 15 packages last spring. Despite disputes, no refund. Got even a message from AE stating that I was violating their refunding rules! Since that I became persona non grata at AE. A few weeks ago a seller sent me a flowindicator instead of PCBs. Seller admitted the mistake, but not willing to refund or send correct parts. Dispute resolved in favor of the seller. Small amount of money, but I feel quite p***** off.

As said before, all AE sellers are not like that. Many are OK.
Banggood seems to be a more reliable plase to buy from - but more expensive.
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3378
Posted: 01:27pm 31 Dec 2021
Copy link to clipboard 
Print this post

My own experience with Aliexpress is quite good. Many dozens of items ordered. Of the few which were not received or not the item ordered I have gotten a refund or reshipment in every case but one. That one was marked "confirmed receipt", but not by me, and I had no success in getting a refund (a couple of dollars--not worth fighting further).

I have an order of 320Ahr LiFePO4 batteries now not received after 3 months, but I understand from the posts of others that shipping time for those will be on the order of 5 months.

Shipping time now is certainly slower than it was 2 years ago.
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
Chrisk

Senior Member

Joined: 21/12/2014
Location: Australia
Posts: 122
Posted: 11:29pm 31 Dec 2021
Copy link to clipboard 
Print this post

Since posting I have received communication from the seller. The seller has offered to send me another unit. It all seems genuine but I have had "genuine" before.
I really have little to loose. The UPS was cheap but that is not the point. We as buyers are prepared to pay their price but expect the goods or a refund if they do not supply.
I left it the 4 months plus on account of the covid crisis, let's see what happens.
Thanks for your replies and suggestions.

Lizby  - I hope yours arrives because that's a long wait.

Regards  Chrisk
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9610
Posted: 10:57pm 02 Jan 2022
Copy link to clipboard 
Print this post

Sorry you had that bad experience.

I prefer AE to eBay most of the time, and I have never had any issues with things not arriving.  Perhaps I was just lucky to choose sellers that were more reliable.

I always choose AT LEAST the AE standard shipping method - pay the extra few bucks, as it seems to be worth it.  The standard free shipping I think is the one that takes friggin' ages to arrive.  For more expensive purchases, I go for the DHL shipping.  Much more expensive, yes, but DHL is usually here in roughly a week.

Not saying that was suitable for you, I'm just saying what I do.

For small cheap stuff, I always go for AE standard shipping for the extra few bucks as mentioned.  I don't bother using AE Premium Shipping, as that tends to be quite expensive also, but I can report having good success with arrivals using AE Standard Shipping option.

If a seller does not offer those shipping options and only has free shipping, I tend to look for another seller that DOES offer those choices.
Smoke makes things work. When the smoke gets out, it stops!
 
Chrisk

Senior Member

Joined: 21/12/2014
Location: Australia
Posts: 122
Posted: 11:49pm 02 Jan 2022
Copy link to clipboard 
Print this post

Had more communication from seller. Hopefully genuine. We will see in the quoted arrival time of 30-40 days.
Thanks for the advice. I am sure other members have gained as well.

Chrisk
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9610
Posted: 06:37am 03 Jan 2022
Copy link to clipboard 
Print this post

eBay.......AliExpress.......

Half-a-dozen of one, and six of the other.

That's been my finding with respect to the final product I get in my hands.

With respect to AE, I have found it to be more reliable to NZ with the AE Standard Shipping option.  Perhaps that does not work for all countries.

Whatever the case, DON'T go for the FREE SHIPPING.
Choose one of the other ones on AE, even if only a few bucks.
Seems to always work.
For me.
Smoke makes things work. When the smoke gets out, it stops!
 
     Page 1 of 2    
Print this page
The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025