How to flash .h and .cpp files to a device?

Hi, I need to clone a Photon that is not mine. That Photon is running a home brew Maker Space card reader system. I am trying to clone their setup for our Maker Space. I purchased the Photons and I can connect to them using a USB micro cable. The Maker Space sent me the firmware files (ending in .h and .cpp). However, the person who programmed the Photons is no longer connected to that Maker Space and they have moved overseas. How do i get the files onto the Photon? I have searched for help thru the forums and I could not find anything. I appreciate any help!

Thank you!
Eddie

So you have access to the physical Photon via USB, good. I assume you also have the CLI installed, you need to have it to upload a firmware file via USB. First, if you haven’t already, you should claim the Photons to your user account and set them up on your WiFi. Then you don’t have to use the USB but rather you could flash firmware Over-the-Air (OTA).

I don’t think the maker space sent you firmware files. A ready-to-go firmware file would probably already be compiled and have a .bin extension. An uncompiled firmware file would have a .ino extension (and may also have some ancillary files such as .h and .cpp). The .h and .cpp files are usually library files. I assume they are the library files to use the card reader? You would need to open those .h and .cpp files in a development environment such as the Web IDE. If the files they sent are only library files, and not a complete application, you may have to code the .ino file yourself. After you compile your firmware, you can then flash it to the Photon via USB. If the Photons are claimed to your account, you could alternatively flash the firmware OTA from the Web IDE.

1 Like

To expand on what’s been mentioned above by @ninjatill: when using the Web IDE, the following should work:

Could you show us an overview of the files you’ve got? Doesn’t have to be the exact contents, but just the kind of files you have? Does at least one of them include the setup() and loop() sections? If so, that’s you main file.

I’d highly recommend playing around with the device a bit to get a feel for how it works. It helps to know what you’re dealing with, rather than blindly copying things and hoping it works. Give the simple examples like Tinker and “Blink an LED” a shot, it’s worthwhile.

list

Yes, I have physical access to their Photon. If i claim their Photon and upload the firmware, could they claim it back? This is one of their working Photons and I don’t want to break it. They were kind enough to let me use it. They have been a big help to me. I have connected to the Photons i purchased and messed around with them a little. They are very cool. I am an old hardware guy. So i can connect to their Photon, claim it, upload their firmware, i should be able to use that instead? I am on a time constraint and would like to get these up and running pretty quickly. I appreciate the help!!!

1 Like

Forgot to add… the main.cpp does have setup and loop statements in it. i wish i could upload them so you could see them.

You don’t really need access to their Photon at all.
Can you flash your own devices Over the Air using the Web IDE? If so, then the method I mentioned above should work fine :slight_smile:

1 Like

I have not tried it yet. However, it sounds like i dont have the compiled files to send over to the Photons yet. Wouldn’t i need to compile them first then send them over?

If their Photon is claimed to their account, you cannot claim it. They would first have to unclaim, or release, that Photon before you could flash OTA. You might still be able to flash firmware to it without having it claimed but I would not do that! As @Moors7 said, you have their complete source code and your own Photon… that’s all you need.

And correct, you need to take their application, compile it, then send it to your own Photon. In the Web IDE, you simply copy the contents of all those files in the application, then compile and send it using the “lightning” bolt icon on the menu.

1 Like

The Web IDE does all that for you. Just stick the files in the right places (check my first post for guidance), then hit verify on the left, followed by flash. That’s all assuming your device is claimed to your account and connected over WiFi.

Sweet! Yes, the new photons are claimed to my account and connected over Wifi (my phone hotspot so i can play with them @ work :grin:) These Photons are really cool.

3 Likes

In that case you should be good to go! Let us know if it worked :slight_smile:

2 Likes

Will do!

2 Likes

Update - I was able to create a new app and bring in the files. I tried to bring in all of the files and hit verify, it gives several error messages (looks like the wifi_login portion - of course one of the longer codes). I then deleted that app and started on a fresh app. i only brought in led.cpp and led.h and it was able to verify. i hit the lightning bolt and it flashed. however, to my understanding there can only be one app on the Photon correct? Also, how can i find out which app(s) are loaded onto a certain Photon? i worked on this for about 5 hours last night. I am getting a better feel about what is going on.

There is no out-the box way to do that.
The easiest is when you expose a Particle.variable() that tells you when you request it.
You can also have the application print a version info on boot-up or on demand via a Particle.function().
Another way is like the mobile app does it for Tinker via the signature of exposed objects (variable & functions).
The next thing may apply but I’m not sure tho’: Each binary has a hash code which you can see via particle binary inspect and particle serial inspect off the device and if I’m not completely off base they should match. So when you keep the binary file and name it in a telling way you should be able to match the device and the binary.

Wow. Ok. Can you confirm the Photon’s can only have one app on them at a time?

Yes, of course.

Most likely, all those files, you posted a screenshot of, work together as one unified application. The main.cpp, which should include your startup() and loop() functions, probably has #include statements at the top of the file which would tell you which additional files need to be included in the project. If you see an include statement for each file, then you need to create all those files within the IDE you are using.

If using web IDE, create a new application and in the default file that’s create ([appname].ino) you can copy and paste the contents of the main.cpp file. Then, for each .h and .cpp pair, click the “+” icon at the top right of the window to create a new .h and .cpp file pair and rename them to one of the files from your list. Then, copy the contents for each of those files into the respective new, empty file. When you have all 10 file contents copied, hopefully the app will compile. If you get stuck, save what progress you have made, and then find the button for “Share this revision”. You can post that link here and we can probably tell you what’s what.

This is all just general guidance. If you want specifics, you could put all those files into a .zip file and post a shared link in dropbox or some other file share tool.

1 Like

hi ninjatill… i added all of the files they sent to me into a new app. it would not compile. very good idea on “share this revision” I will see if i can get it to a dropbox! thanks for the advice! some of the files ![list|150x225] do not have a .cpp (upload://uZY6boC3THZG5DGQNAqm7JNyBXG.JPG) will that be an issue?

@stankcheeze, I believe @ninjatill meant to use this to share your app:

https://docs.particle.io/tutorials/developer-tools/build/photon/#sharing-your-app

For that one lonely config.h, you would click the “+”, enter config.h for the filename (and it creates both a .cpp and .h) and then just delete the .cpp file. I was able to do that just now with a test app.

And yes to @peekay123. The dropbox service I mentioned also allows you to share a link to a file because you cannot post a .zip directly to this forum… but this is completely separate from the Web IDE “Share this Revision” button.