How to keep a copy of the uploaded program and be sure to find it months later?

To illustrate the problem, I have a working handset and a base station pair to which I uploaded programs about 2 or 3 weeks ago. Since then I have been working on similar code on different, but similar hardware.

Now I find that I can't remember exactly which program code was uploaded onto the working pair. I want to try some changes, but I also wish to be able to revert to the working version.

The programs could, of course, be written to print the name of the file from which the code was generated. But that does not prevent me from accidentally or deliberately (perhaps foolishly) altering the code so that the file with the name in Serial.println() is no longer the same as when the code was uploaded.

It is important to note that I am NOT trying to solve the problem of making backup copies while I am actively developing a program - I am reasonably good at that.

The problem is to find a reliable and foolproof way to keep a copy of the program that was actually uploaded in such a way that it will still be there in 2 weeks, 2 months or 2 years - and can easily be identified from the Arduino and uploaded again if required. I don't have the self-discipline to laboriously make copies and store them away, perhaps write-protected - especially because the Arduino system makes it so easy to make some small changes and upload a new version every few minutes.

I'm wondering if anyone else has considered the same problem and found a simple and satisfactory solution?

...R

save it as a txt file.

oddly, I am in that exact predicament.
I have two concurrently running units, on the same project, albeit with altered programs.

last night, I tried to pull the data from one, did not like the data logging format and so re-wrote that bit.
however, I am not sure which file I changed.

Every program should have a unique version number that is output or otherwise accessible upon startup.

The version number can also be in the source file name, but I find it difficult to discipline myself to constantly ensure that everything is kept consistent.

Serial print name and version in setup() as suggested by jremington. Is permanent and takes little space.

Weedpharma

I put all the running codes on a usb stick, naming the file with the date and name of the project. On the top of the page, i comment the date it is uploaded, and a "version number". The file i work on is saved on ny local computer. This works well for me, but as u say it's easy to mix up something. I've been looking for a simple, free software like jira, but made for one-man projects to keep track of versions and bugs and dates. Still haven' found anything.

weedpharma:
Serial print name and version in setup() as suggested by jremington. Is permanent and takes little space.

Yes. But that is not where the problem lies.

How do you ensure that the file on the PC (with the name in Serial.println() ) remains findable and unchanged.

And a related problem. I don't have the self discipline to increment the version number before every single upload. Together with which, the Arduino system makes changing the name of the .ino file a PITA - because you also have to rename the diirectory it sits in.

And an even bigger issue, perhaps. If I want to be able to recreate a program after several months I will also need to know what version of the IDE was used to create it and what version of each of the libraries was used - and if I am now using a newer library for current work I will need access to the older version. There is no shortage of Threads here about incompatibilities between IDE versions.

...R

One way to get it right is to create a build environment that automatically

  1. puts a version string in the file - typically major.minor.buildnr e.g. 0.1.13
  2. takes a snapshot of the source in every upload.

This almost implies a command line build as that is easier to tweak than the IDE(*)

The other way is discipline :slight_smile:


(*) an idea to tweak the IDE is to have a generic POSTUPLOAD command string.

  1. if there is a command it is executed after successful upload.
  2. if empty - nothing happens of course
  3. can be modified by the developer, so it works on Linux Mac & PC, to any need.

E.g. this could also be used to trigger an automatic test if upload succeeded.

robtillaart:
One way to get it right is to create a build environment that automatically

  1. puts a version string in the file - typically major.minor.buildnr e.g. 0.1.13
  2. takes a snapshot of the source in every upload.

This almost implies a command line build as that is easier to tweak than the IDE(*)

The other way is discipline :slight_smile:

That sort of discipline sucks !

I have been developing (in my head, so far) some ideas for using Python to control the environment in the way you describe - and making a call to the Arduino command line to do the actual compile and upload. I'm thinking of recording the filename plus the date and time (including seconds to be sure each is unique). Basically an evolution of the stuff I posted here.

One attractive side effect may be that I can dispense with the requirement to have each .ino in its own directory and leave that house-keeping to Python. It may even mean that I could directly compile (or try to compile) something I copied from a post here without needing to create a framework for it.

...R

I'm interested in your progress, a Python build environment would be nice!

robtillaart:
I'm interested in your progress, a Python build environment would be nice!

It will probably be a few days before I have anything to Post.

In the meantime if anyone has a better idea please let us know. I don't want to re-invent the wheel.

...R

This is exactly the problem that version control software solves. I can go back and recompile any version that I have put onto hardware as 'finished' and I can reconstruct the libraries I was using at the time too.

