hamishcunningham/pi-tronics — pull request #5 by stoduk (2014-06-17 10:28:18+00:00)
Title: Save the last entered config at the end of config block, so it is uploaded to MoPi last

Config saving is done like this:
- first see if the config being saved (wc, wc1, or wc2) already exists.
- if it exists, then use sed to replace that config inline
- if it doesn't exist write it at the end of the config block

This means if the user runs "mopi" multiple times, perhaps just because they are experimenting, that they can end up with some unexpected results.

eg. save wc config1, save wc1 config2, save wc config3. The result of this is a config file with "-wc config3" then "-wc1 config2" in it - and so the last saved config will be overwritten when uploading to MoPi by the wc1 config.

I think what the user likely wanted is the last written config to be written last (ie. "-wc1 config2", then "wc config3"). This diff achieves that.

Note: it may be possible that some more policing could be done to remove unnecessary config (eg. if you save wc1 and wc2 config then any wc config is never going to have effect - but with the comms write problem fixed it is also harmless, just one unnecessary write), but that could be a later optimisation.

I'll add some test logs as a second comment.