Hello respected Sir Hope U are fine
Sir I have tried the code with the blynk server and it worked successfully But when i tried to run the same code with the local server it connected successfully but i can’t control or can’t send any data from my blynk app to my arduino. I mean that i can’t even turn off the led connected to pin 13 of arduino from the button widget in my blynk app. Every thing is fine but why this is happening i don’t understand it at all.
Code is given below and snapshots of local server is also given below.
Thanks in Advance
#define BLYNK_PRINT SwSerial
#include <SoftwareSerial.h>
SoftwareSerial SwSerial(10, 11); // RX, TX
#include <BlynkSimpleStream.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
//char auth[] = "95b6eeef38fe481dba590c28febef4bb"; // For Blynk Cloud Server
char auth[] = "1ec485252d9542b999bc8766edc08172"; // For Local Server
BlynkTimer timer;
// This function sends Arduino's up time every second to Virtual Pin (5).
// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.
/*
int pinValue = 0;
BLYNK_WRITE(V7)
{
pinValue = param.asInt();
}
*/
void myTimerEvent()
{
// You can send any value at any time.
// Please don't send more that 10 values per second.
//------------------Automatic Switching Code-----------------------//
double solar = analogRead(A1);
float voltage = solar*(5.0/(1023*0.2000818));
//----------------------------END----------------------------------//
//----------------Reading The condition of Relay 2 i.e Generator----------------//
const int Relay2_Signal_Pin = 4;
int G = digitalRead( Relay2_Signal_Pin);
//-------------------------------------END--------------------------------------//
//-----------------------------Sending Value of digital and analog pin to the display widget-----------------------------//
//int Digitalpin = analogRead(Relay2_Signal_Pin);
//Blynk.virtualWrite(V3,Digitalpin);
Blynk.virtualWrite(V3,G);
Blynk.virtualWrite(V4,solar);
//---------------------------------------------------END-----------------------------------------------------------------//
//-------------Load indication system for Blynk------------------//
if(digitalRead(2))
Blynk.virtualWrite(V1,255);
else
Blynk.virtualWrite(V1,0);
if(digitalRead(13))
Blynk.virtualWrite(V2,255);
else
Blynk.virtualWrite(V2,0);
//--------------------END--------------------------------//
//------------------------Indication System-------------------------//
if(voltage<6)
{
Blynk.virtualWrite(V5, 0);
if(!G)
{Blynk.virtualWrite(V6, 255);
Blynk.virtualWrite(V7, 0);}
delay(1L * 1000L);
if(G)
{
Blynk.virtualWrite(V6, 0);
Blynk.virtualWrite(V7,255);
}}
else
{Blynk.virtualWrite(V5, 255);
Blynk.virtualWrite(V6,0);
Blynk.virtualWrite(V7,0);}
}
//-----------------END----------------//
void setup()
{
/*pinMode(A1,INPUT);
pinMode(13,OUTPUT);
pinMode(2,OUTPUT);
pinMode(4,OUTPUT);*/
// Debug console
SwSerial.begin(9600);
// Blynk will work through Serial
// Do not read or write this serial manually in your sketch
Serial.begin(9600);
Blynk.begin(Serial, auth);
// Setup a function to be called every second
timer.setInterval(1000L, myTimerEvent);
}
void loop()
{
Blynk.run();
timer.run(); // Initiates BlynkTimer
}
I have tried this simple code and its running with local server but why not the above one?
#define BLYNK_PRINT DebugSerial
// You could use a spare Hardware Serial on boards that have it (like Mega)
#include <SoftwareSerial.h>
SoftwareSerial DebugSerial(2, 3); // RX, TX
#include <BlynkSimpleStream.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "6d26812e3ce04ca08ff0a47e7bdbbc6b";
void setup()
{
// Debug console
DebugSerial.begin(9600);
// Blynk will work through Serial
// Do not read or write this serial manually in your sketch
Serial.begin(9600);
Blynk.begin(Serial, auth);
}
void loop()
{
Blynk.run();
}
First, please learn how to properly format code you paste in this forum… I have edited your last to posts, so please look back at them to see how it is done. Thank you
Every single server is independent of all others… so first you need to create a new account on your Local Server (via the App) then recreate any projects, and use those generated auth codes in your sketch.
You also need to tell your sketch (or in your case, edit the USB-link blynk-ser.bat file) to connect to the Local Server instead of the default Cloud Server.
He seems to be bouncing back and forth between Local and Cloud… and trying to use same sketch and/or connection method without adjusting as required… perhaps not even changing the App login… hard to say.
Yes, they both are set for Local Server… perhaps he is NOT jumping between Local and Cloud server… despite some of the comments that alluded to that…
Honestly, it is hard to tell what the actual question is??
Oh well, @Imran123 Please confirm which server you are using and that you have properly set the App for that server, and the correct Auth code for the project on that server, along with USB link view and the associated script with the correct Auth code… assuming it still doesn’t work after checking all that
These are the screen shots of my blynk app how i am connected at blynk server
First after uploading the code to my arduino with the blynk server token and connected to blynk server are,
Here i am connected and when i press button widget then the led widget glows in response from my arduino
and i am online here its pic is
And now i am gonna connect to my local server and i have created just the same project there too with different name and i am gonna use the token assigned to me by local server.So here are the pics
First gonna connect
Then my project on local server will be opened
And i am online too mean connected to my local server
But when i press the button widget no led glows on my blynk app as shown below
one thing to be noted the red and yellow leds are glowing by default ok and one thing more i have connected to my local server with the simple code as i have mentioned above and it worked fine.
Please help me out in this one bro’s i am getting confused.
Thank U all for giving me your time.
I have already tried to explain… Any two servers cannot be easily swapped… the Authcode gets generated and monitored by the server you are currently logged into, not the App, so even if you have two identical projects, each on a different server, then you must also manually change the auth code in the script to match the one on the App.
Something else to consider with Local Server, particularly if running on a PC… AntiVirus and Firewall software can and will block some or all server access.
Gunner I have resolved it on the proteus without using the real time arduino and it worked great but still haven’t tested again with the real arduino so as i am done with it I am gonna let you know about it.
And thanks for ;your concern and @Gunner bro can you give me some suggestion on the post relating to the arduino shields that i have posted please i am awaiting your response.
Thanks in advance for that one.
Okay