Re: [Dorset] {Spam?} Using a Raspberry Pi 'Headless' and Unattended
On Monday 11 January 2016 20:06:34 Paul Tansom wrote: > Anyway, working on the basis of using a Raspberry Pi, it seems to me that > the key requirement would be to detect the loss of power and shutdown. > Clearly this needs some form of battery or capacitor to provide enough time > before complete loss of power. There are a number of similar projects out > there if you are wanting to do some soldering, etc., but an easier > alternative might me something like the UPS PIco (1) or the Pi UPS (2). Paul, Thanks for that. Clive and I did consider some form of UPS device, before focusing on the live distro approach. The main reason that we rejected the UPS idea is that we thought it might be a bit complex to get working and there would be an ongoing need to replace the battery every few years. The big advantage of course is simplicity, so providing we lay in a stock of batteries, it could be a good way forward. Your links dispel the first concern. The advantage of the live distro approach is that it's zero cost, but the disadvantage is that we'd have to make sure the method to create it was well documented so that future maintainers of the system could recreate it when the need to upgrade the system or replace something arises. I suspect we'll keep both methods in our armoury. -- Terry Coles -- Next meeting: Bournemouth, Tuesday, 2016-02-02 20:00 Meets, Mailing list, IRC, LinkedIn, ... http://dorset.lug.org.uk/ New thread: mailto:dorset@mailman.lug.org.uk / CHECK IF YOU'RE REPLYING Reporting bugs well: http://goo.gl/4Xue / TO THE LIST OR THE AUTHOR
Re: [Dorset] Using a Raspberry Pi 'Headless' and Unattended
I have just done a very quick test booting a RPi with the filesystems mounted read-only. Basically it just worked. There were some 'failure' messages at startup where it was trying to save things to disk, but they aren't things which would matter. If the filesystems are all mounted read-only then there's no problem just turning power off. There's nothing waiting in RAM to be written to the disk if it's read-only! I assume that "dawn" and "dusk" will be time intervals like "every few minutes", rather than actually following clock-time? I'm sure you are aware that the RPi doesn't have a real-time clock, so every time you turn it on its clock will start from the same time. However for around £10 you can get a GPS receiver module which can be connected to the RPi's 3.3v serial pins, which would provide an accurate time if it were needed. If it doesn't know the real time and gets restarted every day then the RPi might actually keep running past year 2038! If the filesystems are mounted read-write then you shouldn't power off by just removing the power. If you do then any data in RAM which hasn't been written to the disk will be lost, and the filesystem will still be marked as dirty, so even if there's no un-written data it might take longer to start the next time. If you do end up using a UPS, perhaps a large capacitor would be better than a battery as it shouldn't require replacement. The "interface kit" required to connect a computer to an Arduino is a USB cable. -- Andrew. -- Next meeting: Bournemouth, Tuesday, 2016-02-02 20:00 Meets, Mailing list, IRC, LinkedIn, ... http://dorset.lug.org.uk/ New thread: mailto:dorset@mailman.lug.org.uk / CHECK IF YOU'RE REPLYING Reporting bugs well: http://goo.gl/4Xue / TO THE LIST OR THE AUTHOR
Re: [Dorset] Using a Raspberry Pi 'Headless' and Unattended
Hi Terry, Andrew wrote: > However for around £10 you can get a GPS receiver module which can be > connected to the RPi's 3.3v serial pins, which would provide an > accurate time if it were needed. If you need all the Zeroes to be in sync, but find they drift apart after all being turned on at the same moment, then you could wire them all up to a single very-slow "clock" signal that just marks "midnight" of their "day" and brings them regularly back in step. This would also help if individual ones lose power during the day because of maintenance of their section of track. Cheers, Ralph. -- Next meeting: Bournemouth, Tuesday, 2016-02-02 20:00 Meets, Mailing list, IRC, LinkedIn, ... http://dorset.lug.org.uk/ New thread: mailto:dorset@mailman.lug.org.uk / CHECK IF YOU'RE REPLYING Reporting bugs well: http://goo.gl/4Xue / TO THE LIST OR THE AUTHOR
Re: [Dorset] Using a Raspberry Pi 'Headless' and Unattended
Hi Tim, > Two or three years back I designed a UPS to work with a Pi for a > backup server, communicating over IIC, only to discover that the Pi > IIC didn't implement pulse stretching. That's interesting. I found http://www.advamation.com/knowhow/raspberrypi/rpi-i2c-bug.html detailing the І²C problem. Not good news! And no sign Broadcom are interested in fixing it in later versions. :-( Cheers, Ralph. -- Next meeting: Bournemouth, Tuesday, 2016-02-02 20:00 Meets, Mailing list, IRC, LinkedIn, ... http://dorset.lug.org.uk/ New thread: mailto:dorset@mailman.lug.org.uk / CHECK IF YOU'RE REPLYING Reporting bugs well: http://goo.gl/4Xue / TO THE LIST OR THE AUTHOR
Re: [Dorset] Using a Raspberry Pi 'Headless' and Unattended
Hi Terry, > we would like to use a Pi Zero to turn lights inside houses on and off > at intervals and also to dim and brighten the main lights at 'dusk' > and 'dawn'. Do dusk and dawn occur repeatedly through the day, or is there any need to tie in with wall clock time, only there's no real-time clock on the Pi Zero. > We have a physical solution and the code is fairly trivial, but my > main concern is the fact that once implemented, the Pi would have to > run unattended for most of the time and also withstand having the > power removed without a formal shutdown every evening (or if there is > a power cut). Clearly, this would put the integrity of the data on > the SD Card at risk. Yes, the Pi can just have its power cut, as Peter, said, but the integrity of the filesystem data depends on the filesystem being unmounted first so its data is flushed out. > I think we have a solution, but before we rush off to do it, I'd > appreciate your comments. The plan is to create a Live Tiny Core ( > http://tinycorelinux.net/ports.html[2] ) distro containing the > packages needed and the code to be run. We would install this on the > SD Card and then make it Read-only. How does the "read only" bit happen? I was thinking of having Raspberian boot as normal and then re-mount its SD-card filesystems read only along with starting your light show. `sudo mount -o remount,ro,noload /dev/...' does the re-mount. ro means read-only. ext3 and others also need noload to avoid reading their journal and making repairs; IOW, without that, they do *write* to the media. See mount(8) for your filesystem type to see if it's needed. But the downside of this is what bits Raspberian has set running take a dislike to finding nothing's writable, and whether that affects system stability over the longer term. Your idea of a cut-down installation with the minimum is better. Taking that further, you could make your program be `init'. Any idea what language you're planning to use yet? If it's not a statically-linked executable then its run-time dependencies will need to be present. This post might be useful. https://blog.bytemark.co.uk/2016/01/04/setting-up-a-raspberry-pi-perfectly-on-the-first-boot Cheers, Ralph. -- Next meeting: Bournemouth, Tuesday, 2016-02-02 20:00 Meets, Mailing list, IRC, LinkedIn, ... http://dorset.lug.org.uk/ New thread: mailto:dorset@mailman.lug.org.uk / CHECK IF YOU'RE REPLYING Reporting bugs well: http://goo.gl/4Xue / TO THE LIST OR THE AUTHOR
Re: [Dorset] Using a Raspberry Pi 'Headless' and Unattended
Hi Terry >Clive has recruited me to help him at the Wimborne Model Town Railway ( http://www.wimborne-modeltown.com/the-model-town/model-railway/ 1] ). His responsibility is controlling the lighting and >we would like to use a Pi Zero to turn lights inside houses on and off at intervals and also to dim and >brighten the main lights at 'dusk' and 'dawn'. > >We have a physical solution and the code is fairly trivial, but my main concern is the fact that once >implemented, the Pi would have to run unattended for most of the time and also withstand having the >power removed without a formal shutdown every evening (or if there is a power cut). Clearly, this would >put the integrity of the data on the SD Card at risk. > >I think we have a solution, but before we rush off to do it, I'd appreciate your comments. The plan is to >create a Live Tiny Core ( http://tinycorelinux.net/ports.html2] ) distro containing the packages needed >and the code to be run. We would install this on the SD Card and then make it Read-only. Each morning, >the manager would then be able to power up the railway, which would bring up the Pi and start the >program running. At the end of the day, the manager would then be able to turn off the supply without >any risk to the SD Card. > >Can anyone see any problems with this approach or suggest a better way? One of these links could provide a solution https://www.raspberrypi.org/forums/viewtopic.php?f=37=39059 or http://mausberry-circuits.myshopify.com/collections/frontpage.The Mausberry Circuits solution may be a bit more expensive but I have the car power supply which works great powering down the Pi when the ignition is switched off. Regards Archie -- Next meeting: Bournemouth, Tuesday, 2016-02-02 20:00 Meets, Mailing list, IRC, LinkedIn, ... http://dorset.lug.org.uk/ New thread: mailto:dorset@mailman.lug.org.uk / CHECK IF YOU'RE REPLYING Reporting bugs well: http://goo.gl/4Xue / TO THE LIST OR THE AUTHOR
Re: [Dorset] Using a Raspberry Pi 'Headless' and Unattended
On Tue, Jan 12, 2016 at 02:09:37PM +, Andrew wrote: >I have just done a very quick test booting a RPi with the filesystems mounted >read-only. Basically it just worked. There were some 'failure' messages at >startup where it was trying to save things to disk, but they aren't things >which would matter. If the filesystems are all mounted read-only then there's >no problem just turning power off. There's nothing waiting in RAM to be >written to the disk if it's read-only! Hello, Dorset LUG. This is perhaps a touch pedantic for a first post, but ... There may still be some situations where you might corrupt the flash card if you yank the power, even when the host processor does not attempt to write to the flash. I expect this is very very rare, and possibly avoidable with the right SD card. Good luck getting the SD card vendor to confirm if it behaves correctly or not. Your SD card almost certainly contains a microcontroller, most likely an ARM or an 8051 with 32-bit extensions, running on the order of 100MHz. This manages the flash and implements a flash translation layer (FTL) which presents the block storage abstraction we know and love. The FTL handles block mapping, concealing bad blocks, wear levelling, all that fun stuff. The floating gates in modern flash memories are so small and densely packed that they hold only a few hundred electrons. Some of these can leak away over time. Worse, multiple reads of one memory block can over time cause changes in nearby memory blocks -- this is known as "read disturb". These problems are made more severe with 2 or 3 bit per cell designs (MLC/TLC) where the thresholds between different values are very close. For example the Samsung 840 Evo SSDs were affected by this issue and required several firmware fixes to fully address the problems. The FTL may therefore track the age and number of reads to each block and will copy blocks around, even if there is no write activity. This copying also requires updating the block mapping so next time the controller knows where in flash the block is located. It's hard to know for sure if the controller in the SD card manipulates the on-flash data structures in such a way that is robust against the power being yanked at any point in the process. For more insight on what's going on inside your SD card (including how to run your own programs on the internal microcontroller!) I recommend this blog post and 30C3 presentation from Bunnie Huang: http://www.bunniestudios.com/blog/?p=3554 Also interesting and includes die-shots of a number of microSD cards: http://www.bunniestudios.com/blog/?page_id=1022 The solution seems obvious - just give them a compressed image of the final SD card. They can later uncompress and write this to a second SD card to make a duplicate should the first ever become corrupted. Will _ William R Sowerbutts w...@sowerbutts.com "Carpe post meridiem" http://sowerbutts.com main(){char*s=">#=0> ^#X@#@^7=",c=0,m;for(;c<15;c++)for (m=-1;m<7;putchar(m++/6%3/2?10:s[c]-31&1<
Re: [Dorset] Using a Raspberry Pi 'Headless' and Unattended
On Tuesday 12 January 2016 14:15:30 Ralph Corderoy wrote: > Do dusk and dawn occur repeatedly through the day, or is there any need > to tie in with wall clock time, only there's no real-time clock on the > Pi Zero. 'Dusk' and 'dawn' are fixed values around 3 to 5 minutes apart so that the visitors can see the layout operating at 'night' as well as during the 'day'. There is no need to know the real time. > How does the "read only" bit happen? I was thinking of having > Raspberian boot as normal and then re-mount its SD-card filesystems read > only along with starting your light show. `sudo mount -o > remount,ro,noload /dev/...' does the re-mount. ro means read-only. > ext3 and others also need noload to avoid reading their journal and > making repairs; IOW, without that, they do *write* to the media. See > mount(8) for your filesystem type to see if it's needed. But the > downside of this is what bits Raspberian has set running take a dislike > to finding nothing's writable, and whether that affects system stability > over the longer term. Your idea of a cut-down installation with the > minimum is better. Yes. That is what I had in mind. > Taking that further, you could make your program be `init'. Any idea > what language you're planning to use yet? If it's not a > statically-linked executable then its run-time dependencies will need to > be present. This post might be useful. > https://blog.bytemark.co.uk/2016/01/04/setting-up-a-raspberry-pi-perfectly-o > n-the-first-boot The plan at the moment is to write the program using Python, because of all the libraries for GPIO support and the huge number of prior examples (remember I was a systems engineer with a maintenance background who ended up doing some basic coding in C and ATLAS). So if a truly cut-down solution was required, I'm sure that the Python code could be converted to C and compiled to run-standalone. I'm intrigued at the idea of making the program 'init'. Are you saying that we would have a custom init that launches only the minimum code required to support execution and then finally our program? I had wondered about doing something like that, eg boot into a shell and then launch the code, but that seems even more extreme. -- Terry Coles -- Next meeting: Bournemouth, Tuesday, 2016-02-02 20:00 Meets, Mailing list, IRC, LinkedIn, ... http://dorset.lug.org.uk/ New thread: mailto:dorset@mailman.lug.org.uk / CHECK IF YOU'RE REPLYING Reporting bugs well: http://goo.gl/4Xue / TO THE LIST OR THE AUTHOR
Re: [Dorset] Using a Raspberry Pi 'Headless' and Unattended
On Tuesday 12 January 2016 15:49:06 Andrew Montgomery-Hurrell wrote: > Could you not just have the sdcard boot up system to run from a ramdisk? > Then the ramdisk can unmount the sdcard if necessary and you can have a, > albeit limited, writeable system. That's effectively what a live Tiny Core instance would do. -- Terry Coles -- Next meeting: Bournemouth, Tuesday, 2016-02-02 20:00 Meets, Mailing list, IRC, LinkedIn, ... http://dorset.lug.org.uk/ New thread: mailto:dorset@mailman.lug.org.uk / CHECK IF YOU'RE REPLYING Reporting bugs well: http://goo.gl/4Xue / TO THE LIST OR THE AUTHOR