Hi everyone, i’m writing code with an arduino mega that will control light, sensors and drive motors. I have made the program in such way that every commands or feedback are done both with the Blynk app or the serial monitor. Unfortunately, when the internet connection is unavailable, the program get stuck .it just keep trying to connect to Blynk server over and over again. It will run as long as the arduino dont get turned off but when power is down, nothing will work till the board can connect to Blynk server.
Is there a way to write my program so the main loop will keep working with the serial monitor even if the ethernet dont work when i turn the power on???
Not really. That is just not how it works.
In my opinion you have a couple options.
- Program everything double, meaning, to run with both Blynk and standalone, but that would more than double your code and probably leave you with a crippled system since you can’t control anything with your Dashboard
- Run a local server with Blynk instead of using cloud services and attach all the devices to a UPS or similar power solution
- Make sure you stay connected to Blynk cloud services
Other than that I don’t see many alternatives. A local server is probably your best bet. You can use a Raspberry Pi or something similar that is equally cheap (Cubiebox) and runs Linux.
No actually you can handle network connection manually.
- You can call Blynk.connect() or Blynk.disconnect()
- There is an example called “User defined connection” which allows you full control over the Blynk connection stream.
This is a “professional mode” ))
Thanks vhymanskyy, i will look for further information on these to see if it can solve my problen.
thanks Lichtsignaal, my program is already written in “double” since i want the user to be able to wort it with Blynk or the serial monitor. All of the input or outputs are available with both.
My main problem is that i would like the user to be able to enter the token number on the first “turn on” and i want to store it in the eeprom. So that each time the power is switched on, my program extract the token from the eeprom. The end user will not have access to the program so i have to give him a way to enter the token with the serial monitor on initial launch. Everything work well, i am able to change the token number this way but if there is no initial working code, everything freeze and i’m stuck.
Thanks for your help!!!
I think i might have found a way. What if i would use two arduino. The “master” one would drive the outputs and control the serial monitor controlled portion of the program. The second would be connected to Blynk and would be used only for this purpose. Both would communicate with the serial1 connection(arduino mega). This way, if the Blynk connection is lost, the user is still able to control it by serial monitor.
The only problem for me is to find a way to enter the token with the program running sinse the end user will not have access to the program , only the serial monitor!!!
Any idea please???
That seems like a fine idea to me. I wondered why I didn’t think of that, LOL
You can have a “setup” portion in your code where you go through once at power up to see if there is a token code in the EEPROM. That should be doable via serial input and output.
Even easier would be to use I2C to bind them together in the darkness etc. You can find some more information about that here: http://www.gammon.com.au/forum/?id=10896
I2C only uses two wires and doesn’t mess up you serial communication lines so I think that would be the way to go
You’re right, i2c look like a good way to go.
I have already succeed in changing the token while running the code by storing the new code in eeprom. The problem is that Blynk start automatically on turn-on and refuse to run the code if token is not accepted. I would like to stop the Blynk connection only for the program to either get the token from eeprom or from serial monitor and later i can put it eeprom. I have no problem with the eeprom part . Hope you can help me!!!
I think you can do that with I2C via the Setup function.
You can connect blynk (Blynk.auth) if a variable is passed via a I2C connection or otherwise enter “standalone” mode.
if (i2cgetVariablethingies == OK)
Very quick in sort pseudo-code
Good news, i tried many approach and i finally got it, here is how i did it!
First of all, in the void setup(),i created a “if” loop that contained :char auth 
while (Blynk.connect() == false.
I ask the user if he want to start Blynk now. I it reply via the serial monitor"yes" then i trigger the “if loop” by setting a boolean value to true, if it do not want it, i let the program go whithout initializing Blynk.
The only thing is that the Blynk.run() must remain in the void loop() and is also conditionnal to the same boolean value via a “if loop”.
That way, if it’s the first time the user use it, he can bypass the Blynk startup and run the rest of the program on its own with the serial monitor and in the setup menu that i have created, there is an option to save the token in eeprom witch will be recalled on the next startup to initiate Blynk. The program is not finished but everithing work well. I will also try to get a selectable software reset to allow the user to restart the program and enable Blynk.
I like the way you think and I like to see the code when you are done! It sounds like something I can use for some things.
And i forgot to say that Blynk will start automatic if not otherwise stated in the first 30 seconds of power turn-on. This will ensure that it will keep booting with Blynk if power is temporarly lost. It will prevent user from having to reconnect manually witch would mean no Blynk connection would be available untill user physically restart board. It would make no sense!!!
Ok, i’ll keep writing on it, but i work a lot so i dont have a lot of time to continue the program but little by little, i will tell you as often as possible!!!
No problem, all good things come slowly
The logic looks sound to me. I may even try to write something myself if I can find the time, lol.