Device was disconnected 2

I keep on getting this error “device was disconnected” on my blynk app. Even the simplest blynk_test program is giving me this error. It was working fine before. The serial monitor does show my wifi is connected but my blynk app just keeps on saying after every few seconds that the device was disconnected.

Does somebody has any clue ?

Is the serial monitor suppose to say connecting to blynk ?

This is what I get in the serial monitor

[19]
___ __ __
/ _ )/ /_ _____ / /__
/ _ / / // / _ / '/
/
//_, /////_
/
__/ v0.4.6 on Arduino Uno

[603] Connecting to J*****
[3788] AT version:1.1.0.0(May 11 2016 18:09:56)
SDK version:1.5.4(baaeaebb)
Ai-Thinker Technology Co. Ltd.
Jun 13 2016 11:29:20
OK
[7080] +CIFSR:STAIP,“192.1**..
+CIFSR:STAMAC,":::::"
[7087] Connected to WiFi

Do you see here some disconnections during long run?

Serial monitor doesnt show any disconnections. My blynk app just keeps on displaying, at bottom of the page after every few seconds that the “device was disconnected”.

Okay so I used:

#define BLYNK_DEBUG

to see more whats going on. Bellow is what I saw. Every time auth token shows up on the serial monitor my blynk app shows “device was disconnected” at the bottom.

[19]
___ __ __
/ _ )/ /_ _____ / /__
/ _ / / // / _ / '/
/
//_, /////_
/
__/ v0.4.6 on Arduino Uno

[104] Free RAM: 987
[624] Connecting to J*****
[3811] AT version:1.1.0.0(May 11 2016 18:09:56)
SDK version:1.5.4(baaeaebb)
Ai-Thinker Technology Co. Ltd.
Jun 13 2016 11:29:20
OK
[7102] +CIFSR:STAIP,“1*********”
+CIFSR:STAMAC,“60:0********”
[7108] Connected to WiFi
[17795] <[02|00|01|00] 19be8f3**********************************
[29145] <[02|00|01|00] 19be8f************************************
[40494] <[02|00|01|00] 19be8ff************************************
[51844] <[02|00|01|00] 19be8ff************************************
[63299] <[02|00|01|00] 19be8ff************************************
[74544] <[02|00|01|00] 19be8ff************************************
[85894] <[02|00|01|00] 19be8ff************************************
[97144] <[02|00|01|00] 19be8ff************************************
[108490] <[02|00|01|00] 19be8ff************************************

