• Hardware = one nodemcu esp8266 with a relay module
• Smartphone = Android with Blynk app (single instance)
• Blynk server or local server = Both servers are setup and working
Hi All,
I have looked for similar topics in this community but unfortunately i cannot find a solution to my problem. If there is a solution please forward me to it and forgive me 
Background:
I have a project to control my lights at home with a relay using the NodeMCU. It works perfectly when i am connected to the cloud. If i am at home and the internet goes down, i wont be able to turn my lights on or off unless i have a local server setup at home (local server is setup and is working fine).
Problem:
I have cloned the blynk project that is in the cloud and added it to my local server (same device). however, when i cloned the project locally, i was given a new Auth code for it. Now i have one for my cloud (X) and another for my local project (Y).
Since i only have one NodeMCU and have one sketch uploaded, how can i add both X and Y Auth codes to my sketch. This will be so that i can connect to the same sketch on the NodeMCU from either my projects.
I tried to be very detailed and clear
i hope it worked. Please can someone assist me on this.
Each and every server is independent of others, and the server generates the AUTH, so there is no sharing.
You need two AUTH codes, and this will have to be done manually as I can’t think of any simple way for the device to automatically know which server you intend to connect to, since you need to also alternate the IP connection in the sketch anyhow… Not to mention make the changes to the App for each login as well.
You can simply comment out whichever ones you don’t need…
char ssid[] = "xxxxxxxxxx";
char pass[] = "xxxxxxxxxx";
int port = 8080;
//char auth[] = "xxxxxxxxxx"; // Auth for your Local Server
char auth[] = "xxxxxxxxxx"; // Auth for Blynk Cloud Server
//char server[] = "xxx.xxx.xxx.xxx"; // IP for your Local Server
char server[] = "blynk-cloud.com"; // URL for Blynk Cloud Server
void setup() {
WiFi.begin(ssid, pass);
Blynk.config(auth, server, port);
Blynk.connect();
}
You would be better served to setup your routers port forwarding for public “aka you” access to your Local Server while out on the road.
Hey @Gunner
Shot for the reply! really appreciate your help. There are some conditions that results in this manual process to be undesirable.
More Context: We in South Africa and internet is not very stable 
-
The Lights will be also controlled by my wife in the house and she wont have the knowledge to uncomment and upload the sketch if i am not home. 
-
The NodeMCU will not be close enough for me to re-upload a new sketch to my NodeMCU as it will be packaged with the relay on my veranda / Stoep.
I was looking to maybe write this in another topic but it is related. I was hoping that there is a way to write a failover connection for example. (Excuse the pseudo code, you should get the idea i hope) I
dont know the library methods that well
char ssid[] = "Bob's";
char pass[] = "Uncle";
char AuthCloud [] = "XXXXXXX"
char AuthLocal [] = "YYYYYYY"
char Auth[] = char AuthCloud[];
Blynk.begin(Auth, ssid, pass);
if (connection to Cloud fails)
{
char Auth[] = char AuthLocal[];
}
Blynk.begin(auth, ssid, pass, IPAddress(192,168,X,XXX), PORT);
If (Connection to local fails)
{
// **Retry the connection from the top after a period of time.**
}
Dont know if this is possible i.e the failover approach and the Retry connection part.
You can try this solution - if properly done, it might work. But you need to use manual connection handling to the Blynk, not the Blynk.begin() as this one will just block the code until it is connected (which may never happen)
I’m still not clear why you don’t use your local sever all of the time.
When your internet is down then any device connected to your home Wi-Fi will be able to control your lights (assuming you’re not having a regular SA power cut - but in that case your lights won’t work anyway).
In the internet failure scenario then you won’t be able to control your lights from a remote location, but that would be the case whether you used local or cloud server.
When the internet is up then (provided you’ve done the port forwarding as mentioned by @Gunner) then you’ll be able to control your light remotely, as well as locally.
The problem with the connection fallover approach is that your mobile app will need to be configured to use either your local or cloud server, and the corresponding Auth codes. The problem is that you won’t know which server your NodeMCU has currently decided to connect to.
Pete.
1 Like
True… every time one connection will fail, you will need to logout from one server, login to another, where most probably you will find it offline too
It is the same internet connection …
I don’t think you understood my point… it is not really a optional process… either use the Cloud all the time or the Local Server all the time… or you will enevidably run into problems, logistical, technical, mental, marital 
2 Likes
Hi All.
Firstly, thank you for your input to get me here. I have not been on a community forum before and this has been a very pleasant experience.
So i have given this some deep thought and i think, based on your input i have a solution going forward that would better suit my needs.
I will go with the suggestion some of you made. It was to create a local server of Blynk at home. Add port forwarding to my router so that i can access it anywhere in the WWW and if my provider is down, i can use local wifi.
It will also enable me to only need one project with one Auth Key.
Thanks Again.
2 Likes