There's two major open source systems: Git and Subversion. Git has free hosting on GitHub. Lots of people use it to back up their hard drives too. I have my own Subversion server on paid hosting. I find Git very difficult to understand as it is intended to manage very large open source projects with hundreds of contributors.

The real advantage of version control is the commit comments. I can go back to any version and not only see what's different but why I changed it.

ummm..
have the IDE append either the first or last lines

// last saved, 5 jan 16 - 523 bytes, last uploaded 22dec15 - 613 bytes

I make folders with sub folders for all the various types of code files I have. The below is the path to the servertest4_led_204_simple.ino file. You have to make the main sub folders to hold the code folders the IDE makes, then you can save the code folder in a main folder for that type of code file. The attached screen capture shows my filing structure and how it it expands from the IDE file > sketchbook selection.
Give the saved code files meaningful names as to what they do and out additional info in the file info header.

C:\Users\zoomkat\Documents\Arduino\A001\Internet\Server\LED\servertest4_led_204_simple

Thanks @zoomkat, but that is not the problem I am trying to solve. I already do what you recommend. The problem is that if I make changes to a file every few minutes and upload a new version I don't have the discipline to create a new directory and a new file every time I change my mind. Also (due to my poor discipline) I change the file after uploading it to Arduino X so that I can try something new on Arduino Y - and get myself all mixed up.

@dave-in-nj, can you explain further what you have in mind? How do I get the IDE to do what you say?

@MorganS, version control has crossed my mind but I'm not clear about how I can rigidly connect the code on an Arduino back to the version on the PC that created it some months earlier - so I can go back to that version and re-compile it and upload it and expect it to be identical.

  • What is it that identifies a particular version in Subversion and how would I put that identifier into my Arduino code?
  • Also, I have a notion that one has to "do something" before the version control system records a new version - or is it an automatic response to uploading the code to my Arduino board?

All the input is much appreciated.

...R

The problem is that if I make changes to a file every few minutes and upload a new version I don't have the discipline to create a new directory and a new file every time I change my mind. Also (due to my poor discipline) I change the file after uploading it to Arduino X so that I can try something new on Arduino Y - and get myself all mixed up.

Well, in the new 1.6.5 IDE there appears to be a new "feature" that wants me to save the file when I'm not ready. I think I click the cancel button and move on. When I'm done working with the file I then use the "save as" option. I think i know better when I want to save something than does the new IDE.

so I can go back to that version and re-compile it and upload it and expect it to be identical.

Assuming you use the same compiler + compiler settings yes
so you should keep all your versions of the compiler too, ans associate the code version with the right compiler.

robtillaart:

so I can go back to that version and re-compile it and upload it and expect it to be identical.

Assuming you use the same compiler + compiler settings yes
so you should keep all your versions of the compiler too, ans associate the code version with the right compiler.

I agree. But I think you have quoted out of context.

I am hoping @MorganS will explain how to do that in the context of Subversion. In other words, how, exactly does Subversion help (if it does).

...R

You can't expect to go back to a version you uploaded in the middle of a programming session, although that is possible. Was the version compiled at 2:04:24 the one that did something useful or was it the one that you broke something?

But once you finish a session, before you turn the computer off, it is often useful to save a checkpoint there. Either it is the "finally got it talking to the sensor!" version or it is the "not sure why it's not talking to the sensor?" version, taking a minute to write that comment as part of a Subversion 'commit' is very valuable.

Bot Git and Subversion start with that concept of a unit of work. You have finished something. Now it is time to save that to the repository. It may be a complete working system, like you just loaded that code onto 100 Arduinos ready to ship or it may be a single feature within a system.

Looking at this in Subversion, you can review the "log" for each file. Each time it was committed, what was the comment you wrote at the time. If you have got yourself tied in knots and the sensor code you thought was working isn't, then you can go back and find that early version where it was working. You can also use the "branch and tag" method, where you can have multiple developers working on different features in branches and use tags to record major events like a version release. Branches aren't useful for a single developer and tags are just like the log except you can't write long comment descriptions.

Can you also associate more files to the project, like drawings, parts list and documentation?

@dorvakta, please don't sidetrack this Thread with queries about Subversion. If you want to follow that up please start your own Thread.

@MorganS, Thanks for your comments. What you have described is pretty much how I thought Subversion works. I specifically want to avoid the need for a "commit" action on my part.

I just want to be able to retrieve the code that created the program that happens to be on my Arduino as identified by a Serial.print() message from the Arduino - regardless of whether I uploaded it in the middle of a session or at the end of it.
For example, the message might be Serial.println("TestInoC-YYYYMMDD-HHMMSS");

I have been writing some stuff which I will post tomorrow. I don't have time to finish it now.

...R