When the auth code keeps repeating, that means the server is either not being reached (despite your being connected to your router/AP or is not responding/recognising? the auth code

Can you confirm if you are connecting to the Cloud Server or your own Local Server.

What type of hardware device are you using

And show the latest sketch that you have tried.

Finally, toss in the phone type (IOS or Android) and App version

Thank you.

Every time you see the token means hardware lost connection and sending login command again. So for some reason hardware drops connections. You need to investigate this. Try from posting your code here.

Okay here is the code I am using,

  • I changed the wifi router, it still gives the same result.
  • I am trying connecting to the blynk cloud server.
  • I am using the latest app version on andriod(6.0.1), Note 5.
  • I am using DHT 22 sensor, 6 channel relay, ESP8266 and Arduino Uno.
#define BLYNK_PRINT Serial
#define BLYNK_DEBUG 
#include <SPI.h>
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h> // include Blynk ESP8266
#include <SimpleTimer.h>
#include <DHT.h>
char auth[] = "19b*****************";
char ssid[] = "K********";
char pass[] = "**********";
#include <SoftwareSerial.h>
SoftwareSerial EspSerial(2, 3); // ( RX, TX )
#define ESP8266_BAUD 9600
ESP8266 wifi(&EspSerial);
#define DHTPIN 4          // What digital pin we're connected to
#define DHTTYPE DHT22   // DHT 22
DHT dht(DHTPIN, DHTTYPE);
SimpleTimer timer;
//Relay in Pin XX
#define Relay1 10
#define Relay2 9
#define Relay3 8
#define Relay4 7
#define Relay5 6
#define Relay6 5
// in Blynk app writes values to the Virtual Pin 1
BLYNK_WRITE(V1)
{
  int RelayStatus1 = param.asInt();
  if (RelayStatus1 == 1) {
    digitalWrite(Relay1, LOW);
  }
  else {
    digitalWrite(Relay1, HIGH);
  }
}
BLYNK_WRITE(V2)
{
  int RelayStatus2 = param.asInt();
  if (RelayStatus2 == 1) {
    digitalWrite(Relay2, LOW);
  }
  else {
    digitalWrite(Relay2, HIGH);
  }
}
BLYNK_WRITE(V3)
{
  int RelayStatus3 = param.asInt();
  if (RelayStatus3 == 1) {
    digitalWrite(Relay3, LOW);
  }
  else {
    digitalWrite(Relay3, HIGH);
  }
}
BLYNK_WRITE(V4)
{
  int RelayStatus4 = param.asInt();
  if (RelayStatus4 == 1) {
    digitalWrite(Relay4, LOW);
  }
  else {
    digitalWrite(Relay4, HIGH);
  }
}
BLYNK_WRITE(V5)
{
  int RelayStatus5 = param.asInt();
  if (RelayStatus5 == 1) {
    digitalWrite(Relay5, LOW);
  }
  else {
    digitalWrite(Relay5, HIGH);
  }
}
BLYNK_WRITE(V6)
{
  int RelayStatus6 = param.asInt();
  if (RelayStatus6 == 1) {
    digitalWrite(Relay6, LOW);
  }
  else {
    digitalWrite(Relay6, HIGH);
  }
}
void sendSensor()
{
  float h = dht.readHumidity();
  float t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit
  if (isnan(h) || isnan(t)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V8, h);
  Blynk.virtualWrite(V7, t);
}
void setup()
{
  pinMode(Relay1, OUTPUT); // sets the digital pin as output
  digitalWrite(Relay1, HIGH); // Prevents relays from starting up engaged
  pinMode(Relay2, OUTPUT); // sets the digital pin as output
  digitalWrite(Relay2, HIGH); // Prevents relays from starting up engaged
  pinMode(Relay3, OUTPUT); // sets the digital pin as output
  digitalWrite(Relay3, HIGH); // Prevents relays from starting up engaged
  pinMode(Relay4, OUTPUT); // sets the digital pin as output
  digitalWrite(Relay4, HIGH); // Prevents relays from starting up engaged
  pinMode(Relay5, OUTPUT); // sets the digital pin as output
  digitalWrite(Relay5, HIGH); // Prevents relays from starting up engaged
  pinMode(Relay6, OUTPUT); // sets the digital pin as output
  digitalWrite(Relay6, HIGH); // Prevents relays from starting up engaged
  // communication with the host computer
  Serial.begin(9600);
  delay(10);
  // Set ESP8266 baud rate
  EspSerial.begin(ESP8266_BAUD);
  delay(10);
  Blynk.begin(auth, wifi, ssid, pass);
  delay(10);
  dht.begin();
  // Setup a function to be called every 5 second
  timer.setInterval(5000L, sendSensor);
}
void loop()
{
  Blynk.run();
  timer.run(); // Initiates SimpleTimer
}

Even the simplest blink code doesnt work? So I guess the code part is okay ?

Any sketch? Can you try http://examples.blynk.cc/?board=ESP8266&shield=ESP8266%20WiFi&example=GettingStarted%2FPushData
and see if it seems to disconnect around the same time, each time? This should simply display the uptime in seconds.

Code seems fine. Maybe issue in power supply? Signal strength?

The uptime is almost zero, it just says Device was disconnected at the bottom of the app after evert few seconds

Power supply for arduino is my laptop via usb and power supply for ESP8266 is an old phone charger of 5v 2A coupled with a voltage divider of 3.3V.

To help with the elimination process, can you test with the USB-link? http://docs.blynk.cc/#hardware-set-ups-arduino-over-usb-no-shield

Keep the shield on, just load this instead http://examples.blynk.cc/?board=Arduino%20Uno&shield=Serial%20or%20USB&example=GettingStarted%2FPushData

And connect via the IDE

I tried http://examples.blynk.cc/?board=Arduino%20Uno&shield=ESP8266%20WiFi%20Shield&example=GettingStarted%2FPushData

setting a display with virtual pin 5. It gives no data, just keep on doing what it was doing before, the device was disconnected

Try again using the USB link…

Blynk USB script failed
java.io.IOException: Cannot run program "/Users/junaid/Documents/Arduino/libraries/Blynk/scripts/blynk-ser.sh": error=13, Permission denied

The IDE displays this error when I run the USB script

Are you on an Apple or Windows PC?

Apple

I’m no Apple user, but I am sure they don’t use what looks like Windows directory structure…

Try following these instructions then instead of running the script from the IDE Arduino Uno and USB step by step tutorial

Start at the 5 minute mark for the relevant part.