In many C++ programs you need to define the WiFi credentials.
I thought, that it could have been a good idea to define the credentials in a library: e.g. WiFiCredentials.h
The advantage were that you can have a portable programm that does not expose your credentials and if those credentials change, you just have to change them at one location.
Do you think that is a good approach?
If yes how could I manage to get that idea be propagated?
The WiFiCredentials.h is simple, but how to agree upon a common variable name for SSID and PASSWD?
I personally would not use such a library unless it made it possible to drag and drop a web server code with default credentials that could be changed by first connecting the device to WiFi, then navigating to a browser page, hosted by the device, containing a form to update the credentials. Any library to hard-code credentials is not really useful.
Perehama:
I personally would not use such a library unless it made it possible to drag and drop a web server code with default credentials that could be changed by first connecting the device to WiFi, then navigating to a browser page, hosted by the device, containing a form to update the credentials. Any library to hard-code credentials is not really useful.
Isn't that a kind of overkill?
All that code would take resources, then you need to store the credentials in eprom, eating eprom resources.
You could end up having much more code to manage that credential swap than your useful code.
RIN67630:
Isn't that a kind of overkill?
All that code would take resources, then you need to store the credentials in eprom, eating eprom resources.
You could end up having much more code to manage that credential swap than your useful code.
I just wanted to get code lean and KISS.
It may be overkill for your use, but it's essential for my use. I hadn't considered Arduino's Web Editor in the scope of this topic until pert said something. If that is the issue, I think she's linked the perfect solution. If you want to keep you code lean and KISS, just hard-code the values. a library for what you want to do is not lean or KISS.
Perehama:
Is it really more flexible to place credentials in a separate h file than at the top of your main INO file?
It would be easier to change one file that handles connecting to my home network, and have all of my sketches know of the changes next time I compiled, than to have to edit many sketches to change the information.
If you only have one such sketch, then a separate file offers no advantage.
RIN67630:
The WiFiCredentials.h makes software distribution much easier.
The question was how to get the idea standardized (evtl in the library directory) and to agree upon the naming for the 2 variables.
It sounds like you don't really need a standard across all Arduino, just across your devices. For that you just write the header and distribute it with your code. Tell the user to go into that file and put in their password or whatever.
Delta_G:
It sounds like you don't really need a standard across all Arduino, just across your devices. For that you just write the header and distribute it with your code. Tell the user to go into that file and put in their password or whatever.
I just wanted to get the solution more universal, and able to work with other programs as well.
Whereas ssid or SSID should be the standards, the variable for the password could be somewhat more "creative".
Would it be universal enough to write this:?
#define ssid "my SSID" #define SSID ssid #define password "my Password" #define PASSWORD password #define PASS password #define PASSWD password
Should I define the macro names as allcaps, to follow the Arduino preprocessor conventions?
It's your code do what you want. I doubt this will be accepted as some sort of wider standard. It really makes little sense to do that. Most anyone could write that header themselves for whatever code they write.
What are you going to have people download this as a library? They still have to go in and modify it. So what is it saving them?
pert:
The trouble is that editing a library file is not terribly easy for the average Arduino user.
I don't see any difference in editing a header with all those lines or simply writing one with the two lines in it that you need. If it has to be edited then why would we want it to be like a separate library and not part of whatever library it is meant to go with.
What I mean is, say I want to write a library which seeks out Arduino posts missing the code and does an automatic reply to tell them to post it. Should the WiFiCredentials.h be a separate library that you have to download separately and this library should be dependent on it? Or should it just be one extra header that I includes with my library?
Delta_G:
I don't see any difference in editing a header with all those lines or simply writing one with the two lines in it that you need...
If we could get it standardized, once you have your personal WiFicredentials library installed, you just could compile any example sketch oob without having to care...
Delta_G:
If it has to be edited then why would we want it to be like a separate library and not part of whatever library it is meant to go with.
Having it in a dedicated library means you only have a single file to edit when your credentials change. Having it in a dedicated library makes the most sense because you will likely be using it with existing libraries rather than some library that was written to use the WiFiCredentials library.
Common generic macro names are likely to cause namespace collisions. You should use something original like WIFICREDENTIALS_SSID and WIFICREDENTIALS_PASSWORD. I see no benefit to spamming a bunch of different names.
pert:
Common generic macro names are likely to cause namespace collisions. You should use something original like WIFICREDENTIALS_SSID and WIFICREDENTIALS_PASSWORD. I see no benefit to spamming a bunch of different names.
OK, but then you would need to edit the sketches to translate the macro names to what was defined there.
You're going to need to edit the sketch to include the library anyway. You should only need to edit a single line for each of the credential definitions you want to use from the library.