Hi.
I have so many variations of sketch in different places like computers (Dropbox), smartphone, tablet that after a few days I have no idea which sketch is the most recent working. I added DATE & TIME so I can read them over serial monitor and see when the current program has been uploaded. However an information about from which computer it was uploaded would be handy as well.
So the question is- is it possible to get the computer name, or IP, or MAC while compiling sketch? A filename of sketch could do as well as I'm saving as a new file each time I modify it.
Thanks in advance.
What if you just added in each code to have it print the type of device the code is on? For example
//on the Mac, write Mac
Serial.println("Mac");
//for smartphone, write Smartphone
Serial.println("Smartphone");
You may be interested in my attempt to keep track of programs.
...R
A filename of sketch could do as well as I'm saving as a new file each time I modify it.
There is the FILE constant that you could use...
I have so many variations of sketch in different places like computers (Dropbox), smartphone, tablet that after a few days I have no idea which sketch is the most recent working.
This problem is what GitHub solves. And does not require you to have anything special in your code.
You can create a new branch of your code for each new development phase you start. If you like it you can merge it into a 'master'.
Using the network graph, you can see where each branch belongs in the history of the project, and changing between branches, or reverting to any point in the history is quite simple.
GitHub/Git also makes it simple to keep code synchronized between different PC's
pYro_65:
This problem is what GitHub solves. And does not require you to have anything special in your code.
I think you mean Git rather than Github.
But it does not provide any way of knowing what program is actually inside the Arduino.
I am not familiar with Git. If you know (from the Arduino) precisely which program is inside the Arduino will Git provide the means to recreate that program exactly (with all the relevant versions of libraries etc) ? (Genuine curiosity).
...R
Robin2:
If you know (from the Arduino) precisely which program is inside the Arduino will Git provide the means to recreate that program exactly (with all the relevant versions of libraries etc) ? (Genuine curiosity).
Yes. Either the SHA hash of the commit (requires uploading after a commit) or a tag (requires uploading after you create the tag).
Using submodules may allow library versions to be captured. I have not tried.
Submodules do point to a specific commit in the submodule's repository, for example see the arscons submodule here: https://github.com/LoathingKernel/Ariadne-Bootloader/tree/master/utilities which is at c8195a1. I'd guess you could also target a tag for the submodule but the tag is just an alias for that commit so either way you can set the submodule library's version.
If you didn't want to mess with the complication of submodules you could just include all necessary libraries in the sketch folder/repository.
Of course you also have to consider the platform version, IDE version, and compiler version used...
I thought there's no interest in my topic but I found out I have to manually set the notifications to be notified about replies...
nunofyourbusiness - your solution is too complicated, despite how funny it sounds
PaulS - that's exactly what I'm looking for ! I haven't tried it yet as I'm at work atm but I read that it returns the full path of file, which is even more helpful as it will help me to determine from which machine it was uploaded.
Robin2 - I will definately check it out later.
Thanks for 'Git' clue as well, I will check it too.
In the meantime, I found out that there are android apps to sync the Dropbox folder with an Android device in the same way as in PC, which is awesome and kinda sorts out my problem too. Don't know why the dropbox app doesn't do that itself.
Anyway, thank you all for your help.
If you are building your sketch with a tool, many tools have ways to interrogate git and ask it what branch/tag is checked out.
Or you could have separate git branches with separate config files, and no config file on the master. To build a particular variant, you checkout the branch, merge the master, and build.
In general, git works very well when you have multiple places where source code needs to live. Typically, you pick an "origin" repository - github.com is a great place for this - and sync your other repositories to and from that.
-- EDIT --
Fine example of the XY problem. X is "I need to manage my build process better" and Y is "I want to know the IP of the machine on which a sketch was compiled".
Robin2:
I think you mean Git rather than Github.
Both, GiutHub (website) provides the network graph, and a generally nice way to view and compare things. Of course Git can provide this information, it is nowhere near as intuitive (text in a console). GitHub app uses Git, and makes things easy on a PC. However, Git is quite easy to use for personal use.
But it does not provide any way of knowing what program is actually inside the Arduino.
No, but you can do one better: manage the code so you do not need to ask the Arduino what it is using.
You can give a commit, or branch a date code or other identifiable information.
Using the network graph you can see what you were last working on.
I am not familiar with Git. If you know (from the Arduino) precisely which program is inside the Arduino will Git provide the means to recreate that program exactly (with all the relevant versions of libraries etc) ? (Genuine curiosity).
You can use submodules like others have said, although I do not like using these.
I prefer to keep the repositories separate. Using a tool like GitMan to manage dependencies is better IMO. It runs in python, so you could simply add a few lines to the top of your python script to grab the dependencies before compiling.
I wonder could one automate the process of creating the tag, writing a line of code into the .ino file Serial.println(tag);, uploading the code and causing a commit to happen?
pYro_65:
No, but you can do one better: manage the code so you do not need to ask the Arduino what it is using.
Perhaps you are much more organized than I am. Suppose I have two or three Arduinos with similar, but not identical programs and only one of them works - how can I tell what is the version of the program on the working Arduino?
...R
Robin2:
I wonder could one automate the process of creating the tag, writing a line of code into the .ino file Serial.println(tag);, uploading the code and causing a commit to happen?
Modifying the .ino file would not work. Outputting a header file that could be included in the .ino file would work. Note: The automatically generated header file has to be outside of git control.
I found a few examples (mostly on stackexchange). Linux shell script seems to be a popular way to automate such things. Personally, I would use Python. The general strategy is to pipe the output of a git command to a header file (after formatting to make it proper C/C++).
To be effective, the commit has to happen first. Create a snapshot (commit), build, upload. The upload would include a reference to the snapshot.
Perhaps you are much more organized than I am.
That is highly unlikely.
Suppose I have two or three Arduinos with similar, but not identical programs and only one of them works - how can I tell what is the version of the program on the working Arduino?
The ideal solution would be a command in the IDE (Commit + Upload) that...
• Saves all files (I believe the IDE already does this before building).
• Commits (execute a few simple git commands like "git add" and "git commit"). Optionally the human could be prompted for a comment to go with the commit.
• Freshens the automatically generated include file (I believe "git status" outputs something appropriate).
• Builds
• Uploads
It would be the developer's responsible to make use of the hash (e.g. Serial.print).
A more "advanced" solution would prompt the human for a tag to go with the commit and include the tag in the generated file.
An even more "advanced" solution would guess a reasonable tag (e.g. if the previous tag was "1.0" a reasonable guess for the next tag is "1.1") then offer that to the human.
Personally, I would use the hash instead of a tag.
Thanks for Reply #12.
I have been assuming that anybody sufficiently advanced to use GIT would no longer be using the Arduino IDE for editing programs.
One thing that has put me off GIT is a sense that if you start using it you are stuck with it forever - it does not seem to be something you can use occasionally. Also, it relies on you remembering to COMMIT at the appropriate points in your code development process. Which is not really any different from remembering to make a backup copy of a .INO file.
...R
Robin2:
Thanks for Reply #12.
You are welcome.
I have been assuming that anybody sufficiently advanced to use GIT would no longer be using the Arduino IDE for editing programs.
Naw. I use git for all kinds of things; large and small; source code and Excel workbooks.
One thing that has put me off GIT is a sense that if you start using it you are stuck with it forever
Nope. When I was maintaining Tiny Core on Google Code I used git internally and SVN to synchronize to Google Code. The two coexisted well.
- it does not seem to be something you can use occasionally.
Pick a directory. Run git init. You now have an repository. Run git add. You now have files in the index. Run git commit. You now have files in the repository. You can now maintain a history.
I believe a total of five commands are all that are necessary to manage a synchronized repository.
Also, it relies on you remembering to COMMIT at the appropriate points in your code development process.
Naw. git works best with lots of commits. I typically commit at the end of each work session. Or, obviously, when I reach a good milestone.
Which is not really any different from remembering to make a backup copy of a .INO file.
While it is not meant for such purpose git is actually a good way to maintain a backup. The big benefit is that the history is also archived.
PaulMurrayCbr:
Fine example of the XY problem. X is "I need to manage my build process better" and Y is "I want to know the IP of the machine on which a sketch was compiled".
No, Mr smartie, that's not the case
X is "I need to manage my build process better" and "I want to know the IP of the machine on which a sketch was compiled" is also X.
I do have my own brain too
Let me demonstrate a problem a bit. I'm working on a sketch on my computer, I'm done and I hit upload. Very often the Arduino IDE has some problem uploading (that's the case for another thread). An hour later I want to check how the project works but I'm not at the computer anymore. No changes in project behaviour so simple check through serial command from my smartphone- "sketch uploaded on (yesterday's date)". Now I know that sketch has not been uploaded and I can come back to my computer if I have time.
Another one. I have some idea so I'm taking my smartphone to do some simple improvements, it's like 2 minutes job- edit, upload, get back to other work. A few days later I wan't to make some other improvements, and the question is- where's the last sketch used? On my Dropbox or on my smartphone?
The IDE's I use are Arduino IDE on Windows machines and Bluino Loader on my Androids. Bluino does not integrate with Dropbox or any other locations like Git. Downloading the file each time is too time consuming. So the solution with tagging the sketch works the best for me.
[quote author=Coding Badly link=msg=2906174 date=1472808037]
Naw. git works best with lots of commits.[/quote]
I just meant that if I forget to COMMIT I don't have any backup of the earlier version
While it is not meant for such purpose git is actually a good way to maintain a backup.
Interesting. I had always assumed that the maintenance of backups was an integral part of the GIT concept.
By the way, even if I sound like I'm picking holes, I am taking account of what you are saying.
...R
A very presumptuous claim...
Robin2:
One thing that has put me off GIT is a sense that if you start using it you are stuck with it forever - it does not seem to be something you can use occasionally. Also, it relies on you remembering to COMMIT at the appropriate points in your code development process. Which is not really any different from remembering to make a backup copy of a .INO file.
Like you say, failing to remember to commit is no shortcoming of Git, you can also forget to backup.
But if something goes wrong with your code, you are one command away from returning to a working state. You can also view the difference between your last commit and the new code.
A backup will require replacing the entire contents, or working from multiple live copies to see a comparison.
I just meant that if I forget to COMMIT I don't have any backup of the earlier version
Of course you do, that is the last commit, the new code is un-staged (uncommitted code).
No, Mr smartie, that's not the case
My github page is here. The various repos named "arduino_forum_xxx" correspond to different threads on these forums. Occasionally I do a job from the "Gigs and collaborations" forum, and I always stipulate that the code will be public domain on github because this is my hobby not my job.
Robin2:
Interesting. I had always assumed that the maintenance of backups was an integral part of the GIT concept.
Regarding "git is not backup", I am relaying what I have read. I actually have no idea why people say that. In my experience it is a good choice for maintaining a backup with one exception: size. A git repository is larger than the files it contains. But, my employer has a few million lines of code stored in various repositories and the entire contents fit easily on a single DVD (~4G). So, size has not been a problem for us.
By the way, even if I sound like I'm picking holes...
Not at all.